CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Undecidable.

Slides:



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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
1 CSC3130 Formal Languages and Automata Theory Tutorial 9 Undecidable Problem KN Hung SHB 1026.
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.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
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
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.

Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
CS5371 Theory of Computation Lecture 10: Computability Theory I (Turing Machine)
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
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.
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
Decidability of Languages That Do Not Ask Questions about Turing Machines Chapter 22.
Pushdown Automata (PDAs)
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Ambiguity.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Text search.
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.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
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: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.
Lecture 14UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 14.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSCI 3130: Formal languages and automata theory Tutorial 7 Chin.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Undecidable.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY * Read chapter 4 of the book for next time * Lecture9x.ppt.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Undecidable.
Nondeterminism The Chinese University of Hong Kong Fall 2011
TMs for {a2n | n  0} {a2n | n  0}
Turing Machines.
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Undecidable problems for CFGs
Undecidable problems for CFGs
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Reducibility The Chinese University of Hong Kong Fall 2010
Pushdown automata and CFG ↔ PDA conversions
LR(1) grammars The Chinese University of Hong Kong Fall 2010
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.
LR(1) grammars The Chinese University of Hong Kong Fall 2011
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
Presentation transcript:

CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Undecidable problems for CFGs Fall 2011

Decidable vs. undecidable “ TM M accepts w” “ TM M accepts some input ” “ TM M and M’ accept same inputs ” undecidable “ TM M halts on w” “ CFG G generates w” “ DFA M accepts w” decidable “CFG G generates all inputs” “CFG G is ambiguous” more? ? “ DFAs M and M’ accept same inputs ”

Representing computations q0q0 q1q1 q2q2 q5q5 q3q3 q4q4 q6q6 q7q7 qaqa a/xR %/%R b/xL b/xR a/xL a/aR b/bR a/aR b/bR x/xR a/aL b/bL x/xL ☐/☐R☐/☐R %/%R a/aL b/bL x/xR L 1 = {w % w: w ∈ { a, b }*} abbaa%abbaa q0q0 xbbaa%abbaa q1q1... q1q1 xbbaa%abbaa q2q2 xbbaa%xbbaa q5q5... xxxxx%xxxxx qaqa

Configurations A configuration consists of the current state, the head position, and tape contents … aba ☐ q1q1 ab q 1 a q1q1 q acc a/bRa/bR abb q acc … abb ☐ q acc configuration

q0a0b0%0a0b0x0q1b0%0a0b0x0b6q1%0a0b0x0b6%0q2a0b0x0b6q5%0x1b0x0q6b0%0x0b0q0a0b0%0a0b0x0q1b0%0a0b0x0b6q1%0a0b0x0b6%0q2a0b0x0b6q5%0x1b0x0q6b0%0x0b0 Computation histories computation history q0q0 q1q1 q2q2 q5q5 q3q3 q4q4 q6q6 q7q7 qaqa a/xR %/%R b/xL b/xR a/xL a/aR b/bR a/aR b/bR x/xR a/aL b/bL x/xL ☐/☐R☐/☐R %/%R a/aL b/bL x/xR x0x0%0x0x0q7x0x0%0x0x0☐aqax0x0%0x0x0q7x0x0%0x0x0☐aqa...

Computation histories as strings M accepts wq acc occurs in hist M rejects w q rej occurs in hist q0a0b0%0a0b0x0q1b0%0a0bq0a0b0%0a0b0x0q1b0%0a0b x0x0%0x0x0q7x0x0%0x0x0qax0x0%0x0x0q7x0x0%0x0x0qa... If M halts on w, the computation history of (M, w) is the sequence of configurations C 1,..., C l that M goes through on input w. #q 0 ab%ab#xq 1 b%ab#... #xx%xx ☐ q a # C1C1 C2C2 ClCl The computation history can be written as a string hist over alphabet  ∪ Q ∪ {#} accepting history: rejecting history:

Undecidable problems for CFGs We will argue that ALL CFG = { 〈 G 〉 : G is a CFG that generates all strings } The language ALL CFG is undecidable. If ALL CFG can be decided, so can A TM.

Undecidable problems for CFGs 〈 M, w 〉 reject if M accepts w accept if M rej/loops w A reject if not accept if G generates all strings 〈G〉〈G〉 A 〈G〉〈G〉 construct G G generates all strings if M rejects or loops on w G fails to generate some string if M accepts w

