L15 Turing machines

54
1 Turing Machines Variants Zeph Grunschlag

Transcript of L15 Turing machines

Page 1: L15 Turing machines

1

Turing Machines VariantsZeph Grunschlag

Page 2: L15 Turing machines

2

AnnouncementMidterms not graded yetWill get them back Tuesday

Page 3: L15 Turing machines

3

AgendaTuring Machine Variants Non-deterministic TM’s Multi-Tape

Page 4: L15 Turing machines

4

Input-Output Turing Machines

Input/output (or IO or transducing) Turing Machines, differ from TM recognizers in that they have a neutral halt state qhalt instead of the accept and reject halt states. The TM is then viewed as a string-function which takes initial tape contents u to whatever the non blank portion of the tape is when reaching qhalt . If v is the tape content upon halting, the notation fM (u) = v is used.

If M crashes during the computation, or enters into an infinite loop, M is said to be undefined on u.

Page 5: L15 Turing machines

5

Input-Output Turing MachinesWhen fM crashes or goes into an

infinite loop for some contents, fM is a partial function

If M always halts properly for any possible input, its function f is total (i.e. always defined).

Page 6: L15 Turing machines

6

TM NotationsThere are three ways that Sipser uses to describe

TM algorithms.1) High level –pseudocode which explains how

algorithm works without the technical snafoos of TM notation

2) Implementation level –describe how the TM operates on its tape. No need to mention states explicitly.

3) Low-level description. One of:Set of complete “goto” style instructionsState diagramFormal description: spell out the 7-tuple

Page 7: L15 Turing machines

7

High-Level TMExample

Let's for example describe a Turing Machine M which multiplies numbers by 2 in unary:

M = "On input w = 1n For each character c in w

copy c onto the next available b blank space"

Page 8: L15 Turing machines

8

Implementation-Level TMExample

The idea is to carry out the high level description by copying each character to the end. We also need to keep track of which characters have already been copied (or were copies themselves) by distinguishing these characters. One way is to use a different character, say X.

EG: Let’s see how 11111 is transformed.

Page 9: L15 Turing machines

9

Implementation-Level TMExample

So round by round, tape transformed as follows:

11111 X1111X XX111XX XXX11XXX XXXX1XXXX XXXXXXXXXX 1111111111

Page 10: L15 Turing machines

10

Implementation-Level TMExample

Implementation level describes what algorithm actually looks like on the Turing machine in a way that can be easily turned into a state-diagram

Some useful subroutines: fast forward

move to the right while the given condition holds

rewind move to the left while the given condition holdsMay need to add extra functionality

Add $ if need to tell when end of tape is

Page 11: L15 Turing machines

11

Implementation-Level TMExample

M = "On input w = 1n 1. HALT if no input 2. Write $ in left-most position3. Sweep right and write X in first blank4. Sweep left through X-streak and 1-streak5. Go right6. If read X, go right and goto 9. Else, replace 1 by X,

move right.7. If read X [[finished original w]] goto 8 Else, goto 38. Sweep to the right until reach blank, replace by X9. Sweep left replacing everything non-blank by 110.HALT

Page 12: L15 Turing machines

12

Implementation-Level TMExample

At the low level the Turing Machine is completely described, usually using a state diagram:

0

halt

�R

21$,R$|XR1|XR

3 41L

1X,R

�1,L

�X,LXL

1L

56

8

1R

XR X

R9

X1,L$1,

L

$R

9

X1,L

Page 13: L15 Turing machines

13

Non-Deterministic TM’sA non-Deterministic Turing Machine N allows more

than one possible action per given state-tape symbol pair.

A string w is accepted by N if after being put on the tape and letting N run, N eventually enters qacc on some computation branch. 

If, on the other hand, given any branch, N eventually enters qrej or crashes or enters an infinite loop on, w is not accepted.

Symbolically as before:L(N) = { x * | accepting config. y, q0 x * y }

(No change needed as need not be function)

Page 14: L15 Turing machines

14

Non-Deterministic TM’sRecognizers vs. Deciders

N is always called a non-deterministic recognizer and is said to recognize L(N); furthermore, if in addition for all inputs and all computation branches, N always halts, then N is called a non-deterministic decider and is said to decide L(N).

Page 15: L15 Turing machines

15

Non-Deterministic TMExample

Consider the non-deterministic method:

void nonDeterministicCrossOut(char c)while()if (read blank) go leftelse if (read c)cross out, go right, return OR go right // even when reading c OR go left // even when reading c

Page 16: L15 Turing machines

16

Non-Deterministic TMExample

Using randomCross() put together a non-deterministic program:

1. while(some character not crossed out)nonDeterministicCrossOut(‘0’)nonDeterministicCrossOut(‘1’)nonDeterministicCrossOut(‘2’)

2. ACCEPT

Q: What language does this non-deterministic program recognize ?

Page 17: L15 Turing machines

17

Non-Deterministic TMExample

A: {x {0,1,2}* | x has the same no. of 0’s as 1’s as 2’s }

Q: Suppose q is the state of the TM while running inside nonDeterministicCrossOut(‘1’) and q’ is the state of the TM inside nonDeterministicCrossOut(‘2’). Suppose that current configuration is

u = 0XX1Xq12X2For which v do we have u v ?

Page 18: L15 Turing machines

18

Non-Deterministic TMExample

A: 0XX1Xq12X2 0XX1qX12X2 | 0XX1X1q2X2 | 0XX1XXq’

2X2These define 3 branches of computation

tree:

Q: Is this a non-deterministic TM decider?

0XX1XXq’ 2X2

