Transcript Lecture 26 • Decision problems about regular languages
Lecture 26
• Decision problems about regular languages – Basic problems are solvable • halting, accepting, and emptiness problems – Solvability of other problems • many-one reductions to basic problems 1
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 2
Basic Decision Problems (and algorithms for solving them)
3
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 4
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 5
Empty Language Problem
• Input – FSA M • Question – Is L(M)={}?
• How would you solve this problem?
6
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 7
Solving Other Problems (using answer-preserving input transformations)
8
Complement Empty Problem
• Input – FSA M • Question – Is (L(M)) c ={}?
• Use answer-preserving input transformations to solve this problem – We will show that the Complement Empty problem transforms to the Empty Language problem – How do we do this?
• Apply the construction which showed that LFSA is closed under set complement 9
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 10
Input Transformation Illustrated
FSA M Complement Construction FSA M’ Algorithm for solving empty language problem Algorithm for complement empty problem Yes/No The complement construction algorithm is the answer-pres. input transformation.
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.
11
NFA Empty Problem
• Input – NFA M • Question – Is L(M)={}?
• Use answer-preserving input transformations to solve this problem – We will show that the NFA Empty problem transforms 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 12
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 13
Input Transformation Illustrated
NFA M Subset Construction FSA M’ Algorithm for solving empty language problem Algorithm for NFA empty problem Yes/No The subset construction algorithm is the ans.-pres. input transformation.
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.
14
Equal Problem
• Input – FSA’s M 1 • Question and M 2 – Is L(M 1 ) = L(M 2 )?
• Use answer-preserving input transformations to solve this problem – Try and transform 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?
15
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 16
Input Transformation Illustrated
FSA M 1 FSA M 2 2FSA -> 1FSA FSA M 3 Construction Algorithm for solving empty language problem Algorithm for Equal problem Yes/No The 2FSA->1FSA construction algorithm is the ans.-pres. input transformation.
If (M 1 ,M 2 ) is a yes input instance of EQ, then M 3 If (M 1 ,M 2 ) is a no input instance of EQ, then M 3 is a yes input instance of EL.
is a no input instance of EL.
17
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 18