Computation Theory Introduction to Turing Machine Turing Machines

  • Slides: 29
Download presentation
Computation Theory Introduction to Turing Machine

Computation Theory Introduction to Turing Machine

Turing Machines n n Proposed by Alan Turing, 1936. England “Turing Award” infinite tape

Turing Machines n n Proposed by Alan Turing, 1936. England “Turing Award” infinite tape control a b B B B: blank symbol …

Differences between finite automata and Turing machine 1. 2. 3. 4. A Turing machine

Differences between finite automata and Turing machine 1. 2. 3. 4. A Turing machine can both write on the tape and read from it. The read-write head can move both to the left and to the right. The tape is infinite. The special states for rejecting and accepting take immediate effect.

eg. Consider a Turing machine M 1 for testing membership in the language B={w#w

eg. Consider a Turing machine M 1 for testing membership in the language B={w#w : w {0, 1}*} 0 1 1 0 0 0 # 0 1 X 1 1 0 0 0 # 0 1 : X 1 1 0 0 0 # X 1 X X 1 0 0 0 # X 1 : 1 0 0 0 B … 1 0 0 0 B … X X X # X X X B …

M 1 = On input string w: 1. Scan the input to be sure

M 1 = On input string w: 1. Scan the input to be sure that it contains a single # symbol. If not, reject. 2. Zig-zap across # on either side to check on whether these positions contain the same symbol. If not, reject. Cross off symbols as they checked. 3. If any symbols remain, reject; otherwise accept.

Formal definition of a Turing machine: n δ: Q×Γ→ Q×Γ×{L, R} transition function. δ(q,

Formal definition of a Turing machine: n δ: Q×Γ→ Q×Γ×{L, R} transition function. δ(q, a) = (r, b, L) q a r b

Def: A Turing Machine is a 7 -tuple (Q, Σ, Γ, S, q 0,

Def: A Turing Machine is a 7 -tuple (Q, Σ, Γ, S, q 0, qaccept, qreject), where Q, Σ, Γ are all finite sets and 1. Q: set of states, 2. Σ: the input alphabet NOT containing the special blank symbol B, 3. Γ: the tape alphabet, where {B} Γ and Σ Γ, 4. δ: Q×Γ→Q×Γ×{L, R} ~ transition func. 5. q 0 Q is the start state, 6. qaccept Q is the accept state, and 7. qreject Q is the reject state, where qreject ≠ qaccept

As a Turing machine computes, it may halt with ‘accept’ or ‘reject’, or it

As a Turing machine computes, it may halt with ‘accept’ or ‘reject’, or it may never halt! During computation, changes occur in n n 1. 2. 3. n the current state, the current tape contents, and the current head location. The above three items form a “configuration” of the Turing machine.

Write uqv for the configuration where q is the current state, uv is the

Write uqv for the configuration where q is the current state, uv is the current contents, the current head location is the first symbol of v. 1011 q. T 0111 q n T 1 0 1 1 1 1 B B… n Let C 1 and C 2 be two configurations. Say that C 1 yields C 2, if the Turing machine can legally go from C 1 to C 2 in a single step. uaqibv yeilds uqjacv if δ(qi, b)=(qj, c, L) a, b Γ, u, v Γ*

n n n uaqibv yields uacqjv if δ(qi, b)=(qj, c, R) qibv yields qjcv

n n n uaqibv yields uacqjv if δ(qi, b)=(qj, c, R) qibv yields qjcv if the transition is right moving. We don’t move the head out of bound! n n We don’t have configuration uaqi. B. Starting configuration: q 0 w Accepting configuration: the state is qaccept Rejecting configuration: the state is qreject

halting configurations n A Turing machine M accepts input w if a seq. of

halting configurations n A Turing machine M accepts input w if a seq. of configurations C 1, C 2, …, Ck exists where 1. C 1 is the start conf. of M on input w, 2. each Ci yields Ci+1, and Ck is an accepting configuration. 3. n The collection of strings that M accepts is the language of M, denoted L(M).

Def: A language is Turing-recognizable if some Turing machine recognizes it. (or recursively enumerable)

Def: A language is Turing-recognizable if some Turing machine recognizes it. (or recursively enumerable) r. e. Def: A language is Turing-decidable or decidable if some Turing machine decides it. (or recursive) r.

eg. Show a TM M that recognizes the language n A={02 : n 0}

eg. Show a TM M that recognizes the language n A={02 : n 0} M=“On input string w: 1. Sweep left to right across the tape, crossing off every other 0. 2. If in stage 1 the tape contained a single 0, accept. 3. If in stage 1 the tape contained more than a single 0 and the number of 0 s was odd, reject. 4. Return the head to the left-hand of the tape. 5. Goto 1. ”

n eg. (Element Distinctness problem) n M=“On input w: ” 1. Place a mark

n eg. (Element Distinctness problem) n M=“On input w: ” 1. Place a mark on top of the leftmost tape symbol. If that symbol was not a “#”, reject. 2. Scan right to the next # and place a second mark on top of it. If no # is encountered before a blank symbol, only x 1 was present, so accept.

3. By zig-zagging, compare the two strings to the right of the marked #’s.

3. By zig-zagging, compare the two strings to the right of the marked #’s. If they are equal reject. 4. Move the rightmost of the two marks to the next “#” symbol to the right. If no # symbol is encountered before a blank symbol, move the leftmost mark to next # to its right. 5. Goto step 3.

n n eg. For ={a, b}, design a Turing Machine that accepts L={anbn :

n n eg. For ={a, b}, design a Turing Machine that accepts L={anbn : n 1} Sol: Q={q 0, q 1, q 2, q 3, q 4}, ={a, b} ={a, b, x, y, B}, q 4: accept state

 (q 0, a)=(q 1, x, R) ; (q 1, a)=(q 1, a, R)

(q 0, a)=(q 1, x, R) ; (q 1, a)=(q 1, a, R) (q 1, y)=(q 1, y, R) ; (q 1, b)=(q 2, y, L) (q 2, y)=(q 2, y, L) ; (q 2, a)=(q 2, a, L) (q 2, x)=(q 0, x, R) (q 0, y)=(q 3, y, R) ; (q 3, y)=(q 3, y, R) (q 3, B)=(q 4, B, R) q 0 aabb├ xq 1 abb├ xaq 1 bb├ xq 2 ayb├ q 2 xayb ├ xq 0 ayb├ xxq 1 yb├ xxyq 1 b├ xxq 2 yy ├ xq 2 xyy├ xxq 0 yy├ xxyq 3 y├ xxyyq 3 B ├ xxyy. Bq 4

Variants of Turing machine n 1. Multi-tape Turing Machines a Turing Machine with several

Variants of Turing machine n 1. Multi-tape Turing Machines a Turing Machine with several tapes.

n n Thm: Every multi-tape Turing machine has an equivalent single tape Turing machine.

n n Thm: Every multi-tape Turing machine has an equivalent single tape Turing machine. Pf: Idea: 0 1 0 B M a a a B b a B S #0 1 0#a a a#b a#B

n n n Non-deterministic Turing Machines: Thm: Every non-deterministic TM has an equivalent deterministic

n n n Non-deterministic Turing Machines: Thm: Every non-deterministic TM has an equivalent deterministic TM. Pf: 0 0 1 D 0 1 x x#0 1 x B q 0 0 q 0 q

1. Initially tape 1 contains the input w, and tapes 2 and 3 are

1. Initially tape 1 contains the input w, and tapes 2 and 3 are empty. 2. Copy tape 1 to tape 2. 3. Use tape 2 to simulate N with input w on one branch of its non-det. computation. Before each step of N consult the next symbol on tape 3 to decide which branch to move. If no symbol remains or this choice is invalid goto step 4. If reject also goto 4. 4. Increase the count on tape 3. go to step 2.

n n Corollary: A language is Turing-recognizable if and only if some non-deterministic TM

n n Corollary: A language is Turing-recognizable if and only if some non-deterministic TM recognizes it. Corollary: A language is decidable if and only if some non-deterministic TM decides it

Enumerators n n A TM with an attached printer. The language enumerated by an

Enumerators n n A TM with an attached printer. The language enumerated by an enumerator is the collection of all the strings that it eventually prints out. Control 0 0 1 0 … Enumerator Work tape

n n Theorem: A language is Turing-recognizable if and only if some enumerator enumerates

n n Theorem: A language is Turing-recognizable if and only if some enumerator enumerates it. Pf: ① If an enumerator E that enumerates a language A, a TM M recognizes A. M=“on input w 1. 2. Run E. Every time that E outputs an string, Compare it with w. If w ever appears in the output of E, accept. ”

② If TM M recognizes a language A, we can construct an enumerator E

② If TM M recognizes a language A, we can construct an enumerator E for A. Let S 1, S 2, …… be a list of all possible strings in *. E=“Ignore the input. 1. 2. 3. Repeat the following for i = 1, 2, 3, … Run M for i steps on each input, S 1, S 2, …, Si, If any computations accept, print out the corresponding Si. ”

Definition of algorithm n n Hilbert’s problems: In 1900, mathematician David Hilbert delivered a

Definition of algorithm n n Hilbert’s problems: In 1900, mathematician David Hilbert delivered a famous address at the “International congress of Mathematicians in Paris. ” He proposed 23 mathematical problems. Hilbert’s tenth problem: Design an algorithm that tests whether a multivariable polynomial has an integral root.

The Church-Turing Thesis n Intuitive notion = Turing machine algorithms of algorithms Necessary to

The Church-Turing Thesis n Intuitive notion = Turing machine algorithms of algorithms Necessary to resolve Hilbert’s tenth problem n In 1970, Yuri Matijasevič, building on work of Martin Davis, Hilary Putnam, and Julia Robinson, Showed that no algorithm exists for testing whether a poly. Has integral roots.

n D = { P| P is a polynomial with an integral root} n

n D = { P| P is a polynomial with an integral root} n Hilbert’s tenth problem: n Is D decidable? n A special case: D 1={P| P is a polynomial over x with an integral root} n D 1 is decidable! n

n n M 1 = “ The input is a polynomial P over x

n n M 1 = “ The input is a polynomial P over x Evaluate P with x to the values 0, 1, -1, 2, -2, 3, -3, …. If at any point the polynomial evaluates to 0, accepts! ” Problem 3. 18: All the roots of P is between Thus, Di is decidable!