0% found this document useful (0 votes)
58 views26 pages

4 TuringMachines

Uploaded by

Dipesh Talukdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views26 pages

4 TuringMachines

Uploaded by

Dipesh Talukdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Turing Machines

Chapter 8

1
Turing Machines are…
• Very powerful (abstract) machines that could
simulate any modern-day computer.

For every input,


answer YES or NO
• Why design such a machine?
• If a problem cannot be “solved” even using a TM,
then it implies that the problem is undecidable

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 …

Input & output tape symbols


B: blank symbol (special symbol reserved to indicate data boundary)

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:

Transition function  for R


 for L

• One move (denoted by |---) in a TM does the


following:
• (q,X) = (p,Y,D) q
X / Y,D
p
• q is the current state
• X is the current tape symbol pointed by tape head
• State changes from q to p
• After the move:
• X is replaced with the symbol Y
• If D=“L”, the tape head moves “left” by one position.
Alternatively, if D=“R” the tape head moves “right” by one
position.

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

• (q,Xi) = (p,Y,R) is same as:


X1…Xi-1qXi…Xn |---- X1…Xi-1YpXi+1…Xn
• (q,Xi) = (p,Y,L) is same as:
X1…Xi-1qXi…Xn |---- X1…pXi-1YXi+1…Xn
7
Way to check for Membership
• Is a string w accepted by a TM?

• 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}

Y / Y,R 1. Mark next unread 0 with X and


0 / 0,R move right
2. Move to the right all the way to
0 / X,R the first unread 1, and mark it
q0 q1 with Y
3. Move back (to the left) all the
Y / Y,R 1 / Y,L way to the last marked X, and
X / X,R then move one position to the
q2 right
Y / Y,R q3 4. If the next position is 0, then
goto step 1.
B / B,R Y / Y,L Else move all the way to the right
0 / 0,L to ensure there are no excess 1s.
q4 If not move right to the next
blank symbol and stop & accept.

10
*state diagram representation preferred

TM for {0n1n | n≥1}


Next Tape Symbol

Curr. 0 1 X Y B
State
q0 (q1,X,R) - - (q3,Y,R) -

q1 (q1,0,R) (q2,Y,L) - (q1,Y,R) -

q2 (q2,0,L) - (q0,X,R) (q2,Y,L) -

q3 - - - (q3,Y,R) (q4,B,R)

*q4 - -- - - -

Table representation of the state diagram 11


TMs for calculations
• TMs can also be used for calculating values
• Like arithmetic computations
• Eg., addition, subtraction, multiplication, etc.

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

0m10n1 (input)  10mn (output)

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

• E.g., TM for 01* + 10*

Current Tape Next


Storage symbol state
Current symbol
state New
Storage
symbol
q Transition function :
storage
• ([q0,B],a) = ([q1,a], a, R)

Tape head • ([q1,a],a) = ([q1,a], a, R)

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

E.g., TM for {wcw | w {0,1}* }


but w/o modifying original input string

BEFORE AFTER
control control

Tape head Tape head

… 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

• A TM can have non-deterministic moves:


• (q,X) = { (q1,Y1,D1), (q2,Y2,D2), … }
• Simulation using a multi-tape deterministic TM:
Control

Input tape
Marker tape ID1 * ID2
* ID3 * ID4 *
Scratch tape

25
End

26

You might also like