1 / 48

Element of the Theory of the Computation

Element of the Theory of the Computation. Lecture 4.3-4.5 Turing machines. Turing machines. Turing machines can be extended d oes not increase computational power d oes increase speed and ease of use/setup/definition r educes head movement, intermediate steps, memorization, shifting.

jera
Download Presentation

Element of the Theory of the Computation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Element of the Theory of the Computation Lecture 4.3-4.5 Turing machines

  2. Turing machines • Turing machines can be extended • does not increase computational power • does increase speed and ease of use/setup/definition • reduces head movement, intermediate steps, memorization, shifting

  3. Extensions of the Turing machine • Possible extensions of the Turing machine: • multiple tapes • two-way infinite tapes • two-dimensional tapes • multiple heads • random access • nondeterministic

  4. Multiple Tape Turing machine • Multiple Tapes (see Figure 1): • each tape is connected to the finite control by means of a read/write head • for any fixed integer k  1  a k-tape Turing machine is a Turing machine equipped with k tapes and corresponding heads

  5. Multiple Tape Turing machine Figure 1

  6. Definition of the k-tape Turing machine • Def.: Let k  1 be an integer • A k-tape Turing machine is a quintuple ( K, , , s, H ), where • K: is a finite set of states, not containing the halt state h; ( h ∉K) • : is an alphabet, containing the blank symbol ⊔, but not containing the symbols L and R • s: is the initial state • : is a function (deterministic) from ( K – H ) x k to K x (   {←,→})k

  7. Definition of the k-tape Turing machine (continued) • for each state q, • each k-tuple of tape symbols: • (a1,...,ak), (q, (a1,...,ak)) = (p,(b1,...,bk)), • where p: the state of the initial configuration • bj: the action taken by M at tape j • if aj = ⊳for some j ≤ k, then bj = →

  8. Configuration of a k-tape Turing machine • Def.: • M = (K, , , s, H)

  9. Example (1) for the multiple tape TM Example (1): x + y • X on first tape, y on second tape and results written to third tape • move 1 and 2 heads to right end, move head 3 to right max (|x|,|y|) • move tape 3 head right one bit for overflow

  10. Example (1) for the multiple tape TM • add 1 and 2, bit by bit and writes each intermediate result as follows • reads bits at 1 and 2 plus carry from previous bits • if sum is 0 or 1, write it to tape 3 • if sum is 2 or 3, set carry and write 0 or 1 on tape 3 • if one string ends (beginning of tape marker) use 0 for that input and do not move that head

  11. Example (2) for the k-tape Turing machine Example (2): • The use of a k-tape Turing machine: • computing a function • deciding or semideciding a language • Adoption: • the input string is placed on the first tape, such as in case of a standard Turing machine • the other tapes are initially blank, the head is on the leftmost blank square of each • at the end of a computation, as k-tape Turing machine is to leave its output on its first tape; the contents of the other tapes are ignored

  12. Example (2) for the k-tape Turing machine • Move the heads on both tapes to the right, copying each symbol on the first tape onto the second tape, until a blank is found on the first tape, but the first square of the second tape should be left blank • Move the head on the second tape to the left until a blank is found • Move the heads on both tapes to the right, this time copying symbols from the second tape onto the first tape and halt when a blank is found on the second tape

  13. Example (2) for the k-tape Turing machine At the beginning: First tape ⊳⊔ω Second tape ⊳⊔ After (1): First tape ⊳⊔ω⊔ Second tape ⊳⊔ω⊔ After (2): First tape ⊳⊔ω⊔ Second tape ⊳⊔ω After (3): First tape ⊳⊔ω⊔ω⊔ Second tape ⊳⊔ω⊔ This sequence of actions can be pictured as follows:

  14. Example (2) for the k-tape Turing machine • The depiction of Turing machines with more than one tape is the same as single-tape Turing machines • We attach as a superscript to the symbol denoting each machine the number of the tape on wich it is to operate; all other tapes are unaffected • For example, ⊔2writes a blank on the second tape • L1⊔searches to the left for a blank on the first tape, and R1,2 moves to the right the heads of both the first and the second tape • A label a1 on an arrow denotes an action if the symbol scanned in the first tape is an a • And so on…

  15. Example (2) for the k-tape Turing machine The 2-tape version of the copying machine: Figure 2

  16. Example (3) for the k-tape Turing machine Example (3): • It is known that Turing machines can add 1 to any binary integer • Turing machines can also add arbitrary binary numbers • This task can be accomplished with two tapes (see Figure 3) • Pairs of bits such as 01 on an arrow label are a shorthand for, in this case, a1 = 0, a2 = 1

  17. Example (3) for the k-tape Turing machine Figure 3

  18. Example (3) for the k-tape Turing machine • The operation of this machine: • it copies the first binary integer in its second tape, writing zeros in its place (and in the place of the ”;” separating the two integers) in the first tape  the first tape contains the second integer zeros added in front • it performs binary addition by the „school method,” starting from the least significant bit of both integers • it adds the corresponding bits writing the result in the first tape

  19. Extensions of the Turing machine Theorem: M= (K, , , s, H) is a k-tape Turing machine for some k 1 Standard Turing machine M’ = (K’, ’, ’, s’, H), where ’  for any input string x *, M on input x halts with output y on the first tape if and only if M’ on input x halts at the same halting state, and with the same output y on its tape. If M halts on input x after t steps, then M’ halts on input x after a number of steps which is O (tּ ( x +t)).

  20. Theorem: M= (K, , , s, H) is a k-tape Turing machine for some k 1. Then there is a standard Turing machine M’ where ’, and such that: • For any input string x, M on input x halts with output y on the first tape if M’ on input x halts at the same halting state and with the same output on its tape • If on input x, M halts after t steps, then M’ halts after a number of steps which is O (tּ ( x +t))

  21. Corollary from the k-tape Turing machine • Corollary: Any function that is computed or language that is decided or semidecided by a k-tape Turing machine is also computed, decided, or semidecided, respectively, by a standard Turing machine

  22. Equivalence of multiple tapes TM and ordinary TM • Theorem: • every multiple tapes Turing machine has an equivalent single-tape Turing machine • Proof ideas: • convert a multi-tape TM M to an equivalent single-tape TM S

  23. Two-way infinite Turing machine • Two-way infinite Tape: • the tape is infinite in both directions • all squares are (exception: those containing the input) • it can be simulated by a 2-tape machine: • tape 1: contains the part of the tape to the right of the square containing the first input symbol • tape 2: contains the part of the tape to the left of this in reverse

  24. Multiple heads Turing machine • Multiple Heads : • uses a single tape and multiple heads • in any state only one head can write or move • the heads all sense the scanned symbols and move or write independently • simulations in case of k-tape machines can be carried out for Turing machines with several heads, too • he tape is divided into tracks • the number of steps needed is quadriatic

  25. Multiple heads Turing machine • L = ( anbncn | n = 0, 1, 2, …) • given string w, position first head at beginning of input • position second head past all a’s to the first b • position third head past all a’s and all b’s to first c • enter loop verifying that, on each iteration, head 1 reads an a, head 2 reads a b and head 3 reads a c • if third head reaches end of input string at the same time head 1 reads the first b and head 2 reads the first c, machine erases the input string and writes a 1 into cell 1 to signify acceptance

  26. Two-dimensional tape Turing machine • Two-Dimensional Tape : • the input string is placed on the first tape, such as in case of a standard Turing machine • tape: an infinite two-dimensional grid • one head on a two dimensional grid that could expand indefinitely down and to the right • head can move in four different directions • end of tape markers on left and top sides

  27. Theorem for extensions of the Turing machine • Theorem: Any language decided or semidecided, and any function computed by Turing machines with several tapes, heads, two-way infinite tapes, or multi-dimensional tapes, can be decided, or computed, respectively, by a standard Turing machine

  28. Random access Turing machines Figure 4

  29. Random access Turing machines • A random access Turing machine has: • a fixed number of registers • a one-way infinite tape • a program counter • program contains a finite sequence of instructions (see Figure 5)

  30. Sequence of instructions Instruction Operand Sematics read j R0 := T [Rj] write j T [Rj] := R0 store j Rj := R0 load j R0 := Rj load =c R0 := c add j R0 := R0+Rj add =c R0 := R0+c sub j R0 := max {R0 – Rj, 0} sub =c R0 := max {R0 – c, 0} half R0 := [R0 / 2] jump s k := s jpos s if R0 > 0 then k := s jzero s if R0 = 0 then k := s halt k := 0 Figure 5

  31. Notes for the sequence of instructions • j stands for a register number, 0 ≤ j < k • T [i] denotes the current contents of tape square i • Rj denotes the current contents of Register j • s ≤ p denotes any instruction number in the program • c is any natural number • All instructions change k to k+1, unless explicitly stated otherwise

  32. Definition of the random access Turing machine • Def.: A random access TM is a pair M = (k, П), where: • k >0 is the number of registers • П = (π1, π2,…, πp), the program, is a finite sequence of instructions ( see Figure 5)

  33. Configuration of a random access Turing machine • A configuration of a random access Turing machine (k, П) is a k + 2-tuple C=(k, R0, R1,…, Rk-1, T), where: • k  N is the program counter, an integer between 0 and p • if k = 0, the configuration is a halted configuration • for each j, 0 ≤ j < k, Rj є N is the current value of register j • T, the tape contents, is a finite set of pairs of positive integers

  34. Example (1) for a random access TM Example (1): • program of a random access Turing machine, deciding the language {anbncn : n  0}. acount := bcount := ccount := 0, n :=1 while T[n] = 1 do : n := n +1, acount :=acount +1 while T[n] = 2 do : n := n +1, bcount :=bcount +1 while T[n] = 3 do : n := n +1, acount :=acount +1 if acount = bcount = ccount and T[n] = 0 then accept else reject

  35. Example (1) for a random access TM • We are assuming here that E(a) = 1, E(b) = 2, E(c) = 3 • We are using the variables acount, bcount, and ccount to stand for the number of a’s, b’s, and c’s • We are also using the abbreviation accept for ”load =1, halt” and reject for ”load =0, halt”

  36. Theorem for a random access Turing machines • Theorem: Any recursive or recursively enumerable language, and any recursive function, can be decided, semidecided, and computed, respectively, by a random access Turing machine.

  37. Theorem for a random access Turing machines • Theorem: Any language decided or semidecided by a random access Turing machine, and any function computable by a random access Turing machine, can be decided, semidecided, and computed, respectively, by a standard Turing machine. • If the machines halt on an input, then the number of steps taken by the standard Turing machine is bounded by a polynomial in the number of steps of the random access Turing machine on the same input.

  38. Nondeterministic Turing machines • Def.:A nondeterministic Turing machine is a quintuple M = (K, ,  , s, H) , where is a transitive relation. (( K – H ) x ) x (K x (   {←,→})) ❑abab ❑abab ❑abab ❑abab ❑bbab

  39. Nondeterministic semideciding • M = (K, ,  , s, H) a nondeterministic Turing machine • M accepts an input w (Σ - {, ❑ })* if • (s, ❑w ) yields a least one accepting configuration • M semidecides a language • L ⊆ (Σ-{, ❑ })* if • for all w (Σ - {, ❑ })* : w  L if • (s, ❑w ) yields at least one halting configuration

  40. An example of nondeterministic semideciding • L = {w {a, b, c, d}* :there are two of at least one letter } Figure 6

  41. Nondeterministic deciding and computing • M decides a language L if, for all w (Σ - {, ❑ })* : • all of M’s computations on w halt, and • w  L if at least one of M’s computations accepts • M computes a function f if, for all w (Σ - {, ❑ })* : • all of M’s computations halt, and • all of M’s computations result in f(w)

  42. An example of nondeterministic deciding • L = {w {0, 1}* : w is the binary encoding of a composite number } • M decides L by doing the following on input w: • nondeterministically choose two binary numbers 1< p, q, where |p| and |q|≤ |w|, and write them on the tape, after w, separated by ❑110011;111;1111❑❑ • multiply p and q and put the answer, A, on the tape, in place of p and q ❑110011;1011111❑❑ • compare A and w, if equal, go to y, else go to n

  43. Equivalence of nondeterministic TM and deterministic TM • Theorem: • every nondeterministic Turing machine has an equivalent deterministic Turing machine • Proof Ideas: • simulate any nondeterministic TM N with a deterministic TM D ( see Figure 7 ) • let D try all possible branches of N’s computation tree. If D finds an accept state on one of these branches, D accepts

  44. N 0 0 1 0 0 0 1 0 D x x # 0 1 x 1 2 3 3 2 3 1 2 1 1 3 Proof of Theorem Deterministic TM D simulating nondeterministic TM N input tape simulation tape address tape Figure 7

  45. Proof of theorem • D has three tapes: • tape 1 always contains the input string and is never altered • tape 2 maintains a copy of N’s tape on some branch of its nondeterministic computation • tape 3 keeps track of D’s location in N’s nondeterministic computation tree • address string 231

  46. Proof of theorem ( continued ) • 1. initially tape 1 contains the input w, and tape 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 nondeterministic computation;before each step of N, consult the next symbol on tape 3 to determine which choice to make among those allowed by N’s transition • if an accepting configuration is encountered, accept the input • if no more symbols remain on tape 3 or if this nondeterministic choice is invalid, abort this branch and go to stage 4

  47. Proof of theorem ( continued ) • if a rejecting configuration is encountered, go to state 4 • 4. replace the string on tape 3 with the lexicographically next string;simulate the next branch of N’s computation by going to stage 2

  48. Nondeterministic Turing machines • Theorem: Any language accepted by a nondeterministic Turing machine is also accepted by a deterministic Turing machine.

More Related