Cmu Toc Lecture19
Cmu Toc Lecture19
Cmu Toc Lecture19
FORMAL LANGUAGES,
AUTOMATA AND
COMPUTABILITY
THURSDAY APRIL 3
FINITE
STATE
q0
CONTROL
I N P U T
INFINITE TAPE
CONFIGURATIONS
11010q700110
q7
1 1 0 1 0 0 0 1 1 0
COMPUTATION HISTORIES
An accepting computation history is a
sequence of configurations C1,C2,…,Ck, where
1. C1 is the start configuration, C1=q0w
2. Ck is an accepting configuration, Ck=uqacceptv
3. Each Ci follows from Ci-1 via the transition
function δ
A rejecting computation history is a sequence
of configurations C1,C2,…,Ck, where
1. C1 is the start configuration,
2. Ck is a rejecting configuration, Ck=uqrejectv
3. Each Ci follows from Ci-1
M accepts w
if and only if
0n10m10k10s10t10r10u1…
Reject if M accepts M
D( M ) = i.e. if H(M,M) accepts
Accept if M does not accept M
i.e. if H(M,M) rejects
ATM = { (M,w) | M is a TM that accepts string w }
ATM is undecidable: (proof by contradiction)
Assume machine H decides ATM
Accept if M accepts w
H( (M,w) ) =
Reject if M does not accept w
Reject if M
D accepts D
M
D( M
D)=
Accept if M
D does not acceptDM
ATM = { (M,w) | M is a TM that accepts string w }
ATM is undecidable: (constructive proof & subtle)
Assume machine H SEMI-DECIDES ATM
Accept if M accepts w
H( (M,w) ) =
Rejects or Loops otherwise
r(w) = t(<R>, w)
THE RECURSION THEOREM
Theorem: Let T be a Turing machine that computes
a function t : Σ* × Σ* → Σ*.
Then there is a Turing machine R that computes a
function r : Σ* → Σ*, where for every string w,
r(w) = t(<R>, w)
(a,b) T t(a,b)
w R t(<R>,w)
Recursion Theorem says:
A Turing machine can obtain its own
description (code), and compute with it
. We can use the operation:
“Obtain your own description”
in pseudocode!
Given a computable t, we can get a computable r
such that r(w) = t(<R>,w) where <R> is a description of r
Contradiction. Why?
MINTM = {<M>| M is a minimal TM, wrt |<M>|}
Example:
r(w) = t(<R>, w)
(a,b) T t(a,b)
w R t(<R>,w)
THE RECURSION THEOREM
Theorem: Let T be a Turing machine that computes
a function t : Σ* × Σ* → Σ*.
Then there is a Turing machine R that computes a
function r : Σ* → Σ*, where for every string w,
r(w) = t(<R>, w)
w Q <Pw> Pw
w
TM Q computes q
A TM SELF THAT PRINTS <SELF>
w’ P<B> B (<B>)
<B> B
B
w’ P<M> M (<M>)
<M> B
M
SELF
w’ B (<B>)
<B> P<B>
w P<B> B
B
A TM SELF THAT PRINTS <SELF>
w’ P<M>
<M> B
M
SELF
w’ P<B>
<B>
w P<B> B
B
A NOTE ON SELF REFERENCE
Suppose in general we want to design a
program that prints its own description. How?
Σ* A B Σ*
f
A≤m B
Σ* A B Σ*
f
A≤m B
Σ* Σ*
f
ATM ≤m HALTTM
ATM HALTTM
s ∈ Σ*
Σ* Σ*
f
ATM ≤m ¬ E
ATM TM ¬ ETM
s ∈ Σ*
Σ* Σ*
f
ATM ≤m REGTM
ATM REGTM
s ∈ Σ*
f: (M,w) → M’w where M’w (s) = accept if s = 0n1n,
M(w) otherwise
So, (M, w)∈ ATM ⇔ M’w ∈ REGTM
ETM = { M | M is a TM and L(M) = ∅ }
EQTM = {( M, N) | M, N are TMs and L(M) =L(N)}
Σ* Σ*
f
ETM ≤m EQTM
ETM EQTM
s ∈ Σ*
Σ* Σ*
f
ATM ≤m¬ALLPDA
ATM ¬ ALLPDA
Σ* Σ*
f
ATM ≤m FPCP
ATM FPCP
Σ* Σ*
f
ATM ≤m PCP
ATM PCP
ALL UNDECIDABLE
Use Reductions to Prove
ATM = { (M,w) | M is a TM that accepts string w }
HALTTM = { (M,w) | M is a TM that halts on string w }
ETM = { M | M is a TM and L(M) = ∅ } ¬ ETM
ALL UNDECIDABLE
Use Reductions to Prove
Which are SEMI-DECIDABLE?
RICE’S THEOREM
Let L be a language over Turing machines.
Assume that L satisfies the following properties:
1. For any TMs M1 and M2, where L(M1) = L(M2),
M1 ∈ L if and only if M2 ∈ L
2. There are TMs M1 and M2,
where M1 ∈ L and M2 ∉ L
Then L is undecidable
EXTREMELY POWERFUL!
RICE’S THEOREM
Let L be a language over Turing machines.
Assume that L satisfies the following properties:
1. For any TMs M1 and M2, where L(M1) = L(M2),
M1 ∈ L if and only if M2 ∈ L
2. There are TMs M1 and M2,
where M1 ∈ L and M2 ∉ L
Then L is undecidable
FINTM = { M | M is a TM and L(M) is
ETM = { M | M isfinite}
a TM and L(M) = ∅ }
REGTM = { M | M is a TM and L(M) is regular}
Proof: Show L is undecidable
Show: ATM is mapping reducible to L
Σ* ATM L Σ*
f
(M,w)
(M,w)
Proof: Show L is undecidable
Show: ATM is mapping reducible to L
Σ* ATM L Σ*
f
(M,w) M1
(M,w) M2
RICE’S THEOREM
Proof:
Define M∅ to be a TM that never halts
Assume, WLOG, that M∅ ∉ L Why?
Let M1 ∈ L (such M1 exists, by
assumption)
Show ATM is mapping reducible to
L:
Map (M, w) Mw where
Σ* ATM L Σ*
f
(M,w) Mw ≡ M1
(M,w) Mw ≡ M∅
QED
Corollary: The following languages are
undecidable.
Is (M,w) in
FINITE ATM?
STATE
qqYES
?
CONTROL
YES
I N P U T
INFINITE TAPE
A Turing Reduces to B
We say A is decidable in B if there is an
oracle TM M with oracle B that decides A
A ≤T B
≤T is transitive
≤T VERSUS ≤m
Theorem: If A ≤m B then A ≤T B
But in general, the converse doesn’t hold!
Proof:
If A ≤m B then there is a computable function
f : Σ* → Σ*, where for every w,
w ∈ A ⇔ f(w) ∈ B
We can thus use an oracle for B to decide A
∑ 0
n+1 = { sets semi-decidable in some B ∈ ∑ 0
}
n
Π 0
n = { complements of sets in ∑ 0
}
n
∆ 01
∑ 01 ∆ 0
2 ∑ 0
2 ∆ 0
3
∑ 0 Π 0
3
3
∆ 0
3
∑ 02 Π 02
∆ 0
2
∑ 01 Π1 0
Semi- Co-semi-
decidable ∆ 0
1
decidable
Languages Languages
0
= ∑ ∩ Π
0
1 1
Decidable Languages
Definition: A decidable predicate R(x,y) is some
proposition about x and y1, where there is a TM M
such that
∑ 0
1
= { semi-decidable sets }
= languages of the form { x | ∃y R(x,y) }
Π 0
1
= { complements of semi-decidable sets }
= languages of the form { x | ∀y R(x,y) }
∆ 01 = { decidable sets }
= ∑ 0
1
Π
∩ 10
∑ 0
2
= { sets semi-decidable in some semi-dec. B }
= languages of the form { x | ∃y1∀y2 R(x,y1,y2) }
Π = { complements of ∑ 2
0 0
sets}
2
= languages of the form { x | ∀y1∃y2 R(x,y1,y2) }
∆ 0
2
= ∑ 0
2
Π
∩ 20
∑ 0
n
= languages { x | ∃y1 ∀y2 ∃y3 …Qyn R(x,y1 ,…,yn) }
Π 0
n
= languages { x | ∀y1 ∃y2 ∀y3 …Qyn R(x,y1 ,…,yn) }
∆ 0
n
= ∑ 0
n
Π
∩ n0
decidable predicate
ATM = { <(M,w)> | ∃t T (<M>, w, t )}
ATM = { <(M,w)> | ∃v (v is an accepting
computation history of M on w}
∑ 0
Π 0
3
∆0 3
3
∑ 0 Π 0
2
2
∆ 0
2
= ∑ 02 ∩ Π 02
Π 0
∑ 0
1
1
Semi- ATM Co-semi-
decidable decidable
languages ∆ 01 languages
Decidable languages
Example
∑ 0 Π 0
2
2
∆ 0
2
= ∑ 02 ∩ Π 02
Π 0
∑ 0
1
1
Semi- ATM EMPTY Co-semi-
decidable decidable
languages ∆ 01 languages
Decidable languages
Example
decidable predicate
Example
TOTAL = { M | ∀w ∃t [ T(<M>, w, t) ] }
decidable predicate
∑ 0
Π 0
3
∆0 3
3
∑ 0 Π 0
2 TOTAL 2
∆ 0
2
= ∑ 02 ∩ Π 02
Π 0
∑ 0
1
1
Semi- ATM EMPTY Co-semi-
decidable decidable
languages ∆ 01 languages
Decidable languages
Example
decidable predicate
∑ 0
Π 0
3
∆0 3
3
∑ 0
FIN Π 0
2 TOTAL 2
∆ 0
2
= ∑ 02 ∩ Π 02
Π 0
∑ 0
1
1
Semi- ATM EMPTY Co-semi-
decidable decidable
languages ∆ 01 languages
Decidable languages
COF
∑ 0
Π 0
3
∆0 3
3
∑ 0
FIN Π 0
2 TOTAL 2
∆ 0
2
= ∑ 02 ∩ Π 02
Π 0
∑ 0
1
1
Semi- ATM EMPTY Co-semi-
decidable decidable
languages ∆ 01 languages
Decidable languages
REG
∑ 0
Π 0
3
∆0 3
3
∑ 0
FIN Π 0
2 TOTAL 2
∆ 0
2
= ∑ 02 ∩ Π 02
Π 0
∑ 0
1
1
Semi- ATM EMPTY Co-semi-
decidable decidable
languages ∆ 01 languages
Decidable languages
DEC
∑ 0
Π 0
3
∆0 3
3
∑ 0
FIN Π 0
2 TOTAL 2
∆ 0
2
= ∑ 02 ∩ Π 02
Π 0
∑ 0
1
1
Semi- ATM EMPTY Co-semi-
decidable decidable
languages ∆ 01 languages
Decidable languages
CFL
∑ 0
Π 0
3
∆0 3
3
∑ 0
FIN Π 0
2 TOTAL 2
∆ 0
2
= ∑ 02 ∩ Π 02
Π 0
∑ 0
1
1
Semi- ATM EMPTY Co-semi-
decidable decidable
languages ∆ 01 languages
Decidable languages
Each is m-complete for its level in
hierachy and cannot go lower (by next
Theorem, which shows the hierarchy
does not collapse).
ORACLES not all powerful
The following problem cannot be decided, even by
a TM with an oracle for the Halting Problem:
Proof Idea.
1. Let ATM,1 = ATM
A TM, n+1 = {(M,x)| M is an oracle machine
with oracle ATM and M accepts x}
Then ATM, n ∈ ∑ 0
n
- Π 0
n
Theorem:
1. The hierarchy is strict
2. Each of the languages is m-complete
for its class.
Proof.
2. Eg to show FIN is m-complete for ∑ 0
2
Need to show
FIN = { M| ∃n ∀x ∀t (|x| <n or
a) FIN ∈ ∑ 02 M does not accept x in t
steps)}
b) For A ∈ ∑ 02 then A ≤m FIN
For A ∈ ∑
0
2 , A={ x | ∃y∀z R(x,y,z)}
FIN = { M | L(M) is finite }
Σ* Σ*
f
A FIN
Given input w:
f: x → Mx For each y of length |w| or less, look for z
such that ¬ R(x,y,z)} . If found for all such y,
Accept. Otherwise keep on running.
For A ∈ ∑
0
2 , A={ x | ∃y∀z R(x,y,z)}
FIN = { M | L(M) is finite }
Σ* Σ*
f
A FIN
A = 01010101010101010101010101010101
B = 110010011101110101101001011001011
Recall:
A = 01010101010101010101010101010101
Proof:
M = “On input x ∈ {0,1}*,
Interpret x as integer n. (|x| ≤ log n)
Find first y ∈ {0,1}* in lexicographical order,
s.t. (y,n) ∉ COMPRESS, then print y and
halt.”
M(x) prints the first string y* with K(y*) > n.
Thus <M,x> describes y*, and |<M,x>| ≤ c + log n
So n < K(y*) ≤ c + log n. CONTRADICTION!
DETERMINING COMPRESSIBILITY
Proof:
M = “On input x ∈ {0,1}*,
Interpret x as integer n. (|x| ≤ log n)
Find first y ∈ {0,1}* in lexicographical order,
s. t. K(y) > n , then print y and halt.”
For example:
P= ∪ k
TIME(n )
k∈N
Definition: A Non-Deterministic TM is a 7-tuple
T = (Q, Σ, Γ, δ, q0, qaccept, qreject), where:
TIME(t(n)) ⊆ NTIME(t(n))
NP = ∪ k
NTIME(n )
k∈N
Theorem: L ∈ NP ⇔ if there exists a poly-time
Turing machine V with
L = { x | ∃y [|y| = poly(|x|) and V(x,y) accepts ] }
Proof:
P = NP?
Can Problem Solving Be Automated?
$$$
A Clay Institute Millennium Problem
POLY-TIME REDUCIBILITY
f : Σ* → Σ* is a polynomial time computable
function if some poly-time Turing machine M,
on every input w, halts with just f(w) on its tape
w ∈ A ⇔ f(w) ∈ B
1. SAT ∈ NP:
A satisfying assignment is a “proof” that a
formula is satisfiable!
2. SAT is NP-hard:
Every language in NP can be polytime
reduced to SAT (complex formula)
c x1 ¬x1
l
a
u x1 x2
s
e
x2 x2
x1 ¬x1 x2 ¬x2
clauses
x1 ¬x1 ¬x1
x1 x2 ¬x2 ¬x2 x2 x2
k = 2(#clauses) + (#variables)
HAMPATH = { (G,s,t) | G is an directed graph
with a Hamilton path from s to t}
Theorem: HAMPATH is NP-Complete
(1) HAMPATH ∈ NP
(2) 3SAT ≤P HAMPATH
SHORTEST PATH
= {(G, s, t, k) |
G has a simple path of length < k from s to t }
LONGEST PATH
= {(G, s, t, k) |
G has a simple path of length > k from s to t }