0% found this document useful (0 votes)
5 views

Lect8

Lecture notes

Uploaded by

THANUSHREE M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lect8

Lecture notes

Uploaded by

THANUSHREE M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Turing Machines Review

✦ An example of a decidable language that is not a CFL


¼ Implementation-level description of a TM
¼ State diagram of TM

✦ Varieties of TMs
¼ Multi-Tape TMs
¼ Nondeterministic TMs
¼ String Enumerators

R. Rao, CSE 322 1

Turing Machines

Blank part of tape

Just like a DFA except:


¼ You have an infinite “tape” memory (or scratchpad) on which you
receive your input and on which you can do your calculations
¼ You can read one symbol at a time from a cell on the tape, write one
symbol, then move the read/write pointer (head) left (L) or right (R)
R. Rao, CSE 322 2
Who’s Turing?
✦ Alan Turing (1912-1954): one of the
most brilliant mathematicians of the
20th century (one of the “founding
fathers” of computing)
✦ Click on “Theory Hall of Fame” link
on class web under “Lectures”
✦ Introduced the Turing machine as a
formal model of what it means to
compute and solve a problem (i.e. an
“algorithm”)
¼ Paper: On computable numbers,
with an application to the
Entscheidungsproblem, Proc.
London Math. Soc. 42 (1936).
R. Rao, CSE 322 3

How do Turing Machines compute?


✦ δ(current state, symbol under the head) = (next state, symbol
to write over current symbol, direction of head movement)

✦ Diagram shows: δ(q1,1) = (qrej, 0, L) (R = right, L = left)


✦ In terms of “Configurations”: 110q110 ⇒ 11qrej000
R. Rao, CSE 322 4
Solving Problems with Turing Machines
✦ We know L = {0n1n0n | n ≥ 0} is not a CFL (pumping lemma)
✦ Show L is decidable
¼ Construct a decider M such that L(M) = L
¼ A decider is a TM that always halts (in qacc or qrej) and is
guaranteed not to go into an infinite loop for any input

R. Rao, CSE 322 5

Idea for a Decider for {0n1n0n | n ≥ 0}


✦ General Idea: Match each 0 with a 1 and a 0 following the 1.
✦ Implementation Level Description of a Decider for L:
On input w:
1. If first symbol = blank, ACCEPT
2. If first symbol = 1, REJECT
3. If first symbol = 0, Write a blank to mark left end of tape
a. If current symbol is 0 or X, skip until it is 1. REJECT if blank.
b. Write X over 1. Skip 1’s/X’s until you see 0. REJECT if blank.
c. Write X over 0. Move back to left end of tape.
4. At left end: Skip X’s until:
a. You see 0: Write X over 0 and GOTO 3a
b. You see 1: REJECT
c. You see a blank space: ACCEPT
R. Rao, CSE 322 6
State Diagram
X→R X→R X→L
0→R 1→R 0→L
1→L
q0 0→_,R qskip0 1→X,R qskip1 0→X,L qgo-left

1→R _→R 0→X,R _→R


qat-left X→R
qREJ qACC _→R
✦ Try running the decider on:
¼ 010, 001100, … Æ ACCEPT
¼ 0, 000, 0100, … Æ REJECT
¼ What about 010010?
R. Rao, CSE 322 7

Houston, we have a
problem with our
Turing machine…

R. Rao, CSE 322 8


What’s the problem?
X→R X→R X→L
0→R 1→R 0→L
1→L
q0 0→_,R qskip0 1→X,R qskip1 0→X,L qgo-left

1→R _→R 0→X,R _→R


qat-left X→R
qREJ qACC _→R
Maybe
✦ The decider accepts incorrect strings: it’s the
¼ 010010, 010001100 Æ ACCEPT!!! GOTO?
¼ Accepts (0n1n0n)*
E. W. Dijkstra
R. Rao, CSE 322 Need to fix it… 9

An Aside: Dijsktra on GOTOs

“For a number of years I have been familiar


with the observation that the quality of
programmers is a decreasing function of the
density of go to statements in the programs
they produce.”

Opening sentence of: “Go To Statement Considered Harmful” by


Edsger W. Dijkstra, Letter to the Editor, Communications of the
ACM, Vol. 11, No. 3, March 1968, pp. 147-148.

R. Rao, CSE 322 10