0XX1Xq12X2

0XX1X1q2X20XX1qX12X2

Page 19: L15 Turing machines

19

Non-Deterministic TMExample

A: No. This is a TM recognizer, but not a decider. nonDeterministicCrossOut() often enters an infinite branch of computation since can see-saw from right to left to right, etc. ad infinitum without ever crossing out anything. I.e., computation tree is infinite!

Note: If you draw out state-diagrams, you will see that the NTM is more compact, than TM version so there are some advantages to non-determinism! Later, will encounter examples of “efficient” nondeterministic programs for practically important problems, with no known efficient counterpart: The P vs. NP Problem.

Page 20: L15 Turing machines

20

NTM’sKonig’s Infinity Lemma

For Problem 3.3 in Sipser the following fact is important:

If a NTM is a decider then given any input, there is a number h such that all computation branches involve at most h basic steps. I.e., computation tree has height h. Follows from:

Konig’s Infinity Lemma: An infinite tree with finite branching at each node must contain an infinitely long path from the root.

Or really, the contrapositive is used: A tree with no infinite paths, and with finite branching must itself be finite.

Page 21: L15 Turing machines

21

Konig’s Infinity LemmaProof Idea

Idea is to “smell-out” where the infinite part of the tree is and go in that direction:

Page 22: L15 Turing machines

22

Konig’s Infinity LemmaProof Idea

Idea is to “smell-out” where the infinite part of the tree is and go in that direction:

Page 23: L15 Turing machines

23

Konig’s Infinity LemmaProof Idea

Idea is to “smell-out” where the infinite part of the tree is and go in that direction:

Page 24: L15 Turing machines

24

Konig’s Infinity LemmaProof Idea

Idea is to “smell-out” where the infinite part of the tree is and go in that direction:

Page 25: L15 Turing machines

25

Konig’s Infinity LemmaProof Idea

Idea is to “smell-out” where the infinite part of the tree is and go in that direction:

Page 26: L15 Turing machines

26

Konig’s Infinity LemmaProof

Proof. Given an infinite tree with finite branching construct an infinite path inductively:

Vertex v0 : Take the root.Edge vn vn+1 : Suppose v0v1…vn-

1vn has been constructed and that the subtree from vn is infinite. Then one of vn’s finite no. of children, call it vn+1, must have an infinite subtree, so add the edge vn vn+1. �

Page 27: L15 Turing machines

27

Multi-tape TM’sOften it’s useful to have several

tapes when carrying out a computations. For example, consider a two tape I/O TM for adding numbers (we show only how it acts on a typical input)

Page 28: L15 Turing machines

28

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1

Input string

Page 29: L15 Turing machines

29

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1

Page 30: L15 Turing machines

30

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1

Page 31: L15 Turing machines

31

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1

Page 32: L15 Turing machines

32

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1

Page 33: L15 Turing machines

33

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1$

Page 34: L15 Turing machines

34

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1$ 1

Page 35: L15 Turing machines

35

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1$ 1 0

Page 36: L15 Turing machines

36

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1$ 1 0 1

Page 37: L15 Turing machines

37

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1$ 1 0 1 1

Page 38: L15 Turing machines

38

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1 1$ 1 0 1 1

Page 39: L15 Turing machines

39

Multi Tape TMAddition Example$ 1 0 1 $ 1 0 1$ 1 0 1 1

Page 40: L15 Turing machines

40

Multi Tape TMAddition Example$ 1 0 1 $ 1 0$ 1 0 1 1

Page 41: L15 Turing machines

41

Multi Tape TMAddition Example$ 1 0 1 $ 1$ 1 0 1 1

Page 42: L15 Turing machines

42

Multi Tape TMAddition Example$ 1 0 1 $$ 1 0 1 1

Page 43: L15 Turing machines

43

Multi Tape TMAddition Example$ 1 0 1$ 1 0 1 1

Page 44: L15 Turing machines

44

Multi Tape TMAddition Example$ 1 0 0$ 1 0 1 0

Page 45: L15 Turing machines

45

Multi Tape TMAddition Example$ 1 0 0$ 1 0 0 0

Page 46: L15 Turing machines

46

Multi Tape TMAddition Example$ 0 0 0$ 1 0 0 0

Page 47: L15 Turing machines

47

Multi Tape TMAddition Example0 0 0 0$ 0 0 0 0

Page 48: L15 Turing machines

48

Multi Tape TMAddition Example1 0 0 01 0 0 0 0

Page 49: L15 Turing machines

49

Multi Tape TMAddition Example1 0 0 01 0 0 0 0

Page 50: L15 Turing machines

50

Multi Tape TMAddition Example1 0 0 01 0 0 0 0

Page 51: L15 Turing machines

51

Multi Tape TMAddition Example1 0 0 01 0 0 0 0

Page 52: L15 Turing machines

52

Multi Tape TMAddition Example1 0 0 0 01 0 0 0 0

Outputstring

HALT!

Page 53: L15 Turing machines

53

Multitape TM’sFormal Notation

NOTE: Sipser’s multitape machines cannot pause on one of the tapes as above example. This isn’t a problem since pausing 1-tape machines can simulate pausing k-tape machines, and non-pausing 1-tape machines can simulate 1-tape pausing machines by adding dummy R-L moves for each pause.

Formally, the -function of a k-tape machine:kkk }RL,{:δ QQ

Page 54: L15 Turing machines

54

Multitape TM’sConventions

Input always put on the first tape If I/O machine, output also on first tape Can consider machines as “string-vector” generators. E.g., a 4 tape machine could be considered as outputting in (*)4