4 TuringMachines
4 TuringMachines
Chapter 8
1
Turing Machines are…
• Very powerful (abstract) machines that could
simulate any modern-day computer.
2
The Church-Turing Thesis
Anything that can be computed by algorithm (in
our intuitive sense of the term “algorithm”)
can be computed by a Turing Machine.
3
A Turing Machine (TM)
Finite
control
Tape is the
memory
Tape head
Infinite tape with tape symbols
… B B B X1 X2 X3 … Xi … Xn B B …
4
Definition: M = (Q, ∑, , , q0,B,F)
Q: set of states
∑: input alphabet
: Tape symbols
δ: transition function (q,X) = (p,Y,D)
q0: start state
B: Blank symbol
F: Final/accepting states
5
You can also use:
6
ID of a TM
• Instantaneous Description or ID :
• X1X2…Xi-1qXiXi+1…Xn
means:
• q is the current state
• Tape head is pointing to X i
• X1X2…Xi-1XiXi+1…Xn are the current tape symbols
• Initial condition:
• The (whole) input string w is present in TM, preceded and
followed by infinite blank symbols
• Final acceptance:
• Accept w if TM enters final state and halts
• If TM halts and not final state, then reject
8
Example: L = {0n1n | n≥1}
• Strategy: w = 000111
…
B B 0 0 0 1 1 1 B B … B B X X 0 Y Y 1 B B …
… …
…
… B B X 0 0 1 1 1 B B … B B X X X Y Y 1 B B …
… …
… B B X 0 0 Y 1 1 B B … B B X X X Y Y Y B B …
…
… B B X X 0 Y 1 1 B B …
B B X X X Y Y Y B B …
Accept 9
TM for {0n1n | n≥1}
10
*state diagram representation preferred
Curr. 0 1 X Y B
State
q0 (q1,X,R) - - (q3,Y,R) -
q3 - - - (q3,Y,R) (q4,B,R)
*q4 - -- - - -
12
Example 2: monus subtraction
“m -- n” = max{m-n,0}
0m10n ...B 0m-n B.. (if m>n)
...BB…B.. (otherwise)
1. For every 0 on the left (mark X), mark off a 0 on the right (mark Y)
2. Repeat process, until one of the following happens:
1. // No more 0s remaining on the left of 1
Answer is 0, so flip all excess 0s on the right of 1 to Bs (and the 1
itself) and halt
2. //No more 0s remaining on the right of 1
Answer is m-n, so simply halt after making 1 to B
13
Example: (4-2)=2
B 0 0 0 0 1 0 0 B
B B 0 0 0 1 0 0 B
B B 0 0 0 1 1 0 B
B B B 0 0 1 1 0 B
B B B 0 0 1 1 1 B
B B B B 0 1 1 1 B
B B B B 0 B B B B
B B B 0 0 B B B B
14
15
Example 3: Multiplication
Pseudocode:
1. Move tape head back & forth such that for every 0
seen in 0m, write n 0s to the right of the last
delimiting 1
2. Once written, that zero is changed to B to get marked
as finished
3. After completing on all m 0s, make the remaining n
0s and 1s also as Bs
16
17
18
Variations of Turing
Machines
19
Generic description
TMs with storage Will work for both a=0 and a=1
B B 0 1 1 1 1 1 B B … • ([q1,a],B) = ([q2,B], B, R)
20
Standard TMs are equivalent to TMs
with storage
Every TM w/ storage can be simulated by a TM w/o
storage as follows:
• For every [state, symbol] combination in the TM
w/ storage:
• Create a new state in the TM w/o storage
• Define transitions induced by TM w/ storage
21
Multi-track Turing Machines
• TM with multiple tracks,
but just one unified tape head
control
One tape head to read
k symbols from the k tracks
at one step.
Track 1 … …
… …
Track 2
…
…
Track k … …
22
Multi-Track TMs
• TM with multiple “tracks” but just one head
BEFORE AFTER
control control
… B B 0 1 0 c 0 1 0 B … Track 1 … B B 0 1 0 c 0 1 0 B … Track 1
… B B B B B B B B B B … Track 2 … B B X X X c Y Y Y B … Track 2
23
Second track mainly used as a scratch space for marking
Multi-Tape Turing Machines
• TM with multiple tapes, each tape with a separate head
• Each head can move independently of the others
control
k separate heads
Tape 1 … …
… …
Tape 2
…
Tape k … … 24
Non-deterministic TMs
Input tape
Marker tape ID1 * ID2
* ID3 * ID4 *
Scratch tape
25
End
26