Undecidable problems for CFGs

Slides:



Advertisements
Similar presentations
CSCI 3130: Formal languages and automata theory Tutorial 9
Advertisements

INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Variants of Turing machines
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Variants.
February 6, 2015CS21 Lecture 141 CS21 Decidability and Tractability Lecture 14 February 6, 2015.
1 Section 14.1 Computability Some problems cannot be solved by any machine/algorithm. To prove such statements we need to effectively describe all possible.
Reducibility A reduction is a way of converting one problem into another problem in such a way that a solution to the second problem can be used to solve.
Theory of Computation What types of things are computable? How can we demonstrate what things are computable?
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS5371 Theory of Computation Lecture 10: Computability Theory I (Turing Machine)
CS5371 Theory of Computation Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
Decidability A decision problem is a problem with a YES/NO answer. We have seen decision problems for - regular languages: - context free languages: [Sections.
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Turing Machines.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Turing.
 2005 SDU Lecture13 Reducibility — A methodology for proving un- decidability.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Turing Machines.
Turing Machine. Turing machine The mathematical models (FAs, TGs, PDAs) that have been discussed so far can decide whether a string is accepted or not.
Lecture 9  2010 SDU Lecture9: Turing Machine.  2010 SDU 2 Historical Note Proposed by Alan Turing in 1936 in: On Computable Numbers, with an application.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Undecidable.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
1 Section 13.1 Turing Machines A Turing machine (TM) is a simple computer that has an infinite amount of storage in the form of cells on an infinite tape.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
CSCI 3130: Formal languages and automata theory Tutorial 7 Chin.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 3 The Church-Turing Thesis Contents Turing Machines definitions, examples,
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Undecidable.
Summary of Previous Class There are languages that are not decidable –(we have not proved this yet) Why not extend Turing machines just as we did with.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Decidable.
CS 154 Formal Languages and Computability April 28 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Theory of Computation Automata Theory Dr. Ayman Srour.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Undecidable.
February 1, 2016CS21 Lecture 121 CS21 Decidability and Tractability Lecture 12 February 1, 2016.
Nondeterminism The Chinese University of Hong Kong Fall 2011
TMs for {a2n | n  0} {a2n | n  0}
More variants of Turing Machines
Turing Machines.
CS21 Decidability and Tractability
Theorem 29 Given any PDA, there is another PDA that accepts exactly the same language with the additional property that whenever a path leads to ACCEPT,
Intro to Theory of Computation
Pushdown Automata PDAs
PDAs Accept Context-Free Languages
Pushdown Automata PDAs
Undecidable problems for CFGs
CSE 2001: Introduction to Theory of Computation Fall 2013
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Reducibility The Chinese University of Hong Kong Fall 2010
Turing Machines Acceptors; Enumerators
Pushdown automata and CFG ↔ PDA conversions
Jaya Krishna, M.Tech, Assistant Professor
Intro to Theory of Computation
Decidable Languages Costas Busch - LSU.
Decidability Turing Machines Coded as Binary Strings
Decidability Turing Machines Coded as Binary Strings
Decidable and undecidable languages
Reducability Sipser, pages
CS21 Decidability and Tractability
CS21 Decidability and Tractability
More undecidable languages
Recap lecture 44 Decidability, whether a CFG generates certain string (emptiness), examples, whether a nonterminal is used in the derivation of some word.
Decidability and Tractability
CS 461 – Nov. 14 Section 5.2 – Undecidable problems starting from ATM:
Pushdown automata The Chinese University of Hong Kong Fall 2011
Subject Name: FORMAL LANGUAGES AND AUTOMATA THEORY
More undecidable languages
Automata, Grammars and Languages
Intro to Theory of Computation
Presentation transcript:

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 http://www.cse.cuhk.edu.hk/~andrejb/csc3130

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? ?

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

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)

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

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

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.

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

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

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.

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

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

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

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.

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

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.

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 …

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

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∪{#}

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## #

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

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## #

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∪{#}

“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 *

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.

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

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

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

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

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