Presentation is loading. Please wait.

Presentation is loading. Please wait.

Undecidable problems for CFGs

Similar presentations


Presentation on theme: "Undecidable problems for CFGs"— Presentation transcript:

1 Undecidable problems for CFGs
The Chinese University of Hong Kong Fall 2008 CSC 3130: Automata theory and formal languages Undecidable problems for CFGs Andrej Bogdanov

2 Decidable vs. undecidable
“DFA M accepts w” “TM M accepts w” “PDA M accepts w” “TM M halts on w” “DFA M accepts all inputs” “TM M accepts some input” “TM M and M’ accept same inputs” “CFG G generates all inputs” “CFG G is ambiguous” other kinds of problems? ?

3 Representing computations
L1 = {w$w: w ∈{a, b}*} a/aR b/bR x/xR $/$R a/aL abbaa$abbaa q0 q1 q2 b/bL a/aL a/xL b/bL xbbaa$abbaa q1 x/xR x/xL a/xR xbbaa$abbaa ... q1 $/$R ☐/☐R $/$R q0 q7 qa q5 q6 b/xR b/xL xbbaa$abbaa q2 q3 q4 xbbaa$xbbaa q5 $/$R ... xxxxx$xxxxx qa a/aR x/xR b/bR x/xR

4 Turing Machine configuration
time 0 abbaa$abbaa #q0abbaa$abbaa☐ q0 time 1 q1 xbbaa$abbaa #xq1bbaa$abbaa☐ ... time 6 xbbaa$abbaa q2 #xbbaa$q2abbaa☐ A configuration of TM M at time t is a string over alphabet G∪Q∪{#} that represents the state, tape head, and “touched” part of tape of M after t steps of work (possibly with ☐s)

5 Computation histories
a/aR b/bR x/xR #0q0a0b0$0a0b0☐ #0x0q1b0$0a0b0☐ #0x0b6q1$0a0b0☐ #0x0b6$0q2a0b0☐ #0x0b6q5$0x1b0☐ #0x0q6b0$0x0b0☐ $/$R a/aL q1 q2 b/bL a/aL a/xL b/bL x/xR x/xL a/xR $/$R ☐/☐R $/$R q0 q7 qa q5 q6 b/xR b/xL ... q3 q4 $/$R #0x0x0$0x0x0q7☐ #0x0x0$0x0x0☐aqa a/aR x/xR b/bR x/xR computation history