Undecidable problems for CFGs 〈 M, w 〉 〈G〉〈G〉 construct G G fails to generate some string M accepts w The alphabet of G will be  ∪ Q ∪ {#} G will generate all strings except the computation history of (M, w), if it is accepting First we construct a PDA P, then convert it to CFG G

Undecidability via computation histories P candidate computation history hist of (M, w) accept everything #q 0 ab%ab#xq 1 b%ab#... #xx%xx ☐ q a # reject except accepting hist On input hist, If w 1 ≠ q 0 w or w k does not contain q a, accept. If two consecutive blocks w i #w i+1 do not follow from the transitions of M, accept. P:P: If hist is not of the form #w 1 #w 2 #...#w k #, accept. Otherwise, hist is an accepting history, so reject. // try to spot a mistake in hist q0q0   

#0q0a0b0%0a0b0#0x0q1b0%0a0b0#0x0b6q1%0a0b0#0x0b6%0q2a0b0#0x0b6q5%0x1b0#0x0q6b0%0x0b0#0q0a0b0%0a0b0#0x0q1b0%0a0b0#0x0b6q1%0a0b0#0x0b6%0q2a0b0#0x0b6q5%0x1b0#0x0q6b0%0x0b0 Computation is local Changes between configurations always occur around the head q0q0 q1q1 q2q2 q5q5 q3q3 q4q4 q6q6 q7q7 qaqa a/xR %/%R b/xL b/xR a/xL a/aR b/bR a/aR b/bR x/xR a/aL b/bL x/xL ☐/☐R☐/☐R %/%R a/aL b/bL x/xR #0x0x0%0x0x0q7#0x0x0%0x0x0☐aqa#0x0x0%0x0x0q7#0x0x0%0x0x0☐aqa...

Legal and illegal transition windows … 6 a 3 b 0 x 0 … … 0 a 6 b 0 x 0 … 0 legal windows … 6 a 3 b 0 a 0 … … 0 a 6 b 0 q 5 … 0 … 6 a 3 q 2 a 0 … … 0 q 5 a 6 x 0 … 0 … 6 q 2 a 0 b 0 … … 0 a 6 b 0 q 2 … 0 illegal windows … 6 a 3 a 0 ☐ 0 … … 0 x 6 a 0 ☐ 0 … 0 q2q2 q5q5 a/xL … 6 a 3 q 2 a 0 … … 0 q 5 a 6 b 0 … 0 … 6 q 2 q 2 a 0 … … 0 q 2 q 2 x 3 … 0 … 6 a 3 q 2 a 0 … … 0 a 6 q 5 x 0 … 0

#0x0b6%0q2a0b#0x0b6q5%0x1b#0x0b6%0q2a0b#0x0b6q5%0x1b Implementing P For every position of w i : Remember first row of window in state After reaching the next # : Pop offset from # from stack as you consume input Remember second row of window in state Remember offset from # in w i on stack If window is illegal, accept; Otherwise reject. offset If two consecutive blocks w i #w i+1 do not follow from the transitions of M, accept:

The computation history method G accepts all strings except accepting computation histories of (M, w) We first construct a PDA P, then convert it to CFG G ALL CFG = { 〈 G 〉 : G is a CFG that generates all strings } If ALL CFG can be decided, so can A TM. 〈 M, w 〉 〈G〉〈G〉 construct G

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 bab cc c ab a ab baa a c ab a baba a baba bab  bab 

Undecidability of PCP PCP = { 〈 T 〉 : T is a collection of tiles that contains a top-bottom match } The language PCP is undecidable.

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

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

Ambiguity of CFGs TG (collection of tiles) bab cc c ab a ab 1 23 Productions: Terminals: T → bab T 1 B → cc B 1 T → c T 2 B → ab B 2 T → a T 3 B → ab B 3 a, b, c, 1, 2, 3 (CFG) Variables: S, T, B S → T | B

Ambiguity of CFGs TG (collection of tiles) bab cc c ab a ab 12 3 Productions: T → bab T 1 Terminals: B → cc B 1 T → c T 2 B → ab B 2 T → a T 3 B → ab B 3 a, b, c, 1, 2, 3 (CFG) Variables: S, T, B S → T | B T → bab1 B → cc1 T → c2 B → ab2 T → a3 B → ab3

Ambiguity of CFGs Each sequence of tiles gives two derivations If the tiles match, these two derive the same string bab cc c ab 1 2 c ab 2 S ⇒ T ⇒ bab T 1 ⇒ babc T 21 ⇒ babcc221 S ⇒ B ⇒ cc B 1 ⇒ ccab B 21 ⇒ ccabab221

Ambiguity of CFGs If G is ambiguous then ambiguity must look like this TG If T can be matched, then G is ambiguous If T cannot be matched, then G is unambiguous (collection of tiles)(CFG) ✓ S T T a1a1 n1n1 aiai nini T a2a2 n2n2 … S B B b1b1 m1m1 bjbj mjmj B b2b2 m2m2 … Then n 1...n i = m 1 …m j ✓ So there is a match a1b1a1b1 a2b2a2b2 aibiaibi n1n1 n2n2 nini …

Undecidability of PCP (optional)

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

Undecidability of PCP Idea: Matches represent accepting histories 〈 M, w 〉 T (collection of tiles)  #q 0 ab%ab #q 0 a #xq 1 aaaa bbbb #### xq 1 % x%q 2 %% … #q 0 ab%ab#xq 1 b%ab#... #xx%xx ☐ q a # aaaa bbbb M accepts wT contains a match

An assumption We will assume that one of the PCP tiles is marked as a starting tile Later we’ll see how to “simulate” the starting tile by an ordinary tile bab cc c ab a ab baa a baba s

Undecidability of PCP On input 〈 M, w 〉 we construct these tiles for PCP 〈 M, w 〉 T (collection of tiles) M accepts w #q0w#q0w s x1qix2x3x4x5x1qix2x3x4x5 for each valid window with state q i in top middle x for all x in  ∪ {#} xqaqaxqaqa ☐#☐#☐#☐# qaxqaqaxqa ☐#qix1☐#x2x3☐#qix1☐#x2x3 q a ## # T contains a match

Undecidability of PCP #q0w#q0w s tile typepurpose represents initial configuration represent valid transitions between configurations add blank spaces before # if necessary complete match if computation accepts xqaqaxqaqa qaxqaqaxqa q a ## # x x1qix2x3x4x5x1qix2x3x4x5 ☐#☐#☐#☐# ☐#qix1☐#x2x3☐#qix1☐#x2x3

Undecidability of PCP accepting computation history #q 0 a%ab#xq 1 %ab#... #xx%xxq 7 ☐ #xx%xx ☐ q a # #q0w#q0w s x ☐#☐#☐#☐# x1qix2x3x4x5x1qix2x3x4x5 ☐#qix1☐#x2x3☐#qix1☐#x2x3 #q0a#q0abab#xq 1 b%ab#... #xx%x xq 7 ☐ # #q 0 ab%ab#xq 1 bab#... #xx%xxq 7 ☐ #xx%x x☐qax☐qa # % %

Undecidability of PCP Once the accepting state symbol occurs, the last two tiles can “eat up” the rest of the symbols x xqaqaxqaqa qaxqaqaxqa q a ## # #xx%xx ☐qa☐qa #xx%xxq a #xx%xq a #... #q a ## #xx%xx ☐ q a #xx%xxqaqa #xx%xqaqa #... #q a ##

Undecidability of PCP If M rejects on input w, then q rej appears on bottom at some point, but it cannot be matched on top If M loops on w, then matching keeps going forever #q0w#q0w s a1qia3b1b2b3a1qia3b1b2b3 for each valid window of this form x for all x in  ∪ {#} xqaqaxqaqa ☐#☐#☐#☐# qaxqaqaxqa ☐#qia2☐#b1b2☐#qia2☐#b1b2 q a ## #

Getting rid of the starting tile We assumed that one tile marked as starting tile We can remove assumption by changing tiles a bit ba bb bcbc a aba s b*a* *b*b c*c*a* *a *a* *a*b*a ** “starting tile” begins with * “final tile” “middle tiles” cca a b* *c

Getting rid of the starting tile b*a* *b*b c*c*a* *a *a* *a*b*a ** b* *c ba bb bcbc a aba s bcbc cca a b* *c can only use as starting tile can only use to complete match