Undecidable Problems for CFGs
CSCI 3130 Formal Languages and Automata Theory
Siu On CHAN Fall 2019
Decidable vs undecidable
Decidable Undecidable
DFAD accepts w TMM accepts w CFGG generates w TMM halts on w DFAsD and D0accept same
inputs
TMM accepts some input TM M and M0 accept the
same inputs CFGG generates all inputs?
Configurations
Aconfigurationconsists of current state, head position, and tape contents
Configuration (abbreviation)
q1 a b a … abq1a
q1 a/bR qacc
Computation histories as strings
IfM halts on w, thecomputation historyof (M, w) is the sequence of configurationsC1, . . . ,CkthatM goes through on input w
q0ab%ab xq2b%ab ... xx%xxq1 xx%xqaccx #q0ab%ab | {z } C1 #xq1b%ab | {z } C2 #…#xx%xqaccx | {z } Ck #
The computation history can be written as a string h over alphabet Γ ∪ Q ∪ {#}
accepting history: M accepts w ⇔ qaccappears inh
Undecidable problems for CFGs
ALLCFG= {hGi | G is a CFG that generates all strings}
The language ALLCFGis undecidable
We will argue that
If ALLCFGcan be decided, so canATM
Undecidable problems for CFGs
Proof by contradiction
Suppose some Turing machineA decides ALLCFG A
hGi accept ifG generates all strings reject otherwise
We want to construct a Turing machineS that decides ATM
Convert toG A hM, wi accept if M rejects or loops onw reject ifM accepts w hGi S
Undecidable problems for CFGs
Convert to G
hM, wi hGi
Gfails to generatesome string m
M accepts w ThealphabetofG will be Γ ∪ Q ∪ {#}
G will generate all stringsexcept
Undecidablility via computation histories
P candidate compu-tation historyh of (M, w) accept everything except acceptingh #q0ab%ab#xq1b%ab#…#xx%xqaccx# ⇒ RejectP = on input h (try to spot amistakeinh) • Ifh isnotof the form #w1#w2#…#wk#,accept
• Ifw16=q0w or wkdoesnotcontainqacc,accept
• If two consecutive blockswi#wi+1donotfollow from the transitions ofM,accept
Computation is local
q0 q1 qacc q2 q3 q4 q5 q6 q7 a/xR b/x%/%RR x/xR /L a/aR b/bR %/%R x/xR a/aR b/bR %/%R x/xR a/xL b/xL a/aL b/bL x/xL %/%L a/aL b/bL x/xR q0ab%ab aq2b%ab abq2%ab ab%q3ab abq2%xb ... xx%xxq1 xx%xqaccxLegal and illegal transitions windows
legal windows illegal windows
Implementing
P
If two consecutive blockswi#wi+1donot
follow from the transitions ofM,accept
#xb%q3ab
#xbq5%xb
For every position ofwi:
Remember offset from # inwion stack 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
The computation history method
ALLCFG= {hGi | G is a CFG that generates all strings}
If ALLCFGcan be decided, so canATM
Convert to G
hM, wi hGi
G accepts all stringsexcept
accepting computation history of (M, w)
Post Correspondence Problem
Input: A fixed set of tiles, each containing a pair of strings bab cc c ab a ab baa a a baba bab ε
Given an infinite supply of tiles from a particular set, can you match top and bottom?
Undecidability of PCP
PCP = {hTi |
T is a collection of tiles that contains a top-bottom match} Next lecture we will show (using computation history method)
Ambiguity of CFGs
AMB = {hGi | G is an ambiguous CFG} The language AMB is undecidable
We will argue that
Ambiguity of CFGs
T (collection of tiles) 7−→ G (CFG) IfT can be matched, then G is ambiguous IfT cannot be matched, then G is unambiguous
Ambiguity of CFGs
Each sequence of tiles gives a pair of derivations
bab cc c ab c ab 1 2 2
S ⇒ T ⇒ babT1 ⇒ babcT21 ⇒ babcc221 S ⇒ B ⇒ ccB1 ⇒ ccabB21 ⇒ ccabab221 If the tilesmatch, these two derive the same string
Ambiguity of CFGs
T (collection of tiles) 7−→ G (CFG) IfT can be matched, then G is ambiguous 3
IfT cannot be matched, then G is unambiguous 3