6 Computation histories as strings
If M halts on w, We can represent the computation history by a string hist over alphabet G∪Q∪{#} #0q0a0b0$0a0b0☐ #0x0q1b0$0a0b0☐ ... #q0ab$ab☐#xq1b$ab☐#...#xx$xx☐qa# #0x0x0$0x0x0q7☐ #0x0x0$0x0x0☐aqa M accepts w qa occurs in string hist M rejects w qa does not occur in hist

7 Undecidable problems for PDAs
ALLPDA = {〈P〉: P is a PDA that accepts all inputs} Theorem Proof: We will show that The language ALLPDA is undecidable. If ALLPDA can be decided, so can ATM.

8 Undecidable problems for PDAs
accept if P accepts all inputs reject if not accept if M rej/loops w A 〈P〉 〈M〉, w reject if M accepts w P accepts all inputs if M rejects or loops on w P does not accept some input if M accepts w

9 Undecidability via computation histories
P accepts all inputs if M rejects or loops on w P does not accept some input if M accepts w candidate computation history of M on w P reject accepting histories #q0ab$ab☐#xq1b$ab☐#...#xx$xx☐qa# reject every other string accept M accepts w P rejects hist M rej/loops on w no accepting histories P accepts everything

10 Undecidability via computation histories
Task: Design a PDA P such that candidate computation history hist of M on w P reject accepting histories Input: hist of the form w1#w2#...#wk# #0q0a0b0$0a0b0☐ #0x0q1b0$0a0b0☐ If w1 ≠ #q0w , accept hist. If hist does not contain qa, accept hist. ... #0x0x0$0x0x0q7☐ #0x0x0$0x0x0☐aqa If two consecutive blocks wi#wi+1 do not correspond to a proper transition of M, accept hist.

11 Computation is local #0q0a0b0$0a0b0☐ #0x0q1b0$0a0b0☐ #0x0b6q1$0a0b0☐
a/aR b/bR x/xR #0q0a0b0$0a0b0☐ #0x0q1b0$0a0b0☐ #0x0b6q1$0a0b0☐ #0x0b6$0q2a0b0☐ #0x0b6q5$0x1b0☐ #0x0q6b0$0x0b0☐ $/$R a/aL q1 q2 b/bL a/aL a/xL b/bL x/xR x/xL a/xR $/$R ☐/☐R $/$R q0 q7 qa q5 q6 b/xR b/xL ... q3 q4 $/$R #0x0x0$0x0x0q7☐ #0x0x0$0x0x0☐aqa a/aR x/xR b/bR x/xR The changes between configurations occur in a 2x3 window

12 Implementing P valid transition
On input hist: Nondeterministically make one of the following choices Look in the first block w1 of hist If w1 ≠ #q0w, accept hist. Look for the appearance of qa If t does not contain qa, accept hist. #0x0b6$0q2a0b0☐ #0x0b6q5$0x1b0☐ Look for the beginning of the ith block of hist If two consecutive blocks wi#wi+1 do not represent a valid transition of M, accept hist. valid transition wi#wi+1 represents a valid transition if all 3x2 windows correspond to possible transitions of M

13 Valid and invalid windows
… 6a3b0x0 … … 0a6b0x0 …0 … 6q2a0b0 … … 0a6b0q2 …0 … 6a3q2a0 … … 0q5a6x0 …0 … 6q2q2a0 … … 0q2q2x3 …0 q2 a/xL … 6a3b0a0 … … 0a6b0q5 …0 … 6a3q2a0 … … 0q5a6b0 …0 q5 … 6a3a0☐0 … … 0x6a0☐0 …0 … 6a3q2a0 … … 0a6q5x0 …0

14 Implementing P How to check wi#wi+1 represents a valid transition:
Nondeterministically look for a 3x2 window #0x0b6$0q2a0b0☐ #0x0b6q5$0x1b0☐ Remember window offset on stack valid transition Remember first row of window in state Locate the second row of window Go past next #, then keep reading/popping until stack is empty offset Remember second row of window in state If window is not valid, accept; Otherwise reject.

15 The Post Correspondence Problem
Input: A set of tiles like this Given an infinite supply of such tiles, can you match top and bottom? bab cc c ab a ab baa a a baba bab e a ab baa a bab e c ab c ab bab cc a baba

16 Undecidability of PCP PCP = {〈T〉: T is a collection of tiles that contains a top-bottom match} The language PCP is undecidable. Proof: We will show that If PCP can be decided, so can ATM.

17 Undecidability of PCP 〈M, w〉 T
(collection of tiles) If M accepts w, then T can be matched If M rej/loops on w, then T cannot be matched Idea: Matches represent accepting histories #q0ab$ab#xq1b$ab#...#xx$xx☐qa# #q0ab$ab#xq1b$ab#...#xx$xx☐qa# e #q0ab$ab #q0a #xq1 b a $ # xq1$ x$q2

18 Some technicalities We will assume that
TM M never attempts to move left of first cell One of the PCP tiles is marked as a starting tile These assumptions can be made without loss of generality (we will see why later) s bab cc c ab a ab baa a a baba

19 for each valid window with state qi in top middle
Undecidability of PCP 〈M, w〉 T (collection of tiles) If M accepts w, then T can be matched If M rej/loops on w, then T cannot be matched To decide ATM, we construct these tiles for PCP s e #q0w x1qix2 x3x4x5 ☐#qix1 ☐#x2x3 ☐# xx xqa qa qax qa qa## # for each valid window with state qi in top middle for all x in G∪{#}

20 Undecidability of PCP tile type purpose s e #q0w
represent initial configuration represent transitions between configurations x1qix2 x3x4x5 xx add blank spaces if necessary ☐#qix1 ☐#x2x3 ☐# complete match if computation accepts xqa qa qax qa qa## #

21 Undecidability of PCP #q0a$ab#xq1$ab#...#xx$xxq7☐#xx$xx☐qa#
accepting computation history #q0a b $ ab# xq1b$ab#... #xx$x xq7☐ # #q0ab$ab #xq1 b $ ab# ...#xx$xxq7☐ #xx$x x☐qa # s e #q0w x1qix2 x3x4x5 ☐#qix1 ☐#x2x3 ☐# xx

22 Undecidability of PCP Once the accepting state symbol occurs, the last two tiles can “eat up” the rest of the symbols #xx$xx ☐qa #xx$x xqa #xx$xqa#... # qa## #xx$xx☐qa #xx$xx qa #xx$x qa #...#qa # # xx xqa qa qax qa qa## #

23 for each valid window of this form
Undecidability of PCP If M rejects on input w, then qreject appears on bottom at some point, but it cannot be matched on top If M loops on w, then matching keeps going forever s e #q0w a1qia3 b1b2b3 ☐#qia2 ☐#b1b2 ☐# xx xqa qa qax qa qa## # for each valid window of this form for all x in G∪{#}

24 “starting tile” begins with *
A technicality We assumed that one tile marked as starting tile We can remove assumption by changing tiles a bit s a baba bab cc c ab *a* *b*a*b*a b*a*b* *c*c c* *a*b * “starting tile” begins with * “middle tiles” “ending tile” matches last *

25 Ambiguity of CFGs AMB = {G: G is an ambiguous CFG} Theorem
Proof: We will show that The language AMB is undecidable. If AMB can be decided, so can PCP.

26 Ambiguity of CFGs T G Proof: Step 1: Number the tiles
(collection of tiles) (CFG) If T can be matched, then G is ambiguous If T cannot be matched, then G is unambiguous Proof: Step 1: Number the tiles 1 2 3 bab cc c ab a ab

27 Ambiguity of CFGs T G Terminals: a,b,c,1,2,3 Variables: S, T, B
(collection of tiles) (CFG) Terminals: a,b,c,1,2,3 Variables: S, T, B Productions: T → babT1 T → cT2 S → aT3 B → ccS1 B → abB2 B → abB3 1 2 3 bab cc c ab a ab S → T | B

28 Ambiguity of CFGs T G Terminals: a,b,c,1,2,3 Variables: S, T, B 1 2 3
(collection of tiles) (CFG) Terminals: a,b,c,1,2,3 Variables: S, T, B 1 2 3 Productions: bab cc c ab a ab S → T | B T → babT1 T → cT2 T → aT3 T → bab1 T → c2 T → a3 B → ccS1 B → abB2 B → abB3 B → cc1 B → ab2 B → ab3

29 Ambiguity of CFGs Each sequence of tiles gives two derivations
If the tiles match, these two derive the same string 1 2 2 bab cc c ab c ab S ⇒ T ⇒ babT1 ⇒ babcT21⇒ babcc221 S ⇒ B ⇒ ccB1 ⇒ ccabB21⇒ ccabab221

30 Ambiguity of CFGs T G ✓ ✓ Argue by contradiction:
(collection of tiles) (CFG) If T can be matched, then G is ambiguous If T cannot be matched, then G is unambiguous Argue by contradiction: If G is ambiguous then ambiguity must look like this S S Then n1...ni = m1…mj T B So there is a match a1 T n1 b1 m1 B n1 n2 ni a2 n2 b2 m2 a1 b1 a2 b2 ai bi T B ai ni bj mj


Download ppt "Undecidable problems for CFGs"

Similar presentations


Ads by Google