Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 23 Decision problems about regular languages –Programs can be inputs to other programs FSA’s, NFA’s, regular expressions –Basic problems are.

Similar presentations


Presentation on theme: "1 Lecture 23 Decision problems about regular languages –Programs can be inputs to other programs FSA’s, NFA’s, regular expressions –Basic problems are."— Presentation transcript:

1 1 Lecture 23 Decision problems about regular languages –Programs can be inputs to other programs FSA’s, NFA’s, regular expressions –Basic problems are solvable halting, accepting, and emptiness problems –Solvability of other problems many-one reductions to basic problems

2 2 Problems with programs as inputs

3 3 Decision problems with numbers as inputs Examples –Primality: Input: integer n Yes/No question: Is n prime? –Zero: Input: integer n Yes/No question: Is n = 0? –Equal: Input: integers m, n Yes/No question: Is m=n?

4 4 Decision problems with programs as inputs Examples –Lines of code: Input: program P, integer n Yes/No question: Does P have less than n lines of code? –Empty language: Input: program P Yes/No question: Is L(P) = {}? –Equal: Input: programs P, Q Yes/No question: Is L(P) = L(Q)?

5 5 Language representation Empty language problem: –Input: program P –Yes/No question: Is L(P) = {}? How might we represent input program P? –As a string P over ASCII alphabet What is the language that corresponds to empty language decision problem? –The set of strings representing programs which are yes instances to the empty language problem

6 6 Programs In this unit, our programs are the following three types of objects –FSA’s –NFA’s –regular expressions Previously, they were C ++ programs –Review those topics after mastering today’s examples

7 7 Basic Decision Problems (and algorithms for solving them)

8 8 Divisibility Problem Input –integers m,n Question –Is m a divisor of n? Algorithm DIV for solving divisibility problem –Apply Euclid’s algorithm for finding the greatest common divisor to m and n –If greatest common divisor is m THEN yes ELSE no

9 9 Halting Problem Input –FSA M –Input string x to M Question –Does M halt on x? Algorithm for solving halting problem –Output yes Correct because an FSA always halts on all input strings

10 10 Accepting Problem Input –FSA M –Input string x to M Question –Is x in L(M)? Algorithm ACCEPT for solving accepting problem –Run M on x –If halting configuration is accepting THEN yes ELSE no Note this algorithm actually has to do something

11 11 Primality Problem Input –integer n Question –Is n a prime number? Algorithm for solving primality problem –for i = 2 to n-1 Do apply algorithm DIV to inputs i,n If answer for any i is yes THEN no ELSE yes

12 12 Empty Language Problem Input –FSA M Question –Is L(M)={}? How would you solve this problem?

13 13 Algorithms for solving empty language problem Algorithm 1 –View FSA M as a directed graph (nodes, arcs) –See if any accepting node is reachable from the start node Algorithm 2 –Let n be the number of states in FSA M –Run ACCEPT(M,x) for all input strings of length < n –If any are accepted THEN no ELSE yes Why is algorithm 2 correct? –Same underlying reason for why algorithm 1 works. –If any string is accepted by M, some string x must be accepted where M never is in the same state twice while processing x –This string x will have length at most n-1

14 14 Solving Other Problems (using many-one reductions)

15 15 Complement Empty Problem Input –FSA M Question –Is (L(M)) c ={}? Use many-one reductions to solve this problem –We will show that the Complement Empty problem many-one reduces to the Empty Language problem –How do we do this? Apply the construction which showed that LFSA is closed under set complement

16 16 Algorithm Description Convert input FSA M into an FSA M’ such that L(M’) = (L(M)) c –We do this by applying the algorithm which we used to show that LFSA is closed under complement Feed FSA M’ into algorithm which solves the empty language problem If that algorithm returns yes THEN yes ELSE no

17 17 Reduction Illustrated Algorithm for solving empty language problem FSA M Complement Construction FSA M’ Yes/No Algorithm for complement empty problem The complement construction algorithm is the many-one reduction function. If M is a yes input instance of CE, then M’ is a yes input instance of EL. If M is a no input instance of CE, then M’ is a no input instance of EL.

18 18 NFA Empty Problem Input –NFA M Question –Is L(M)={}? Use many-one reductions to solve this problem –We will show that the NFA Empty problem many-one reduces to the Empty Language problem –How do we do this? Apply the construction which showed that any NFA can be converted into an equivalent FSA

19 19 Algorithm Description Convert input NFA M into an FSA M’ such that L(M’) = L(M) –We do this by applying the algorithms which we used to show that LNFA is a subset of LFSA Feed FSA M’ into algorithm which solves the empty language problem If that algorithm returns yes THEN yes ELSE no

20 20 Reduction Illustrated Algorithm for solving empty language problem NFA M Subset Construction FSA M’ Yes/No Algorithm for NFA empty problem The subset construction algorithm is the many-one reduction function. If M is a yes input instance of NE, then M’ is a yes input instance of EL. If M is a no input instance of NE, then M’ is a no input instance of EL.

21 21 Equal Problem Input –FSA’s M 1 and M 2 Question –Is L(M 1 ) = L(M 2 )? Use many-one reductions to solve this problem –Try and reduce this problem to the empty language problem –If L(M 1 ) = L(M 2 ), then what combination of L(M 1 ) and L(M 2 ) must be empty?

22 22 Algorithm Description Convert input FSA’s M 1 and M 2 into an FSA M 3 such that L(M 3 ) = (L(M 1 ) - L(M 2 )) union (L(M 2 ) - L(M 1 )) –We do this by applying the algorithm which we used to show that LFSA is closed under symmetric difference (similar to intersection) Feed FSA M 3 into algorithm which solves the empty language problem If that algorithm returns yes THEN yes ELSE no

23 23 Reduction Illustrated Algorithm for solving empty language problem FSA M 1 FSA M 2 2FSA -> 1FSA Construction FSA M 3 Yes/No Algorithm for Equal problem The 2FSA->1FSA construction algorithm is the many-one reduction function. If (M 1,M 2 ) is a yes input instance of EQ, then M 3 is a yes input instance of EL. If (M 1,M 2 ) is a no input instance of EQ, then M 3 is a no input instance of EL.

24 24 Summary Decision problems with programs as inputs Basic problems –You need to develop algorithms from scratch based on properties of FSA’s Solving new problems –You need to figure out how to combine the various algorithms we have seen in this unit to solve the given problem


Download ppt "1 Lecture 23 Decision problems about regular languages –Programs can be inputs to other programs FSA’s, NFA’s, regular expressions –Basic problems are."

Similar presentations


Ads by Google