Title: Reductions
1Reductions
- To prove a problem P1 to be hard in some sense
(e.g., undecidable), we can reduce P2, a known
hard problem, to P1 - For each instance w (string in) P2, we construct
an instance x of P1, using some fixed algorithm. - The same algorithm must also turn a string w that
is not in P2 into a string x that is not in P1.
2- We can then argue that if P1 were decidable, we
could use the algorithm in which we transformed w
to x and then test x for membership in P1 as a
way to decide P2 - Since P2 is undecidable, we have a contradiction
of the assumption P1 is decidable - The same idea works for showing P1 not to be RE,
but now P2 must be non-RE, and the transformation
from instances of P2 to instances of P1 may be a
procedure, not necessarily an algorithm - Common error trying to do the reduction in the
wrong direction
3Post's Correspondence Problem
- An undecidable, but RE, problem that appears not
to have anything to do with TM's -
- Given two lists of "corresponding" strings (w1,
w2,, wn) and (x1, x2,, xn), does there exist a
nonempty sequence of integers i1, i2,, ik such
that wi1wi2 wik xi1xi2 xik?
4PCP as a game
- Given a set of cards
- N card types (can use as many copies of each type
as needed) - Each card has a top string and a bottom string
- Example 1
- Puzzle
- Is it possible to arrange cards so that the top
and bottom strings are the same? - Solution 1
BAB
A
AB
BA
A
ABA
B
B
N 4
0
1
2
3
5PCP as a game
- Given a set of cards
- N card types (can use as many copies of each type
as needed) - Each card has a top string and a bottom string
- Example 1
- Puzzle
- Is it possible to arrange cards so that the top
and bottom strings are the same? - Solution 1
BAB
A
AB
BA
ABA
B
B
A
N 4
0
1
2
3
6Another example
- Given a set of cards
- N card types (can use as many copies of each type
as needed) - Each card has a top string and a bottom string
- Example 2
- Puzzle
- Is it possible to arrange cards so that the top
and bottom strings are the same? - Solution 2
A
A
ABA
B
N 4
B
A
B
BAB
0
1
2
3
No. The first card in the solution must contain
the same letter in the leftmost position.
7PCP Puzzle Contest
- Contest
- Additional restriction string must start with
'S'. - Be the first to solve this puzzle!(no credit,
just fame and acclamation) - Check solutions at
- http//www.cs.princeton.edu/introcs/74computabilit
y/pcp/pcp.php
8PCP is undecidable
- We can try all lists i1, i2,, ik in order of k.
If we find a solution, the answer is "yes." But
if we never find a solution, how can we be sure
no longer solution exists? - So we can never say "no."
9Argument by Reduction
- We can show (see Appendix)
- Lu can be reduced to an intermediate problem,
MPCP - This is done simply for convenience
- MPCP can be reduced to PCP
- So, if PCP is decidable, so is Lu
- But we know Lu is undecidable
- Therefore, PCP is undecidable
- or, if PCP were decidable, Lu would also be
decidable (but it isn't)
10Reducing One Undecidable Problem to Another
- We say a problem A is reduced to problem B if
the decidability of A follows from the
decidability of B - Then, if we know A is undecidable, we can
conclude that B is also undecidable - The typical case is to use the Halting Problem
(ATM), since we know it is undecidable - Important point the proof that the Halting
Problem is undecidable does not preclude solving
it for specific cases--it only states that this
cannot always be done. I.e., there is no
algorithm that can make a correct decision for
all TM/input pairs.
11Undecidable Problems
- We have already established that the Halting
problem (ATM) is undecidable. - Related problem
- HTM ltM,wgtM is a TM and M halts on input w
-
- Question How is this language different from
ATM?
ATM is really the acceptance problem
12HTM is undecidable
- Proof
- By contradiction
- Assume HTM is decidable
- Let R be a TM that decides HTM
- Use R to construct S, a TM that decides ATM
- Deciding ATM is reduced to HTM
- Since ATM is undecidable, so is HTM
13- Assume R decides HTM
- Define S as follows
- On input ltM,wgt,
- Run R on ltM,wgt
- If R rejects, reject
- If R accepts, simulate M on w until it halts
- If M accepted, accept otherwise reject
14The State Entry Problem
- Given any TM M (Q,?,?,?,B,F) and any q ? Q, w
? ?, decide whether or not the state q is ever
entered when M is applied to w. - This problem is undecidable
- Step 1
- Reduce ATM to the State-entry Problem
- Assume an algorithm A that solves the state-entry
problem. We could then use it to solve ATM - E.g., given any M and w, first modify M to get M1
in such a way that M1 halts in state q if and
only if M halts.
15- Do this by looking at ? of M
- if M halts, it does so because some ?(qi,a) is
undefined. - To get M1 we change every such undefined ? to
- ?(qi,a) (q,a,R)
- (q is a final state)
- Now, apply the state-entry algorithm A to
(M1,q,w) - If A answers yes (i.e., state q is entered) then
(M,w) halts. - If A answers no (M,w) does not halt.
- Therefore the assumption that the state-entry
problem is decidable gives us an algorithm to
decide the Halting Problem - But because the Halting Problem is undecidable,
the state-entry problem must also be undecidable
16Reductions involving TM behaviors
- Undecidable behavior properties normally restrict
the Turing machine's behavior in cosmetic ways,
but still allow it to complete the standard range
of Turing machine tasks - Such a problem involves a language L which is a
set of all Turing machines with a specific
behavior B - E.g. L ltMgt M prints three 1's in a row on
blank input or L ltMgt M has a state which is
never entered on any input string - For this class of problems, reductions typically
require modifying the input Turing machine code
ltMgt to create code for a new Turing machine ltM'gt
which does pretty much the same thing as M except
that - When M would have halted, M' first does behavior
B before halting, and - M' never accidently does behavior B while it's
computing - Typical example of this type of reduction is the
state entry problem, where M mimics M until M
halts, then goes to state q and it is ensured
that M' can never go into state q unless M halts
17The Blank-tape Halting Problem
- Another problem to which the Halting Problem can
be reduced - Given a TM M, determine whether or not M halts if
started with a blank tape - This problem is undecidable
- How to do the reduction
- Assume we are given some M and some w
- Construct from M a new machine Mw that starts
with a blank tape, writes w on it, then positions
itself in a configuration (q0,w) - After that, Mw acts like M
- Clearly, Mw will halt on a blank tape if and only
if M halts on w
18- KEY
- Suppose the blank-tape halting problem is
decidable - Given any (M,w), construct Mw
- Apply the blank-tape halting problem algorithm to
it - The conclusion tells us whether or not M applied
to w will halt - Since this can be done for any M and any w, an
algorithm for the blank-tape halting problem can
be converted into an algorithm to solve the
halting problem - BUT the halting problem is undecidable, so the
blank-tape halting problem must also be
undecidable
19- These examples show the common approach using
reduction
Visualization of the process for the blank-tape
halting problem
Halts
generate Mw
blank-tape halting algorithm A
Halts
Mw
M,w
Does not halt
Does not halt
20Reductions involving l(M)
- Problems concerning the language of a TM often
require S to significantly rewrite the code for M
before feeding it to R - Or, this can be viewed as creating a new TM Mw
that behaves quite differently from M - The new Turing machine often has w "hardcoded"
into it - The new TM is usually designed so that it accepts
one set of strings if M accepts w, and a totally
different set of strings if M doesn't accept w - One of these sets should have the property that R
tests for and the other should not - For example, Mw accepts all input strings if M
accepts w, and accepts no input strings if M does
not accept w
21- The code for Mw typically involves simulating M
on w, plus some other (trivial) tests on x - For some reductions, we test x first, e.g.
- input is a string x
- If x has some easily-tested property P, accept
- Simulate M on w and accept if M accepts w.
- For either of these two steps, you could also
take the opposite action, e.g. reject all strings
x that have property P - Examples of this pattern are REGULARTM and ETM
22Does a TM accept a regular language?
- RTM ltM,wgtM is a TM and L(M) is regular
- Theorem REGULARTM is undecidable
- Proof by contradiction
- Assume REGULARTM is decidable
- Let R be a TM that decides REGULARTM
- Use R to construct S, a TM that decides ATM
- but how?
23- Modify M so that the resulting machine accepts a
regular language if and only if M accepts w - Design Mw so that
- if M does not accept w, then Mw accepts the
non-regular language 0n1nn 0 - if M accepts w, then Mw accepts the regular
language ?
24- From M and w define Mw
- On input x,
- If x has the form 0n1n, accept
- Otherwise, run M on input w and accept if M
accepts w - Now, feed Mw to R
- if R accepts, S accepts
- if R rejects, S rejects
- If M does not accept w, then Mw accepts 0n1nn
0 - If M accepts w, then Mw accepts ? (i.e., any
string x) -
25Is the language of a TM empty?
- ETM ltM,wgtM is a TM and L(M) ?
- Theorem ETM is undecidable
- Proof idea
- By contradiction
- Assume ETM is decidable
- Let R be a TM that decides ETM
- Use R to construct S, a TM that decides ATM
26- One approach
- When S receives input ltM,wgt, it calls R with
input M - If R accepts, then reject, because M does not
accept w - I.e., R says L(M) is empty, so it must not accept
w - But what if R rejects?
- Then we do not know if M accepts w or not
- Solution Modify M
27- Define Mw
- On input x
- if x ? w, reject.
- if x w, run M on w and accept if M does
- Mw either
- accepts w, or
- accepts nothing
-
28S
accepts if x w rejects if not
rejects if Mw accepts accepts if not
R
Mw
reject M accepts w
M,w
Mw
accept M rejects w
29- For some reductions, we simulate M on w first,
before we test x - Code for Mw looks like
- Simulate M on w
- If M rejects, reject
- Otherwise, accept exactly when x has some
easily-tested property P - An example of this pattern is the proof of Rices
theorem (see Sipsers solved exercise 5.28)
30Tips
- Note that in code rewriting reductions, the
string w is an input to the machine S, i.e. the
machine that decides ATM, and the string x is an
input to the Turing machine Mw - The input to the Turing machine R is usually the
code for the machine Mw w and x are not inputs
to R - The value of w may be hardcoded into the code for
Mw - The value of x is not specified (you can imagine
that Mw will ask the user to input a value for x)
31Is an arbitrary RE language empty?
Reductions involving languages
- Reduce ATM to this problem
- Suppose we are given a TM M and a string w
- Modify M such that
- M first saves its input on some special part of
its tape - Whenever M enters a final state, it checks the
saved input and accepts if and only if it is w - Do this by changing ? in a simple way
- Create for each w a machine Mw such that
- L(Mw) L(M) ? w
32- Then, construct a corresponding grammar Gw
- Clear that L(Gw) is nonempty if and only if w ?
L(M) - Assume there exists an algorithm A for deciding
whether or not L(G) ? - Let T denote an algorithm by which we generate Gw
- Put T and A together to create a TM that for any
M and w, tells us whether or not w ? L(M)
S
L(Gw) not empty
T construct Gw
w ? L(M)
A emptiness algorithm
Gw
M,w
w ? L(M)
L(Gw) empty
33Conclusion
- If such a TM existed, we would have a membership
algorithm for RE languages - But we know membership for REs is undecidable
- So, L(G) ? is not decidable
34Is L(M) finite?
- Use ATM again
- From M construct another TM M' in which
- Halting states of M are changed so that if any
one is reached, all input is accepted by M' - Achieve this by having any halting configuration
go to a final state - M is modified so that M' first generates w on its
tape, then performs the same computations as M
using the newly created w and some other unused
space - Moves of M' after writing w on its tape are the
same as those performed by M, had it started in
the original configuration (q0,w) - If M halts on any configuration, then M' will
halt in a final state
35- If (M,w) halts, M' will halt in a final state for
all input. - If (M,w) does not halt, M' will not halt either
and so will accept nothing - In other words M' either accepts the infinite
language ? or the finite language ? - If we assume the existence of an algorithm A that
tells whether L(M') is finite, then can solve the
halting problem
L(M') finite
generate M'
Does not halt
finiteness algorithm A
M'
M,w
Halts
L(M') not finite
36Does L(M) contain two strings of the same length?
- Use the same approach as in the previous example,
except when M' reaches a halting configuration,
it is modified to accept two strings a and b of
equal length - To do this
- Initial input is saved and at the end of the
computation compared to a and b - Accepts only these two strings
- Therefore, if (M,w) halts, M' will accept two
strings of equal length - Otherwise M' accepts nothing
- Finish up the argument as in the previous problem
37Are two TMs equivalent?
- EQTM ltM1,M2gt M1, M2 are TMs and
- L(M1) L(M2)
- Theorem EQTM is undecidable
- We are getting tired of reducing everything to
ATM - Lets try reduction to ETM
38Theorem EQTM is undecidable
- Proof Idea
- ETM is the problem of testing whether a TMs
language is empty - EQTM is the problem of testing whether two TM
languages are the same. - If one of these two TM languages happens to be
empty, then we are back to ETM - So ETM is a special case of EQTM
- The rest is easy
39- Let MNO be the TM
- 1. reject
- Let R decide EQTM
- Let S be
- On input ltMgt
- Run R on input ltM, MNO gt
- If R accepts, accept if R rejects, reject
40ReductionsBasic Template
- To prove that a language L is undecidable, you
will normally want to use a reduction from a
language already known to be undecidable (e.g.
ATM) - A reduction proof will look something like this
- Suppose that L were decidable. Let R be a Turing
machine deciding L. We will now construct a
Turing machine S that decides ATM. - S is constructed as follows
- Input is ltM,wgt, where M is the code for a Turing
Machine and w is a string. - Pseudocode explaining how S decides whether M
accepts w, using R as a subroutine. - But we know that ATM is undecidable. So S can't
exist. Therefore we have a contradiction. So L
must have been undecidable. - Sometimes you can write a shorter/simpler proof
by replacing ATM with some other problem known to
be undecidable - you may need to change the inputs to S
- e.g. elements of the language EQTM are pairs of
Turing machines a reduction from EQTM requires
constructing a Turing machine S whose inputs are
pairs ltM1,M2gt of two Turing machines. - If you aren't sure what problem to reduce to L,
ATM is normally a good choice
41Bucket of Undecidable Problems
- Same techniques prove undecidability of
- Does a TM accept a decidable language?
- Does a TM accept a context-free language?
- Is there an input string that causes a TM to
traverse all its states? - Does L(M) contain any string of length 5?
- These are (creatively) called "similar questions"
42Rices Theorem
- By now, some of you may have become cynical and
embittered - Like, been there, done that, bought the T-shirt
- Looks like any non-trivial property of TMs is
undecidable
That is correct
43Rices Theorem
- If C is a proper non-empty subset of the set of
enumerable languages, then it is undecidable
whether for a given TM M, L(M) is in C
44Undecidable Problems About CFL'sPCP is a
convenient tool for studying undecidable
questions about CFLs
- Example
- You have been asked to convert RE's to DFA's, but
there is an algorithm to convert RE's to DFA's,
so it is at least possible for you to succeed - Suppose you are asked to take a CFG and tell
whether it is ambiguous. You can't do it because
the problem is undecidable!
45Reduction of PCP to CFG Ambiguity Problem
- Given lists A and B, construct grammar as
follows - S ? A B.
- A is the start symbol for a grammar from list A
B is the same for list B. - If there is a solution to the PCP instance, then
the same string can be derived starting S ? A and
S ? B - Conversely, the only way a string can have two
leftmost derivations is if they begin in these
two ways, because the grammar of each list is
unambiguous.
lm
lm
46Example
- Use the lists (1, 0, 010, 11) and (10, 10, 01, 1)
- Let a, b, c, d stand for the four index integers
- That is, we have
-
- a b c d
- The grammar is
- S ? A B
- A ? 1Aa 0Ab 010Ac 11Ad ?
- B ? 10Ba 10Bb 01Bc 1Bd ?
1
0
010
11
10
10
01
1
Each string has a unique derivation from A and B
Ambiguity can only come from S
47S ? A B A ? 1Aa 0Ab 010Ac 11Ad ? B ?
10Ba 10Bb 01Bc 1Bd ?
- A string with two leftmost derivations
- 10101001011dccaba
- CONCLUSION
- The grammar constructed from (A,B) is ambiguous
if and only if there is a solution to instance
(A,B) of PCP - In this case, there is a way to get a
corresponding pair of strings
S ? B ? 10Ba ? 1010Bba ? 101010Baba
? 10101001Bcaba ? 1010100101Bccaba ?
10101001011Bdccaba ? 10101001011dccaba
S ? A ? 1Aa ? 10Aba ? 101Aaba ?
101010Acaba ? 101010010Accaba ?
10101001011Adccaba ? 10101001011dccaba
48A Hierarchy of Formal Languages and Automata
- We have already seen the following
- A language is recursively enumerable if there is
a TM that accepts it - A language is recursive if there is a TM that
accepts it and halts on every w in ? - There are languages that are not recursively
enumerable (i.e., the ones we showed are not
countable using the diagonalization argument) - There are RE languages whose complement is not RE
- If both a language and its complement are RE then
both are recursive - There are RE languages that are not
recursive--i.e., the family of recursive
languages is a proper subset of the family of RE
languages
49Unrestricted Grammars
- A grammar (V,T,S,P) is unrestricted if all the
productions are of the form u ? v, where u is in
(V ? T) and v is in (V ? T) - Basically, no restrictions imposed on productions
- Any number of variables on the left and
right-hand sides - Can occur in any order
- Only restriction is that ? cannot appear on the
left side of a production - Any language generated by an unrestricted
grammar is recursively enumerable - Proof the grammar in effect defines a procedure
for enumerating all the strings in the language
systematically - Since the set of productions is finite, we can
simulate the derivations on a TM to enumerate
every string in the language
50Context-Sensitive Grammars
- Between the unrestricted grammars and the
"restricted" CFGs, there is a variety of
"somewhat restricted" grammars - A grammar is context-sensitive if all
productions are of the form x ? y, where x,y are
in (V ? T) and x y - Fundamental property
- grammar is non-contracting--i.e., the length of
successive sentential forms can never decrease - Why "context-sensitive"?
- All productions can be rewritten in a normal form
xAy ? xvy - Effectively, "A can be replaced by v only in the
context of a preceding x and a following y"
51Example
- CSG for anbncn n 1
- Try to derive a3b3c3
S ? aAbc ?abAc ? abBbcc ? aBbbcc ?
aaAbbcc ? aabAbcc ? aabbAcc ? aabbBbccc
? aabBbbccc ? aaBbbbccc ? aaabbbccc
S ? abc aAbc Ab ? bA Ac ? Bbcc bB ? Bb aB
? aa aaA
A and B are "messengers"- an A is created on the
left, travels to the right to the first c,
creates another b and c. Then sends B back to
create the corresponding a. Similar to the way
one would program a TM to accept the language.
52Linear-Bounded Automata
- A limited TM in which tape use is restricted
- Use only part of the tape occupied by the input
- I.e., has an unbounded tape, but the mount that
can be used is a function of the input - Restrict usable part of tape to exactly the cells
taken by the input - LBA is assumed to be nondeterministic
53Relation between CSLs and LBAs
- If a language L is accepted by some linear
bounded automaton, then there is a
context-sensitive grammar that generates L. - Every step in a derivation from a CSG is a
bounded function of w because any CSG G is
non-contracting
54CSLs and Recursive Languages
- Every context-sensitive language is recursive.
- There exists a recursive language that is not
context-sensitive. - I.e., context sensitive languages are a proper
subset of recursive languages
55The Chomsky Hierarchy
Turing Machine
r
Recursively Enumerable Languages
Context Sensitive Languages
Linear Bounded Automata
Context Free Languages
Regular Languages
Push Down Automata
Finite Automata
56Expanded Hierarchy
r
Recursively Enumerable Languages
Turing Machine
Recursive Languages
Context Sensitive Languages
Turing Machine that halts
Context Free Languages
Linear Bounded Automata
Deterministic CFL
Regular Languages
Push Down Automata
Deterministic PDA
Finite Automata
57APPENDIX
APPENDIX
APPENDIX
58Using Reduction to Show Virus Detection is
Undecidable
- Virus Detection
- Melissa Virus
- Input A Word macro (like a program, but embedded
in an email message) - Output true if the macro will forward the
message to people in your address book false
otherwise.
How can we show it is undecidable?
59Undecidability Proof
- Suppose we could define is-virus? that decides
the Melissa problem.
(define (halts? P) (if (is-virus? (begin P
virus-code)) t f))
Since it is a virus, we know virus-code was
evaluated, and P must halt (assuming P wasnt a
virus).
Its not a virus, so the virus-code never
executed. Hence, P must not halt.
60Undecidability Proof
- Suppose we could define is-virus? that decides
the Melissa problem.
(define (halts? P) (is-virus? (begin
(vaccinate P) virus-code))
Where (vaccinate P) evaluates to P with all mail
commands replaced with print commands (to make
sure (is-virus? P) is false.
61Proof
- If we had is-virus? we could define halts?
- We know halts? is undecidable
- Hence, we cant have is-virus?
- Thus, we know is-virus? is undecidable
62PCP problem as dominos
- Begin with a collection of dominos, each
containing two strings, one on each side - Task make a list of the dominos (repetitions
permitted) so that the string we get reading
across the top is the same as the one across the
bottom (call this a solution) - PCP is to determine whether a collection of
dominos has a solution.
63Example
- (1, 0, 010, 11) and (10, 10, 01, 1).
- A solution is 1, 2, 1, 3, 3, 4.
- The constructed string from both lists is
10101001011.
64Another Example
- (10, 011, 101) and (101, 11, 011).
- Another argument why this instance of PCP has no
solution - The first index has to be 1 because only the pair
10 and 101 begin with the same symbol. - Then, whatever indexes we choose to continue,
there will be more 1's in the string constructed
from the first list than the second (because in
each corresponding pair there are at least as
many 1's in the second list). Thus, the two
strings cannot be equal.
65Plan to Show PCP is Undecidable
- Introduce MPCP, where the first pair must be
taken first in a solution. - Show how to reduce MPCP to PCP.
- Show how to reduce Lu to MPCP.
- This is the only reason for MPCP it makes the
reduction from Lu easier. - Conclude that if PCP is decidable, so is MPCP,
and so is Lu (which we know is false).
66Reduction of MPCP to PCP
- Trick
- given a MPCP instance, introduce a new symbol .
- In the first list, appears after every symbol,
but in the second list, the appears before
every symbol. - Example
- the pair 10 and 011 becomes 10 and 011.
- Notice that no such pair can ever be the first in
a solution.
67- Take the first pair w1 and x1 from the MPCP
instance (which must be chosen first in a MPCP
solution) and add to the PCP instance another
pair in which the 's are as always, but w1 also
gets an extra at the beginning. - Referred to as "pair 0."
- Example if 10 and 011 is the first pair, also
add to the PCP instance the pair 10 and
011. - Finally, since the strings from the first list
will have an extra at the end, add to the PCP
instance the pair and . - is a new symbol, so this pair can be used only
to complete a match. - Referred to as the "final pair."
68Proof the Reduction is Correct
- If the MPCP instance has a solution 1 followed by
i1, i2,, ik, then the PCP instance has a
solution, which is the same, using the first pair
in place of pair 1, and terminating the list with
the final pair. - If the PCP instance has a solution, then it must
begin with the "first pair," because no other
pair begins with the same symbol. - Thus, removing the 's and deleting the last pair
gives a solution to the MPCP instance.
69Reduction of Lu to MPCP
- Intuition The equal strings represent a
computation of a TM M on input w. - Sequence of ID's separated by a special marker .
- First pair is and q0w.
- String from first list is always one ID behind,
unless an accepting state is reached, in which
case the first string can "catch up."
70 Some Example Pairs
- X and X for every tape symbol X. Allows copying
of symbols that don't change from one ID to the
next. - If ?(q,X) (p,Y,R), then qX and Yp is a pair.
Simulates a move for the next ID. - If q is an accepting state, then XqY and q is a
pair for all X and Y. Allows ID to "shrink to
nothing" when an accepting state is reached.
71Constructing MPCP P'
- Put ( , q0,w1,w2,wn) as the first pair.
- For every a, b ? ? and every q, r ? Q, if ?(q,a)
(r,b,R) put (qa , br) into P' - For every a, b,c ? ? and every q, r ? Q, if
?(q,a) (r,b,L) put (cqa , rcb) into P' - For every a ? ? put (a , a) into P'
- Put (,) (to separate configurations) and (,B)
(to simulate the infinite blanks to the right
that are suppressed when the configuration is
written) into P'
Must extend top string to match rest
q0 w1 w2 wn
match so far
72What we have so far
- Suppose ? 0,1,2,B, w 0100, start state is
q0, ?(q0,0) (q7,2,R) - STEP 1
- STEP 2 adds (q00 , 2q7)
- STEP 4 adds (0,0), (1,1), (2,2), (B,B)
q0 0 1 0 0
q0 0 1 0 0 q0 0 1 0 0 2 q7 1 0 0
73- Suppose ?(q0,0) (q7,2,R) and ?(q5,0) (q9,2,L)
- Add (q71 , 0q5)
- Add (0q50 , q902), (1q50 , q912), (2q50 , q922),
(Bq50 , q9B2)
2 q7 1 0 0 2 q7 1 0 0 2 0 q5 0 0
74- Continues until M reaches a halting state--if
also an accept state, let the top of the partial
match "catch up" - Add two more items to P'
- For every a ? ?, put (aqA , qA) and (qAa , qA)
into P', where qA ? F.
2 1 qA 0 2
2 1 qA 0 2 2 1 qA 0 2
2 1 qA 2 qA
75- Put (qA , ) into P'
- We have thus shown that Lu can be reduced to
MPCP. - Last step show that M accepts w if and only if
the constructed MPCP instance has a solution. - Only-if we have shown that the computation can
be mimicked, providing the solution. - If the MPCP will only provide a solution if we
reach an accepting state, so that the two strings
are of equal lengths. Otherwise, we never perform
step 7, which enables the strings to become equal
in length.
76Undecidable ProblemIs the Intersection of Two
CFL's Empty?
- Consider the two list languages from a PCP
instance. They have an empty intersection if and
only if the PCP instance has no solution.
77Complements of List Languages
- We can get other undecidability results about
CFL's if we first establish that the complement
of a list language is a CFL. - PDA is easier approach.
- Accept all ill-formed input (not a sequence of
symbols followed by indexes) using the state. - For inputs that begin with symbols from the
alphabet of the PCP instance, store them on the
stack, accepting as we go.
78- When index symbols start, pop the stack, making
sure that the right strings were found on top of
the stack again, keep accepting until - When we expose the bottom-of-stack marker, we
have found a sequence of strings from the PCP
list and their matching indexes. This string is
not in the complement of the list language, so
don't accept. - If more index symbols come in, then we have a
mismatch, so start accepting again and keep on
accepting.
79Undecidable Problem Is a CFL Equal to ??
- Take an instance of PCP, say lists A and B.
- The union of the complements of their two list
languages is ? if the instance has no solution,
and something less if there is a solution.
80Undecidable ProblemIs the Intersection of Two
CFL's Regular?
- Key idea the intersection of list languages is
regular if and only if it is empty. Thus, PCP
reduces to regularity of intersection for CFL's. - Obviously, if empty, it is regular.
- Suppose the intersection of two list languages,
for A and B, LA ? LB, is nonempty. Then there is
a solution to this instance of PCP, say string w
and string of index symbols i. - Example for the running PCP instance, w
10101001011 and I abaccd.
81- Then ik is an index sequence that yields solution
wk for all k. - General principle concatenation of PCP solutions
is a solution. - Consider homomorphism h(0) w and h(1) iR.
- h-1(LA ? LB) is 0n1n n ? 1
- Since regular languages are closed under inverse
homomorphism, if the intersection were regular,
so would h-1(LA ? LB) be. - Since we know this language is not regular, we
conclude that LA ? LB is not regular.