Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

CS 341: Chapter 3 3-2

Chapter 3
Church-Turing Thesis
CS 341: Foundations of CS II
Contents
• Turing Machines
• Turing-recognizable
Marvin K. Nakayama • Turing-decidable
Computer Science Department
• Variants of Turing Machines
New Jersey Institute of Technology
Newark, NJ 07102 • Algorithms
• Encoding input for TM

CS 341: Chapter 3 3-3 CS 341: Chapter 3 3-4


Previous Machines Turing machine (TM)

• DFA
• Infinitely long tape, divided into cells, for memory
Reads input from left to right
• Tape initially contains input string followed by all blanks 
Finite control (i.e., transition function) based on
 current state, 0 0 1   . . .
 current input symbol read.
• Tape head (↓) can move both right and left
• PDA
• Can read from and write to tape
Has stack for extra memory
• Finite control based on
Reads input from left to right
current state,
Can read/write to memory (stack) by popping/pushing
current symbol that head reads from tape.
Finite control based on
 current state, • Machine has one accept state and one reject state.
 what’s read from input, • Machine can run forever: infinite loop.
 what’s popped from stack.
CS 341: Chapter 3 3-5 CS 341: Chapter 3 3-6
Key Difference between TMs and Previous Machines Example: Machine for recognizing language
• Turing machine can both read from tape and write on it. A = { s#s | s ∈ {0, 1}∗ }

• Tape head can move both right and left. Idea: Zig-zag across tape, crossing off matching symbols.

• Tape is infinite and can be used for storage. • Consider string 01101#01101 ∈ A.
• Tape head starts over leftmost symbol
• Accept and reject states take immediate effect.
0 1 1 0 1 # 0 1 1 0 1   . . .
• Record symbol in control and overwrite it with X

X 1 1 0 1 # 0 1 1 0 1   . . .
• Scan right: reject if blank “” encountered before #

CS 341: Chapter 3 3-7 CS 341: Chapter 3 3-8


• When # encountered, move right one cell. • After several more iterations of zigzagging, we have

X 1 1 0 1 # 0 1 1 0 1   . . . X X X X X # X X X X X   . . .
• If current symbol doesn’t match previously recorded symbol, reject. • After all symbols left of # have been matched to symbols right of #,
• Overwrite current symbol with X check for any remaining symbols to the right of #.
If blank  encountered, accept.
X 1 1 0 1 # X 1 1 0 1   . . . If 0 or 1 encountered, reject.

• Scan left, past # to X


X X X X X # X X X X X   . . .
• Move one cell right
• The string that is accepted or not by our machine is the original input
• Record symbol and overwrite it with X
string 01101#01101.

X X 1 0 1 # X 1 1 0 1   . . .
• Scan right past # to (last) X and move one cell to right . . .
CS 341: Chapter 3 3-9 CS 341: Chapter 3 3-10
Description of TM M1 for { s#s | s ∈ {0, 1}∗ } Formal Definition of Turing Machine
Definition: A Turing machine (TM) is a 7-tuple
M1 = “On input string w: M = ( Q, Σ, Γ, δ, q0, qaccept, qreject ), where
1. Scan input to be sure that it contains a single #. • Q is a finite set of states
If not, reject.
• Σ is the input alphabet not containing blank symbol 
2. Zig-zag across tape to corresponding positions on
either side of the # to check whether these positions • Γ is tape alphabet with blank  ∈ Γ and Σ ⊆ Γ
contain the same symbol. If they do not, reject. • δ : Q × Γ → Q × Γ × {L, R} is the transition function, where
Cross off symbols as they are checked off to keep track L means move tape head one cell to left
of which symbols correspond.
R means move tape head one cell to right
3. When all symbols to the left of # have been crossed off
along with the corresponding symbols to the right of #, • q0 ∈ Q is the start state
check for any remaining symbols to the right of the #. • qaccept ∈ Q is the accept state
If any symbols remain, reject; otherwise, accept.” • qreject ∈ Q is the reject state, with qreject = qaccept.

CS 341: Chapter 3 3-11 CS 341: Chapter 3 3-12


Transtion Function of TM Start of TM Computation

• Transition function δ : Q × Γ → Q × Γ × {L, R} M = (Q, Σ, Γ, δ, q0, qaccept, qreject ) begins computation as follows:
• δ(q, a) = (s, b, L) means
• Given input string w = w1w2 · · · wn ∈ Σ∗ with each wi ∈ Σ,
if TM i.e., w is a string of length n for some n ≥ 0.
 in state q ∈ Q, and • TM begins in start state q0
 tape head reads tape symbol a ∈ Γ,
• Input string is on n leftmost tape cells
then TM
 moves to state s ∈ Q
w1 w2 w3 · · · wn    ...
 overwrites a with b ∈ Γ
 moves head left (i.e., L ∈ {L, R})
• Rest of tape contains blanks 
a → b, L Before a b a a   • Head starts on leftmost cell of tape
q s
• Because  ∈ Σ, first blank denotes end of input string.
read → write, move
After a b b a  
CS 341: Chapter 3 3-13 CS 341: Chapter 3 3-14
TM Computation Example: Turing machine M2 recognizing language
n
When computation on TM M = (Q, Σ, Γ, δ, q0, qaccept, qreject) starts, A = { 02 | n ≥ 0 },
which consists of strings of 0s whose length is a power of 2.
• TM M proceeds according to transition function
δ : Q × Γ → Q × Γ × {L, R} Idea: The number k of zeros is a power of 2 iff successively halving k
always results in a power of 2 (i.e., each result > 1 is never odd).
a → b, L
q s
M2 = “On input string w:
read → write, move
1. Sweep left to right across the tape, crossing off every other 0.
• If M tries to move head off left end of tape,
2. If in stage 1 the tape contained a single 0, accept.
then head remains on first cell.
3. If in stage 1 the tape contained more than a single 0
• Computation continues until qaccept or qreject is entered. and the number of 0s was odd, reject.

• Otherwise, M runs forever: infinite loop. 4. Return the head to the left end of the tape.

In this case, input string is neither accepted nor rejected. 5. Go to stage 1.”

CS 341: Chapter 3 3-15 CS 341: Chapter 3 3-16


Run TM M2 with Input 0000 n
Diagram of TM for { 02 | n ≥ 0 }
• Tape initially contains input 0000.
0 → 0, L
0 0 0 0  . . . x → x, L
q5
• Run stage 1: Sweep left to right across tape, crossing off every other 0.  → , R x → x, R
x → x, R
 x 0 x  . . . (Put  in first cell to mark beginning of tape.)  → , L
q1 q2 q3
• Run stage 4: Return head to left end of tape (marked by ). 0 → , R 0 → x, R
 → , R
 x 0 x  . . .  → , R 0 → 0, R
x → x, R 0 → x, R
• Run stage 1: Sweep left to right across tape, crossing off every other 0. q4
qreject qaccept
 x x x  . . .

• Run stages 4 and 1: Return head to left end and scan tape.  → , R x → x, R
• Run stage 2: If in stage 1 the tape contained a single 0, accept.
CS 341: Chapter 3 0 → 0, L 3-17 CS 341: Chapter 3 3-18
x → x, L
n
q5
TM for { 02 | n ≥ 0 }
Run TM on input  → , R x → x, R
x → x, R
w = 0000  → , L Turing machine M2 = (Q, Σ, Γ, δ, q1, qaccept, qreject), where
q1 q2 q3
0 → , R 0 → x, R
 → , R
• Q = {q1, q2, q3, q4, q5, qaccept, qreject }
 → , R 0 → 0, R
x → x, R 0 → x, R
• Σ = {0}
q4
qreject qaccept
• Γ = {0, x, }
• q1 is start state
 → , R x → x, R
• qaccept is accept state
Step State Tape Step State Tape
• qreject is reject state
0 q1 0 0 0 0  . . . 4 q3  x 0 x  . . . • Transition function δ : Q × Γ → Q × Γ × {L, R}
1 q2  0 0 0  . . . 5 q5  x 0 x  . . . is specified in previous diagram. For example,
δ(q4, 0) = (q3, x, R)
2 q3  x 0 0  . . . 6 q5  x 0 x  . . .
δ(q3, ) = (q5, , L)
3 q4  x 0 0  . . . .. .. ..

CS 341: Chapter 3 3-19 CS 341: Chapter 3 3-20


TM Configurations TM Configurations
Configuration 1011q201 means
• Computation changes
• current state is q2
current state
q2 1 0 1 1 0 1   · · · • LHS of tape is 1011 q2 1 0 1 1 0 1   · · ·
current head position
tape contents State Tape
• RHS of tape is 01
State Tape
• head is on RHS 0

• Configuration provides “snapshot” of TM at any point during


Definition: a configuration of a TM
computation: M = (Q, Σ, Γ, δ, q0, qaccept, qreject ) is a string uqv with u, v ∈ Γ∗
current state q ∈ Q and q ∈ Q, and specifies that currently
current tape contents ∈ Γ∗ • M is in state q
current head location
• tape contains uv
• tape head is pointing to the cell containing the first symbol in v .
CS 341: Chapter 3 3-21 CS 341: Chapter 3 3-22
TM Transitions TM Transitions
Definition: Configuration C1 yields configuration C2 if the Turing
machine can legally go from C1 to C2 in a single step. • Similarly, configuration uaqibv yields configuration uqj acv if
• Specifically, for TM M = (Σ, Γ, δ, q0, qaccept, qreject ), suppose δ(qi, b) = (qj , c, L).
u, v ∈ Γ∗
a, b, c ∈ Γ
Before u a b v   · · ·
qi, qj ∈ Q b → c, L
transition function δ : Q × Γ → Q × Γ × {L, R}. qi qj

• Then configuration uaqibv yields configuration uacqj v if After u a c v   · · ·


δ(qi, b) = (qj , c, R).

Before u a b v   · · ·
b → c, R
qi qj

After u a c v   · · ·

CS 341: Chapter 3 3-23 CS 341: Chapter 3 3-24


TM Transitions Remarks on TM Configurations

• Consider TM M = ( Q, Σ, Γ, δ, q0, qaccept, qreject ).


• Special case: qibv yields qj cv if
• Starting configuration on input w ∈ Σ∗ is
δ(qi, b) = (qj , c, L)
q0w

If head is on leftmost cell of tape and tries to move left, • An accepting configuration is
then it stays in same place.
uqacceptv
for some u, v ∈ Γ∗
Before b v   ··· • A rejecting configuration is
b → c, L
qi qj
uqreject v
After c v   ··· for some u, v ∈ Γ∗
• Accepting and rejecting configurations are halting configurations.
• Configuration wqi is the same as wqi 
CS 341: Chapter 3 3-25 CS 341: Chapter 3 3-26
0 → 0, L
x → x, L Formal Definition of TM Computation
q5
 → , R  → , L
x → x, R x → x, R
• Turing machine M = (Q, Σ, Γ, δ, q0, qaccept, qreject ).
• Input string w ∈ Σ∗.
q1 q2 q3
0 → , R 0 → x, R
 → , R • Definition: M accepts input w if there is a finite sequence of
 → , R 0 → 0, R
x → x, R 0 → x, R
configurations C1, C2, . . . , Ck for some k ≥ 1 with
qreject qaccept q4
C1 is the starting configuration q0w
x → x, R
 → , R Ci yields Ci+1 for all i = 1, . . . , k − 1
 sequence of configurations obeys transition function δ
On input 0000, get following sequence of configurations:
q10000,  q2000,  xq300,  x0q40,  x0xq3 ,  x0q5x, Ck is an accepting configuration uqaccept v for some u, v ∈ Γ∗.

 xq50x,  q5x0x, q5  x0x,  q2x0x,  xq20x,  xxq3x,


• Definition: The set of all input strings accepted by TM M is the
 xxxq3 ,  xxq5x,  xq5xx,  q5xxx, q5  xxx,  q2xxx, language recognized by M and is denoted by L(M ).
 xq2xx,  xxq2x,  xxxq2 ,  xxx  qaccept  .
Note that L(M ) ⊆ Σ∗.

CS 341: Chapter 3 3-27 CS 341: Chapter 3 3-28


Turing-recognizable Turing-decidable
Definition: Language A is Turing-recognizable if there is a TM M Definition: A decider is TM that halts on all inputs, i.e., never loops.
such that A = L(M ).
Definition: Language A = L(M ) is decided by TM M if on each
Remarks: possible input w ∈ Σ∗, the TM finishes in a halting configuration, i.e.,

• Also called a recursively enumerable or enumerable language. • M ends in qaccept for each w ∈ A
• M ends in qreject for each w ∈ A.
• On an input w ∈ L(M ), the machine M can either
halt in a rejecting state, or Definition: Lang A is Turing-decidable if ∃ TM M that decides A.
it can loop indefinitely Remarks:
• How do you distinguish between • Also called a recursive or decidable language.
a very long computation and • Differences between Turing-decidable language A and
one that will never halt? Turing-recognizable language B
A has TM that halts on every string w ∈ Σ∗.
• Turing-recognizable not practical because never know if TM will halt.
TM for B may loop on strings w ∈ B .
CS 341: Chapter 3 3-29 CS 341: Chapter 3 3-30
Describing TMs Example: Turing machine M3 to decide language

• It is assumed that you are familiar with TMs and with programming C = { ai bj ck | i × j = k and i, j, k ≥ 1 }.
computers. Idea: If i collections of j things each, then i × j things total.
• Clarity above all: TM: for each a, cross off j c’s by matching each b with a c.

high-level description of TMs is allowed M3 = “On input string w:


M = “On input string w: 1. Scan the input from left to right to make sure that it is
1. Scan input . . . ” a member of L(a∗b∗c∗), and reject if it isn’t.
2. Return the head to the left-hand end of the tape
but it should not be used as a trick to hide the important details of
the program. 3. Cross off an a and scan to the right until a b occurs.
Shuttle between the b’s and the c’s, crossing off each
• Standard tools: Expanding tape alphabet Γ with until all b’s are gone. If all c’s have been crossed off
separator “#” and some b’s remain, reject.
• • 4. Restore the crossed off b’s and repeat stage 3 if there
dotted symbols 0, a, to indicate “activity,” as we’ll see later.
• • is another a to cross off. If all a’s are crossed off,
Typical example: Γ = {0, 1, #, , 0, 1} check whether all c’s also are crossed off.
If yes, accept; otherwise, reject.”

CS 341: Chapter 3 3-31 CS 341: Chapter 3 3-32

Running TM M3 on Input a3b2c6 ∈ C • Stage 3: Cross off one a and cross off matching b’s and c’s

• Tape head starts over leftmost symbol • • • • • • • • ...


A a a b b c c c c c c  
a a a b b c c c c c c   . . . • Stage 4: Restore b’s and return head to first a not crossed off
• Stage 1: Mark leftmost symbol and scan to see if input ∈ L(a∗b∗c∗) • • • • • • ...
A a a b b c c c c c c  
...
A a a b b c c c c c c   • Stage 3: Cross off one a and cross off matching b’s and c’s
• Stage 3: Cross off one a and cross off matching b’s and c’s • • • • • • • • • • • ...
• • • • • A a a b b c c c c c c  
...
A a a b b c c c c c c   • Stage 4: If all a’s crossed off, check if all c’s crossed off.
• Stage 4: Restore b’s and return head to first a not crossed off • accept

• • • ...
A a a b b c c c c c c  
CS 341: Chapter 3 3-33 CS 341: Chapter 3 3-34
TM Tricks Variant of TM: k-tape

• Question: How to tell when a TM is at the left end of the tape?


Tape 1 0 1 1  · · ·
• One Approach: Mark it with a special symbol.

3-tape TM Tape 2 0 0  · · ·
• Alternative method:
remember current symbol
overwrite it with special symbol Tape 3 1 0 0 1  · · ·
move left
if special symbol still there, head is at start of tape • Each tape has its own head.
otherwise, restore previous symbol and move left. • Transitions determined by
current state, and
what all the heads read.
• Each head writes and moves independently of other heads.

CS 341: Chapter 3 3-35 CS 341: Chapter 3 3-36


k-tape Turing Machine Multi-Tape TM
Definition: A k-tape Turing machine • Transition function
M = ( Q, Σ, Γ, δ, q0, qaccept , qreject ) δ : Q × Γk → Q × Γk × {L, R}k
has k different tapes and k different read/write heads: • Suppose
• Q is finite set of states δ(qi, a1, a2, . . . , ak ) = (qj , b1, b2, . . . , bk , L, R, . . . , L)
• Σ is input alphabet (where  ∈ Σ)
• Interpretation: If
• Γ is tape alphabet with ({} ∪ Σ) ⊆ Γ
machine is in state qi, and
• q0 is start state ∈ Q
heads 1 through k read a1, . . . ak ,
• qaccept is accept state ∈ Q
• then
• qreject is reject state ∈ Q
machine moves to state qj
• δ is transition function heads 1 through k write b1, . . . , bk
δ : Q × Γk → Q × Γk × {L, R}k each head moves left (L) or right (R) as specified.
where Γk = Γ
 ×Γ×  · · · × Γ.
k times
CS 341: Chapter 3 3-37 CS 341: Chapter 3 3-38
Multi-Tape TM Equivalent to 1-Tape TM Basic Idea of Proof of Theorem 3.13
Simulate k-tape TM using 1-tape TM
Theorem 3.13
For every multi-tape TM M , there is a single-tape TM M such that
L(M ) = L(M ).
Tape 1 0 1 1  · · ·

Remarks:
3-tape TM Tape 2 0 0  · · ·
• In other words, for every multi-tape TM M , there is an equivalent
single-tape TM M .
Tape 3 1 0 0 1  · · ·
• Proving and understanding this kind of robustness result is essential for
appreciating the power of the TM model.
We will consider different variants of TMs, and show each has
equivalent basic TM. Equivalent • • •
1-tape TM Tape # 0 1 1 # 0 0 # 1 0 0 1 #  · · ·

CS 341: Chapter 3 3-39 CS 341: Chapter 3 3-40


Proof of Theorem 3.13 Proof of Theorem 3.13
• Let Mk = (Q, Σ, Γ, δ, q0, qaccept, qreject ) be a k-tape TM. On input w = w1 · · · wn, the 1-tape TM M1 does the following:
• First M1 prepares initial string on single tape:
• • •
# w1 w2 · · · wn #  #  #   ···
Tape 1 w1 w2 · · · wn  · · ·
• Initially, Mk has • For each step of Mk , TM M1 scans tape twice

input w = w1 · · · wn on tape 1 1. Scans its tape from


Tape 2      · · · first # (which marks left end of tape) to
other tapes contain only blanks 
each head points to first cell. (k + 1)st # (which marks right end of used part of tape)
Tape 3      · · · to read symbols under “virtual” heads
2. Rescans to write new symbols and move heads
If M1 tries to move virtual head to the right onto #, then
• Construct 1-tape TM M1 with expanded tape alphabet
•  Mk is trying to move head onto unused blank cell.
Γ = Γ ∪ Γ ∪ {#}
 So M1 has to write blank on tape and shift rest of tape right
Head positions are marked by dotted symbols. one cell.
CS 341: Chapter 3 3-41 CS 341: Chapter 3 3-42
Turing-recognizable ⇐⇒ k-tape TM Nondeterministic TM
Definition: A nondeterministic Turing machine (NTM) M can
From Theorem 3.13, we get the following: have several options at every step. It is defined by the 7-tuple
M = ( Q, Σ, Γ, δ, q0, qaccept , qreject ),
Corollary 3.15
Language L is TM-recognizable if and only if some multi-tape TM where
recognizes L.
• Q is finite set of states
• Σ is input alphabet (without blank )
• Γ is tape alphabet with {} ∪ Σ ⊆ Γ
• q0 is start state ∈ Q
• qaccept is accept state ∈ Q
• qreject is reject state ∈ Q
• δ is transition function
δ : Q × Γ → P(Q × Γ × {L, R})

CS 341: Chapter 3 3-43 CS 341: Chapter 3 3-44


Transition Function δ of NTM Computing With NTMs
• On any input w, evolution of NTM represented by a
δ : Q × Γ → P(Q × Γ × {L, R}) tree of configurations (rather than a single path).
• If ∃ (at least) one accepting leaf, then NTM accepts.
qj
c → a, L t=1
C1

c → c, R
qi qk C2 C3 C4 t=2

c → a, L C5 C6 C7 C8 C9 t=3
q
c → d, R
“reject” C10 “accept” t=4
Multiple choices when in state qi and reading c from tape:
δ(qi, c) = { (qj , a, L), (qk , c, R), (q, a, L), (q, d, R) }
CS 341: Chapter 3 3-45 CS 341: Chapter 3 3-46
NTM Equivalent to TM Proof of Equivalence of NTM and TM

Theorem 3.16 On each input w, NTM N ’s computation is a tree


Every nondeterministic TM N has an equivalent deterministic TM D . • Each branch is branch of nondeterminism.

Proof Idea: • Each node is a configuration arising from running N on w.

• Build TM D to simulate NTM N on each input w. • Root is starting configuration.

• D tries all possible branches of N ’s tree of configurations. • TM D searches through tree to see if it has an accepting configuration.

• If D finds any accepting configuration, then it accepts input w. Depth-first search (DFS) doesn’t work. Why?

• If all branches reject, then D rejects input w.


Breadth-first search (BFS) works.

• If no branch accepts and at least one loops, then D loops on w. • Tree doesn’t actually exist.

So TM D needs to build tree as it searches through it.

CS 341: Chapter 3 3-47 CS 341: Chapter 3 3-48


Proof of Equivalence of NTM and TM Address Tape Works as Follows

Simulating TM D has 3 tapes • Every node in the tree has at most b children.
b is size of largest set of possible choices for N ’s transition function.
1. Input tape
• Every node in tree has an address that is a string over the alphabet
• contains input string w
Γb = {1, 2, . . . , b}
• never altered
• To get to node with address 231
2. Simulation tape start at root
• used as N ’s tape when simulating N ’s execution on some path in take second branch
N ’s computation tree. then take third branch
then take first branch
3. Address tape
• Ignore meaningless addresses.
• keeps track of current location of BFS of N ’s computation tree.
• Visit nodes in BFS order by listing addresses in Γb∗ in string order:
ε, 1, 2, . . . , b, 11, 12, . . . , 1b, 21, 22, . . .
CS 341: Chapter 3 3-49 CS 341: Chapter 3 3-50
Proof of Equivalence of NTM and TM Simulating TM D Works as Follows
• “accept” configuration has address 231. 1. Initially, input tape contains input string w.
• Configuration C6 has address 12. • Simulation and address tapes are initially empty.

• Configuration C1 has address ε. 2. Copy input tape to simulation tape.


• Address 132 is meaningless. 3. Use simulation tape to simulate NTM N on input w
on path in tree from root to the address on address tape.
C1 t=1 • At each node, consult next symbol on address tape to determine
which branch to take.
C2 C3 C4 t=2 • Accept if accepting configuration reached.
• Skip to next step if
C5 C6 C7 C8 C9 t=3 symbols on address tape exhausted
nondeterministic choice invalid
“reject” C10 “accept” t=4 rejecting configuration reached
4. Replace string on address tape with next string in Γb∗ in string order,
and go to Stage 2.

CS 341: Chapter 3 3-51 CS 341: Chapter 3 3-52


Remarks on TM Variants TM Decidable ⇐⇒ NTM Decidable
Corollary 3.18
Language L is Turing-recognizable iff a nondeterministic TM recognizes it. Definition: A nondeterministic TM is a decider if all branches halt on
all inputs.
Proof.
• Every nondeterministic TM has an equivalent 3-tape TM Remark: Can modify proof of previous theorem (3.16) so that
if NTM N always halts on all branches, then TM D will always halt.
1. input tape
2. simulation tape
Corollary 3.19
3. address tape A language is decidable iff some nondeterministic TM decides it.
• 3-tape TM, in turn, has an equivalent 1-tape TM by Theorem 3.13.

Remarks:

• k-tape TMs and NTMs are not more powerful than standard TMs:
• The Turing machine model is extremely robust.
CS 341: Chapter 3 3-53 CS 341: Chapter 3 3-54
Enumerators Enumerators
Theorem 3.21
Remarks: Language A is Turing-recognizable iff some enumerator enumerates it.
• Recall: a language is enumerable if some TM recognizes it.
• But why enumerable? Proof. Must show
1. If E enumerates language A, then some TM M recognizes A.
Definition: An enumerator is a TM with a printer 2. If TM M recognizes A, then some enumerator E enumerates A.
• TM takes no input To show 1, given enumerator E , build TM M for A using E as black box:
• TM simply sends strings to printer
• M = “On input string w,
• may create infinite list of strings
1. Run E .
• duplicates may appear in list 2. Every time E outputs a string, compare it to w.
• enumerates a language 3. If w is output, accept.”

CS 341: Chapter 3 3-55 CS 341: Chapter 3 3-56


Second Half of Proof of Theorem 3.21 “Algorithm” is Independent of Computation Model

We now show 2: If TM M recognizes A, • All reasonable variants of TM models are equivalent to TM:
then some enumerator E enumerates A. k-tape TM
• Let s1, s2, s3, . . . be a list of all strings in Σ∗ nondeterministic TM
enumerator
• Given TM M , define E using M as black box as follows: random-access TM: head can jump to any cell in one step.
Repeat the following for i = 1, 2, 3, . . .
• Similarly, all “reasonable” programming languages are equivalent.
 Run M for i steps on each input s1, s2, . . . , si.
Can take program in LISP and convert it into C, and vice versa.
 If any computation accepts, print out corresponding string s

• The notion of an algorithm is independent of the computation model.


• Note that duplicates may appear.
CS 341: Chapter 3 3-57 CS 341: Chapter 3 3-58
Algorithms Hilbert’s 10th Problem

What is an algorithm?
• Informally David Hilbert
(1862 – 1943)
a recipe
source: wikipedia
a procedure
a computer program Muh.ammad ibn Mūsā al-Khwārizmī
(c. 780 – c. 850)
source: wikipedia
• Historically, In 1900, David Hilbert delivered a now-famous address
algorithms have long history in mathematics • Presented 23 open mathematical problems
but not precisely defined until 20th century
• Challenge for the next century
informal notions rarely questioned, but
insufficient to show a problem has no algorithm. • 10th problem concerned algorithms and polynomials

CS 341: Chapter 3 3-59 CS 341: Chapter 3 3-60


Polynomials Hilbert’s 10th Problem
• Problem: Devise an algorithm that tests whether a polynomial has an
• A term is a product of variables and a constant coefficient:
integral root.
6x3yz 2
• In Hilbert’s words:
• A polynomial is a sum of terms:
“to devise a process according to which it can be
6x3yz 2 + 3xy 2 − x3 − 10 determined by a finite number of operations . . . ”
• A root of a polynomial is an assignment of values to variables so that
the value of the polynomial is zero. • Hilbert seemed to assume that such an algorithm exists.

• The above polynomial has a root at (x, y, z) = (5, 3, 0). • However, Matijasevic̆ proved in 1970 that no such algorithm exists.

• We are interested in integral roots. • Mathematicians in 1900 couldn’t have proved this.

• Some polynomials have integral roots; some don’t. No formal notion of an algorithm existed.
Informal notions work fine for constructing algorithms.
Neither 21x2 − 81xy + 1 nor x2 − 2 has an integral root.
Formal notion needed to show no algorithm exists for a problem.
CS 341: Chapter 3 3-61 CS 341: Chapter 3 3-62
Church-Turing Thesis Hilbert’s 10th Problem
• Consider language
Alonzo Church Alan Turing
D = { p | p is a polynomial with an integral root }.
(1903 – 1995) (1912 – 1954)
source: wikipedia source: wikipedia
Since 6x3yz 2 + 3xy 2 − x3 − 10 has an integral root at
(x, y, z) = (5, 3, 0),
6x3yz 2 + 3xy 2 − x3 − 10 ∈ D.
• Formal notion of algorithm developed in 1936
Since 21x2 − 81xy + 1 has no integral root,
λ-calculus of Alonzo Church
21x2 − 81xy + 1 ∈ D.
Turing machines of Alan Turing
Definitions appear very different, but are equivalent. • Hilbert’s 10th problem asks whether this language is decidable.
i.e., Is there a TM that decides D ?
• Church-Turing Thesis
The informal notion of an algorithm corresponds exactly to a • D is not decidable, but it is Turing-recognizable.
Turing machine that halts on all inputs.

CS 341: Chapter 3 3-63 CS 341: Chapter 3 3-64


Hilbert’s 10th Problem Hilbert’s 10th Problem
• Consider simpler language of polynomials over single variable: • It turns out, though, that D1 is decidable.
D1 = { p | p is a polynomial over x with an integral root }
• Can show that the roots of p (over single variable x) lie between
cmax
• D1 is recognized by following TM M1: ±k
c1
On input p, which is a polynomial over variable x where
1. Evaluate p with x set successively to values k is number of terms in polynomial
0, 1, −1, 2, −2, 3, −3, . . . . cmax is maximum coefficient
2. If at any point the polynomial evaluates to 0, accept. c1 is coefficient of highest-order term

• Note that • Thus, only have to check integers between −k cmax cmax
c1 and k c1 .

If p has an integral root, the machine eventually accepts. • Matijasevic̆ proved such bounds don’t exist for multivariate polynomials.
If not, machine loops.
M1 recognizes D1, but does not decide D1.
CS 341: Chapter 3 3-65 CS 341: Chapter 3 3-66
Encoding Encoding an Undirected Graph

• Input to a Turing machine is a string of symbols over an alphabet. • Undirected graph G


• But we want TMs (algorithms) that work on 2
polynomials 1 4
graphs
3
grammars
Turing machines
• One possible encoding
etc.
G = (1, 2,3, 4) ( (1, 2), (1, 3),(2, 3), (3, 4) )
• Need to encode an object as a string of symbols over an alphabet. nodes edges
• Can often do this in many reasonable ways.
• In this encoding scheme, G of graph G is string of symbols over
• We sometimes distinguish between some alphabet Σ, where the string
an object X starts with list of nodes
its encoding X. followed by list of edges

CS 341: Chapter 3 3-67 CS 341: Chapter 3 3-68


Connected Graphs Decision Problems

Definition: An undirected graph is connected if every node can be • Decision problem: (computational) question with YES/NO answer.
reached from any other node by travelling along edges. Answer depends on particular value of input to question.

2 2 • Example: Graph connectedness problem:

1 4 1 4
Is an undirected graph connected?

3 3 Graph G1 Graph G2
2 2
Connected graph G1 Unconnected graph G2 1 4 1 4

3 3
Example: Let A be the language consisting of strings representing
connected undirected graphs:
Input to question is undirected graph.
A = { G | G is a connected undirected graph }. For input G1, answer is YES.
So G1 ∈ A and G2 ∈ A. For input G2, answer is NO.
CS 341: Chapter 3 3-69 CS 341: Chapter 3 3-70
Instance and Language of Decision Problem Proving a Language is Decidable
• Instance of decision problem is specific input value to question. • Recall for graph connectedness problem,
Instance is encoded as string over some alphabet Σ. Ω = { G | G is an undirected graph },
YES instance has answer YES. A = { G | G is a connected undirected graph }.
NO instance has answer NO.
• To prove A is decidable language,
• Universe Ω of a decision problem comprises all instances. need to show ∃ TM that decides A.
• Language of a decision problem comprises all its YES instances.
• For a TM M to decide A, the TM must
• Example: For graph connectedness problem,
take any instance G ∈ Ω as input
Universe consists of (encodings of) every undirected graph G:
halt and accept if G ∈ A
Ω = { G | G is an undirected graph } halt and reject if G ∈ A (i.e., never loops indefinitely)
Language A of decision problem
A = { G | G is a connected undirected graph }
is subset of universe; i.e., A ⊆ Ω

CS 341: Chapter 3 3-71 CS 341: Chapter 3 3-72


TM to Decide if Graph is Connected TM M for Deciding Language A

A = { G | G is a connected undirected graph } For TM M that decides A = { G | G is a connected undirected graph }
• Stage 0 checks that input G ∈ Ω is valid graph encoding, e.g.,
Graph G1 2 Graph G2 2

1 4 1 4 two lists
3 3  first is a list of numbers
 second is a list of pairs of numbers

M = “On input G ∈ Ω, where G is an undirected graph: first list contains no duplicates
0. Check if G is a valid graph encoding. If not, reject. every node in second list appears in first list
1. Select first node of G and mark it. • Stages 1–4 then check if G is connected.
2. Repeat until no new nodes marked:
3. For each node in G, mark it if it’s attached by an • When defining a TM, we often do not explicitly include stage 0 to
edge to a node already marked. check if the input is a valid encoding.
4. Scan all nodes of G to see whether they all are marked. Instead, the check is often only implicitly included.
If they are, accept; otherwise, reject.”
CS 341: Chapter 3 3-73 CS 341: Chapter 3 3-74
Hierarchy of Languages (so far) Summary of Chapter 3
Examples • Turing machines
All languages ??? tape head can move right and left
tape head can read and write
Turing-recognizable ???
TM, k-tape TM, NTM, enumerator, . . .
• TM computation can be expressed as sequence of configurations
• Language is Turing-recognizable if some TM recognizes it
Decidable { 0n 1 n 2 n | n ≥ 0 }
Decider (deterministic, nondet, k-tape, . . . ) But TM may loop forever on input string not in language
Context-free { 0n 1n | n ≥ 0 } • Language is Turing-decidable if a TM decides it (must always halt)
CFG, PDA
• Variants of TM (k-tape, nondeterministic, etc.) have equivalent TM
Regular (0 ∪ 1)∗
DFA, NFA, Reg Exp • Church-Turing Thesis
Finite { 110, 01 } Informal notion of algorithm is same as deciding by TM.
• Hilbert’s 10th problem undecidable.
• Encoding TM input and decision problems.

You might also like