A Simple Fix (to the Decider)
✦ Scan initially to make sure string is of the form 0*1*0*
✦ On input w:
1. If first symbol = blank, ACCEPT Add this
2. If first symbol = 1, REJECT
3. If first symbol = 0: if w is not in 00*11*00*, REJECT; else,
Write a blank to mark left end of tape
a. If current symbol is 0 or X, skip until it is 1. REJECT if blank.
b. Write X over 1. Skip 1’s/X’s until you see 0. REJECT if blank.
c. Write X over 0. Move back to left end of tape.
4. At left end: Skip X’s until:
a. You see 0: Write X over 0 and GOTO 3a
b. You see 1: REJECT
GOTO
c. You see a blank space: ACCEPT
okay
here…
R. Rao, CSE 322 11

The Decider TM for L in all its glory


0→R 1→R 0→R
New part tests
q0 0→_,R q1 1→R q2 0→R q3 for 00*11*00*
1→R
0→L _→L qREJ
1→R 1→L qREW
X→R
X→R X→L
qREJ 0→R _→R
1→R 0→L
1→L
qskip0 1→X,R qskip1 0→X,L qgo-left

_→R 0→X,R _→R


qat-left X→R
qACC _→R
R. Rao, CSE 322 12
Varieties of TMs

What if we What if we
allow multiple allow
tapes? nondeterminism
?

What if I
take nap?

R. Rao, CSE 322 13

Various Types of TMs


✦ Multi-Tape TMs: TM with k tapes and k heads
¼ δ: Q × Γk → Q × Γk × {L,R}k
¼ δ(qi, a1, …, ak) = (qj, b1, …, bk, L, R, …, L)
✦ Nondeterministic TMs (NTMs)
¼ δ: Q × Γ → Pow(Q × Γ × {L,R})
¼ δ(qi, a) = {(q1, b, R), (q2, c, L), …, (qm, d, R)}
✦ Enumerator TM for L: Prints all strings in L (in any order,
possibly with repetitions) and only the strings in L
✦ Other types: TM with Two-way infinite tape, TM with
multiple heads on a single tape, 2D infinite tape TM,
Random Access Memory (RAM) TM, etc.
R. Rao, CSE 322 14
Surprise!
All TMs are born equal…
✦ Each of the preceding TMs is equivalent to the standard TM
¼ They recognize the same set of languages (the Turing-
recognizable languages)
✦ Proof idea: Simulate the “deviant” TM using a standard TM
✦ Example 1: Multi-tape TM on a standard TM
¼ Represent k tapes sequentially on 1 tape using separators #
¼ Use new symbol a to denote a head currently on symbol a
01 ...........
bah.......... ≡ #01#bah#322#.......
322.......... (See text for details)
R. Rao, CSE 322 15

Example 2: Simulating Nondeterminism


✦ Any nondeterministic TM N can be q0
simulated by a deterministic TM M a a
¼ NTMs: δ: Q × Γ → Pow(Q × Γ × {L,R}) (q , b, R) (q2, c, L)
¼ No ε transitions but can simulate them b 1
by reading and writing same symbol a
¼ N accepts w iff there is at least 1 path in
N’s tree for w ending in qACC
qREJ
✦ General proof idea: Simulate each qACC
branch sequentially
¼ Proof idea 1: Use depth first search?
No, might go deep into an infinite branch
and never explore other branches!
¼ Proof idea 2: Use breadth first search
Explore all branches at depth n before n+1
This branch does
not halt
R. Rao, CSE 322 16
Simulating Nondeterminism: Details, Details
✦ Use a 3-tape DTM M for breadth- q0
a a
first traversal of N’s tree on w:
¼ Tape 1 keeps the input string w (q1, b, R) (q2, c, L)
¼ Tape 2 stores N’s tape during
simulation along 1 path (given by
tape 3) up to a particular depth, 213
starting with w qREJ
¼ Tape 3 stores current path number qACC
E.g. ε = root node q0
213 = path made up of 3rd child of
1st child of 2nd child of root
✦ See text for more details Does
not halt
R. Rao, CSE 322 17

Next Class: We’ll ‘rap up Chapta 3 and


cova’ undecidability…

Can’t wait for


undecidability!

That
guy
needs
help…
Have a
great
weekend!
R. Rao, CSE 322 18

You might also like