Professional Documents
Culture Documents
Lecture 24
Some examples on the notion of context-free languages.
Eg.: A “ tw | #a pwq ă #b pwq ă #c pwqu Is A regular?
Let’s use pumping lemma to prove otherwise. Given k, choose z “ ak bk`1 ck`2 , z P A. Let
now, z “ uvwxy, s.t. vx ‰ ϵ, and |vwx| ď k.
We would have to break it into several cases. One of the several cases is: v contains only a’s
and y contains only b’s so v “ am , y “ bk ; 1 ď m ` l ď k.
Let i “ 3, we have thus the pumped string uv 3 wx3 y “ ak`2m bk`2l`1 ck`2 .
Since vx ‰ ϵ, we have either m ě 1, and l ě 1.
If m ě 1, then k ` 2m ě k ` 2, which would imply that uv 3 wx3 y R A.
If l ě 1, then k ` 2l ` 1 ě k ` 2, which would again imply, that uv 3 wx3 y R A.
Similar to proving that no grammar has ww represented. Take ak bk ak bk , and proceed accord-
ingly.
It is not a CFL. While enumeratig cases in the pumping lemma with z “ ak bk ck P A, let us
consider a single case, where v consists of b’s, and x consists of c’s. Take i “ 0, we would have
ak bk´m ck´l R A.
Taking intuition from how an NPDA will handle this. We can start pushing a’s onto the stack,
and then pop while b’s come until the stack is empty. After which we start pushing onto the stack,
while reading b’s, and again start popping when a’s are encountered again. The stack must remain
not-empty after the starting.
S Ñ ABC A Ñ aAb | ϵ B Ñ bB | b C Ñ bCa | ϵ
Finite-state automata + semi-infinite automata (infinite to the right and delimited on the left
with a marker $)
Head can move both left and right, and can read as well as write on the tape.
Infinitely many cells to the right of the finite input string, contain a special blank character \.
M “ pQ, Σ, Γ, $, \, δ, s, t, rq
Σ : finite input alphabet
Γ : finite tape alphabet Σ Ď Γ
\ P Γ ´ Σ : blank symbol
$P Γ ´ Σ : left end marker
s P Q : start state
t P Q : accept state
r P Q : reject state
δ : Q ˆ Γ Ñ Q ˆ Γ ˆ tL, Ru
δ is the transition function, and we have δpp, aq “ pq, b, loomo
d on q
P tL, Ru
Assumptions:
- @p P Q, Dq P Q s.t. δpp, $q “ δpq, $, Rq
1 1 1 1
- b P Γ, Dc, c P Γ and d, d P tL, Ru s.t. δpt, bq “ pt, c, dq and δpr, bq “ pr, c , d q. That is, once
M enters accept/reject state, it never leaves it.
Lecture 25
Configurations of a Turing Machine
Tape of M consists of a string y\w where y P Γ˚ . A configuration is P Q ˆ ty \w | ysinΓ˚ u ˆ N.
A configuration of TM: pp, z, nq, where p is state P Q, z is the current content on the tape,
and n ě 0 is the current position of the head on the tape.
Start configuration: ps, $ x\w , 0q
1
Next configuration relation: ÝÑ.
M
For an infinite string z, let zn , be the nth symbol in z, and snb pzq string obtained by substituting
zn with b.
#
1 pq, snb pzq, n ´ 1q if δpp, zn q “ pq, b, Lq
pp, z, nq ÝÑ
M pq, snb pzq, n ` 1q if δpp, zn q “ pq, b, Rq
˚ 1
α ÝÑ β be the reflexive-transitive closure of ÝÑ
M M
˚
Thus we have, M accepts x P Σ˚ , if ps, $ x\w , 0q ÝÑ pt, y, nq.
M
LpM q “ tx P Σ˚ | M accepts xu
˚
M rejects x P Σ˚ , if ps, $ x\w , 0q ÝÑ pr, y, nq.
M
Total Turing Machine: A Turing Machine that halts on all inputs is called a total TM.
$ aabbbaabbb \ \\
$ aabbbaabbb % \\
$ à à b̀ b̀ b̀ á á b́ b́ b́ % \ \
$ \ \ b̀ b̀ b̀ \ \ b́ b́ b́ % \ \
Lecture 26
Proving the claim: if both A, and Ā are r.e., then A is recursive.
Let LpM1 q “ A and LpM2 q “ Ā. Construct M , that on input x runs both on M1 and M2 ,
simultaneously on two tracks of the tape. If M1 accepts, M accepts, and if M2 accepts then M
rejects.
Decidable / Semi-decidable
A property P is decidable, iff the set of all strings satisfying P is a recursive set.
P is decidable if tx | P pxqu is recursive.
A property P is semi-decidable, iff the set of all strings satisfying P is a r.e.
P is semi-decidable if tx | P pxqu is r.e.
5
Universal Machines
An observation about the power of Turing machines: there exists Turing machines that can
simulate other Turing machines whose descriptions are presented as a part of the input. First
a encoding scheme needs to be fixed, so that the other machine can read and decode the en-
coded machine M . Consider the first line of the encoding representing the machine is as follows:
0n 10m 10k 10s 10t 10r 10u 10v 1. This might indicate that the machine has n states, from 0 to n ´ 1,
6
it has m tape symbols, represented 0 to m ´ 1, of which the first k represent the input symbols
and s, t, r are start, accept and reject states, and endmarker and blank symbol are u, v.
The remainder of the string may represent the various transition in δ. For eg. 0p 101 10q 10b 1,
which might encode the transition ppp, aq, pq, b, Lqq.
Te exact details of the encoding is not necessary, the only requirement is that it should be easy
enough to interpret.
Once we have the encoding of the TM, we can create a Universal Turing Machine U , s.t.
LpU q “ tM #x | x P LpM qu. In other words, given the encoding of the machine M , and the string
x over input alphabet, separated by a #, we can have, and U accepts M #x ðñ M accepts x.
Since the input alphabet of input machine M might be different from the input alphabet of
U , which might mean that a single symbol in x might be represented as a string of symbols in U
and vice versa. In general, to simulate each step of M , we might require many steps of U .
Instead of a blind simulation, can we do something better, can one build a TM which on input
M #x, halts and accepts if M halts and accepts, and halts and rejects, if either M halts and
rejects, or it loops?
Lecture 27
Consider the sets,
HP “ tM #x | M halts on xu
M P “ tM #x | x P LpM qu
We shall establish that HP, M P are r.e. but not recursive.
Technique of Diagonalization
It was used to show that there is not a one-to-one correspondence between 2N and N.
Suppose such a function f : N Ñ 2N , exists which is onto. Consider the infinite two-dimensional
matrix which is 1 at the position i, j if j P f piq and 0 otherwise.
7
0 1 2 3 4 ...
f p0q 1 0 0 1 1
f p1q 1 0 1 0 0
f p2q 0 0 0 1 1
...
We can construct a new set which does not appear on the list by complementing the main
diagonal.
Now consider an infinite two-dimensional matrix indexed along the top by strings in t0, 1u˚
and down the left by the TMs in the list. The matrix contains an H in position x, y if Mx halts
on input y and an L if Mx loops on input y.
ϵ 0 1 00 01 ...
Mϵ H L L H H
M0 H L H L L
M1 L L L H H
...
The xth row of the matrix describes for each input string y whether or not Mx halts on y.
Suppose there exists a total TM K accepting the set HP ; i.e. a machine that for any given x and
y could determine the x, y entry of the above table. Thus on the input M #x, K halts and accepts
if M halts on x and K rejects if M loops on x.
This says that N ’s behaviour is different from Mx on at least one string, namely x. But since
the list was to contain all the Turing machines over the input alphabet t0, 1u, including N , which
means this is a contradiction.
Suppose there exists a total TM K, s.t. LpKq “ M P . Given a TM M and input x. To check
if M halts on x. Build a new TM NM that does the following. Similar to M , NM accepts if M
accepts or rejects. For all x P Σ˚ , NM accepts x iff M halts on x.
For any M and x to check if M halts on x. Construct NM and run K on input NM #x. By
1 1
assumption K is a total TM. But then we can construct a total K s.t. LpK q “ HP . This is a
contradiction.
Lecture 28-29
HP is not recursive, HP is r.e. M P is not recursive, M P is r.e. [HP , M P is not r.e.]
- Is it decidable if a TM M accepts ϵ?
- Is it decidable if a TM M , LpM q “ ϕ?
- Is it decidable if a TM M , LpM q “ Σ˚ ?
Is ϵ P LpMq?
Let there exist a total TM K such that given an input machine M , accepts if ϵ P LpM q and rejects
1
if not. We will show that if such a K exists then DK (another total TM) such that given M #x,
accepts if M halts on x and rejects otherwise (basically solves the halting problem) and hence we
will arrive at a contradiction.
Is it decidable if a TM M accepts ϵ?
Is tM | ϵ P LpM qu recursive?
Suppose D a total TM K that can decide if a given TM accepts ϵ, i.e. LpKq “ tM | ϵ P LpM qu.
1 1
Then we can construct a total TM K s.t. LpK q “ HP .
Given a TM M and x, to determine if M halts on x. Construct M1 that on input y works as
follows:
1. Erases its input y.
2. Writes x on the tape.
3. Runs M on input x. [M, x are hard-coded in M1 ]
4. Accepts if M halts on x.
Is it decidable if a TM M , LpM q “ Σ˚ ?
OR
Is tM | LpM q “ Σ˚ u?
Is LpMq regular?
Is it decidable for a TM M if LpM q is regular? Or in other words: is tM | LpM q is regularu recur-
sive?
Choose a set A that is r.e. but not recursive. Eg.: A “ HP or A “ M P . Let N be a TM s.t.
LpN q “ A.
Suppose D a total TM K that can decide, given an arbitrary TM M , if LpM q is regular, then
1 1
using K, we can construct a total TM K s.t. LpK q “ HP (given M, x to determine if M halts
on x).
Construct a TM M2 (with multiple tracks) which on input y does the following:
1. Writes y on one of the tracks.
2. Writes x on a separate track.
3. Runs M on input x.
4. If M halts on x then M2 runs N on y (y is M2 original input). M2 accepts if N accepts y.
If M does not halt on x then M2 does not accept any string.
#
A if M halts on x
LpM2 q “
ϕ if M does not halt on x
Since A is neither recursive, nor a CFL, nor regular, and ϕ is all of those three things. If one
could decide whether a given TM accepts a recursive, CFL or regular set, then one could apply
this decision procedure to M2 and this would tell whether M halts on x.
Reduction
Given sets A Ď Σ˚ and B Ď Γ˚ , a (many-one) reduction of A to B is a computable function
σ : Σ˚ Ñ Γ˚ , such that @ x P Σ˚ x P A ðñ σpxq P B.
In other words strings in A must go to strings in B under σ, and strings not in A must go to
strings not in B under σ.
10
A function σ need not be one-one or onto. It must be totally and effectively computable. This
means σ must be computable by a total Turing machine, that on input x halts with σpxq written
on the tape.
When such a reduction exists, we say A is reducible to B via the map σ and we write A ďm B.
The subscript m represents many-one, and is used to distinguish it from other types of reducibility
relations.
Lecture 30-31
Consider the following theorems:
Theorem: If A ďm B, and B is r.e. then A is also r.e. Similarly, if A ďm B and A is not r.e.
then B is not r.e.
Theorem: If A ďm B, and B is recursive then A is also recursive. Similarly, if A ďm B and
A is not recursive then B is not recursive.
Proof :
1. Suppose A ďm B, over σ and B is r.e, therefore B “ LpM q for some TM M . Construct a
TM N s.t. LpN q “ A as follows:
On input x:
- Compute σpxq
- Run M on σpxq
- Accept if M accepts
N accepts x, iff σpxq accepts M iff σpxq P B iff x P A.
loooooooooomoooooooooon
Definition of A ďm B
Rice theorem
Theorem: Every non-trivial property of r.e. sets is undecidable.
Proof of Rice Theorem: Let P be a non-trivial property of set. WLOG, let P pϕq “ K, and
P pAq “ J for some A, where A is r.e. Let K be a TM, s.t. LpM q “ A.
We will give a reduction HP ď tM | P pLpM qq “ Ju.
1
Given M and x, construct M “ σpM #xq, which on input y does the following:
1. Saves y on one of the tracks
2. Writes x on another track
3. Runs M on x.
1
4. If M halts on x, then K (TM whose language was A), is run on y, and M accepts if K
accepts. If M does not halt on x, step 3 does not terminates.
1
If M does not halt on x, then step 3 does not ends, and hence y P LpM q for all y.
1
If M halts on x, then y P LpM q ðñ y P LpKq “ A.
Thus we have,
1 1
M halts on x ñ LpM q “ A ñ P pLpM qq “ P pAq “ J.
12
1 1
M does not halt on x ñ LpM q “ ϕ ñ P pLpM qq “ P pϕq “ K.
Thus we have HP ď tM | P pLpM qq “ Ju ñ not recursive. Thus it is undecidable if LpM q
satisfies P .
$ b1 b2 ... bk ... bm
- - - ... q ... -
$ b1 b2 ... bn
s - - ... -
Lecture 32
We shall use the construct V ALCOM P S to give solution to the universality problem of CFLs.
Claim 1:V ALCOM P SpM, xq is a CFL.
Claim 2:We can construct CFG G for V ALCOM P SpM, xq from the description of M and x.
Observation: LpGq “ ∆˚ iff M does not halts on x. (established later)
Reduction: HP “ tG | G is a CFG and LpGq “ ∆˚ u
1. z must begin and end with a #. It must be of the form #α1 #α2 #...#αN #.
2. Each αi is a string of symbols of the form pa, ´q or pa, qq, where exactly one symbol of αi
has an element of Q on the bottom (second element of the tuple), and others have ´, and
only the leftmost has a $ on top.
• For condition 2, it suffices to check that between every two #’s there is exactly one symbol
with q P Q on the bottom, and $, occurs on immediately after $ (except the last) and
nowhere else. A2 is a regular set.
$ a b a b a a b
- - - - q - - -
goes to
$ a b a a a a b
- - - p - - - -
if δpq, bq “ pp, a, Lq
Note: αi and αi`1 agree on most symbol except potentially once within a boundary of 3.
1
How to check α ÝÑ β? Check all 3 letter substrings of α and there corresponding substring v
M
of β (occurring at the same distance from #).
1
Thus, to check if α ÝÑ β does not hold, we to check whether their exists a substring of length
M
3 in α, such the corresponding substring in β is not consistent with δ.
V ALCOM P S revpM, xq “ #α1 #α2 ...., D G1 , G2 CFGs s.t. G1 XG2 “ V ALCOM P S revpM, xq.