1 / 61

Turing Machines

Turing Machines. The Next Level of Computation. Turing Machines From Alan Turing, 1936 Turns out to be the LAST The only machine you'll ever need The Church-Turing Thesis All algorithms have a Turing Machine equivalent Some TMs are not algorithms , however. But First….

thi
Download Presentation

Turing Machines

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. Turing Machines

  2. The Next Level of Computation • Turing Machines • From Alan Turing, 1936 • Turns out to be the LAST • The only machine you'll ever need • The Church-Turing Thesis • All algorithms have a Turing Machine equivalent • Some TMs are not algorithms, however

  3. But First… • We have shown that anbncn is not context free • By the Pumping Lemma • What if we add an extra stack to a PDA?

  4. A 2PDA Trace “aabbcc”…

  5. An Observation • “an” is accepted by an FA • “anbn” is accepted by a PDA • “anbncn” is accepted by a 2PDA • What about “anbncndn”?

  6. A 2PDA for “anbncndn” Trace “aabbccdd” …

  7. Interesting Fact • 2PDA = nPDA = TM = (many things…)

  8. Perspective • An FA is a machine with no memory • A PDA is like an FA but with unlimited, restricted memory • Restricted because we access it LIFO • A Turing Machine is like an FA but with unlimited, unrestricted memory • We can move to any memory cell • By moving one cell at a time over and over • Can move back and forth • We can both read and write there

  9. Turing MachinesTake some states and add… • A one-way-infinite, read/write “tape” • Initialized with input string at left; blanks everywhere else • Machine can replace one character with another • Then it can move to the right or left • Except it can't fall off the left end (“crash”) • Can contain instances of a special “blank” symbol (not part of input alphabet) • A “program” • A set of transitions, plus… • Specifies the character replacements and tape movements

  10. Example • The following TM swaps a's and b's: • q3 is a “halt state” NOTE: B == “blank”; input is preceded by B here Trace “bab”…

  11. Tracing a TM Execution • BbabB (character about to be read)BbabBBaabBBabbBBabaBBabaBBabaBBabaBBabaBBabaB (halts pointing at 1st output character)

  12. Turing Machines • A set of states • At least one is a “halting” state • Program halts (and optionally accepts input) • If it crashes, the input is rejected • May leave output on tape • Therefore, can also compute functions • An input alphabet • An output alphabet • Usually contains input alphabet • And a “blank symbol” (not part of input) • A Program

  13. anbncn Trace “aabbcc”…

  14. BaabbccB BaabbccB BXabbccB BXabbccB BXaYbccB BXaYbccB BXaYbZcB BXaYbZcB BXaYbZcB BXaYbZcB BXaYbZcB BXXYbZcB BXXYbZcB BXXYYZcB BXXYYZcB BXXYYZZB BXXYYZZB BXXYYZZB BXXYYZZB BXXYYZZB BXXYYZZB BXXYYZZB BXXYYZZB BXXYYZZB BXXYYZZBB (halt) Tracing “aabbcc”

  15. Subroutines • A TM can be used as a subroutine • Just place an arrow from the calling machine to the start state of the subroutine machine • After tape is positioned at the string to be copied • Then every halt state of the subroutine moves back to where you want it to (must copy/paste) • See INSERT on page 451 (next slide) • See DELETE on pp. 452-453 (second slide) • Can also just chain TMs in a sequence

  16. Insert 2 1 5 6 7 (a,a,R) (a,Q,R) (b,a,R) (a,b,R) (b,b,R) (X,a,R) ( ,a,R) (b,Q,R) 3 In (a,X,R) (b,X,R) (X,b,R) (X,Q,R) ( ,b,R) 4 ( ,X,R) (X,X,R) ( , ,L) (a,a,L) ( ,b,R) (Q,b,R) (b,b,L) (X,X,L) Out

  17. (a,a,R) Delete ( a, ,R) ( b, ,L) ( a, ,L) ( c, ,R) ( b, ,R) ( c, ,L) ( , ,L) 2 (b,b,L) (b,a,L) 1 (c,c,L) (c,b,L) (a,a,L) (b,c,L) (a,b,,L) (a,c,L) 4 (c,a,L) 5 7 6 ( ,c,R) ( ,a,R) Out (b,b,R) (c,c,R) 3 In

  18. COPY Trace “ab”… (in class, right now)

  19. BabB BabB BXbB BXbB BXbBB BXbBa BXbBa BXbBa BXbBa BXYBa BXYBa BXYBaB BXYBab BXYBab BXYBab BXYBab BXYBab BXbBab BabBab BabBab (halt) Copying “ab”

  20. Mechanisms equivalent to Standard TMs • PDAs with 2 or more stacks • TMs with 2-way infinite tapes • TMs with n tapes or n heads or n-dim tapes • TMs with various “move” options • Move by a number of cells (including 0), random cell access by position • Adding non-determinism to a Standard TM • Church's Lambda Calculus (LISP) • Unrestricted Phrase Structure Grammars • Matrix Grammars • Post Systems • Markov Algorithms • Structured Programming with unlimited memory • Any abstract machine yet imagined by man!

  21. Interesting Fact About TMs • They may not halt on every possible input! • And not just because the creator of a specific TM was a doofus • As we shall see, there are languages that are recognizable (if a valid string is input, the TM halts and accepts) • But not decidable (because if an invalid string is input, it will not halt!) • This is the major mathematical/computational discovery of the 20th century! • There are propositions that cannot be decided (“proven”)

  22. “Algorithms” that may not Halt • Let g(x,y) be some computable function • Let f(x) = the smallest p where g(x, p) = 1, 0, if such a p does not exist • “Pseudo-algorithm” for f(x):m = 0;while (g(x, m) != 1) ++m;cout << m; • If there is no m for a given g and x, then we hang!

  23. A language L over the alphabet is called recursive (aka “Turing computable” or “Turing decidable”) if there is a TM T that accepts every word in L and rejects every word in L'; that is, accept(T) = L reject(T) = L' A TM that recognizes a recursive set is a model of an algorithm. It always halts.

  24. Halting • It is possible that TMs will not halt for certain inputs • Infinite loop • Due to the nature of the language or computation • This is the price we pay for such a flexible computation model as TMs • 3 possibilities when a TM processes an input string from a non-recursive language: • Accepts (goes to a halt state) • Rejects (crashes) • Hangs (infinite loop)

  25. A language L over the alphabet is called recursively enumerable (aka “Turing recognizable”) if there is a TM T that accepts every word in L and either rejects (crashes) or loops forever for every word in the language L', the complement of L: accept(T) = L reject(T) + loop(T) = L' Recursive sets are r.e, of course. Just like regular languages are vacuously context-free.

  26. Important Facts • There exist languages that are r.e. but not recursive • You'll see one shortly • There exist languages that aren't even r.e.! • (Again, you'll see one soon) • All are “contrived” • They don't arrive in “practice” • They just make mathematicians feel smart :-) • Languages generated by grammars are r.e. or “better”

  27. Closure Properties • All r.e. languages are closed under union, intersection, concatenation, and Kleene* • Everything but complement! • Recursive languages are also closed under complement • Also: If L and L' are r.e., then L is recursive • Here come the Proofs…

  28. Complements of Recursive Languages • Let M be a machine that decides a recursive language, L • Form the machine M' by inverting the acceptability of M • Goes to a reject state instead • Then M' decides L' • So L' is recursive

  29. Complements of r.e. Languages • Suppose L and L' are both r.e. • Let M recognize L, and M' recognize L' • M may hang on elements of L', but M' doesn't • Form a new machine, M* that calls M and M' in parallel (non-deterministically) • If M accepts w, so does M* • If M' accepts w, reject w • There are no other possibilities! (No hanging) • Therefore, L is recursive, by definition

  30. Pit Stop/Review • TMs can recognize strings from certain languages and/or compute functions • If there is a TM, M, that accepts a language, L, and M always halts, then L is recursive • Also called decidable • M constitutes an algorithm for L • If there is no such M for a language, L1, but there is instead a machine M1 that accepts every string in L1, but M1 may hang on strings not in L1, then L1 is recursively enumerable

  31. Pit Stop(continued) • The complement of a recursive language is recursive • Recursive languages are closed under all operations, like regular languages are • r.e. languages are closed under intersection • The complement of a r.e. language may not be r.e. • If it is, then both languages are recursive!

  32. Universal Turing Machines TMs that process partitioned input: A “code” section and a “data” section A UTM simulates the actions of the input TM (the “code”) on the input data Requires encoding TM instructions as data Using separator characters

  33. A Sample TM Encoding a = 1 b = 11 B = 111 q0 = 1 q1 = 11 qn = 1(n+1) L = 1 R = 11 Use 000 to delimit machine components Use 00 to delimit transitions A TM is just a big binary string! (So they're enumerable!) The UTM reads a character, searches for the transition that applies, updates the state and tape

  34. The Totality of TMs is Enumerable • In other words, they are countable • They can be arranged in a sequence • TM1, TM2, etc. • Why? • Because they can be encoded as strings fed unto a Universal TM • Strings can be ordered lexicographically • So there you have it!

  35. Interlude • The Halting Dog Problem

  36. The Halting Problem • Question: Is there a TM (H) that takes another TM (M) as input, along with an input string (w), and decides whether or not M halts on w? • In other words, is there such an algorithm? • This would be very useful • Could detect infinite loops in bad code! • Or could save us from wasting precious time

  37. The Halting Problem • Suppose there is such a machine, H • This is the dog, Meg, before retraining • Since all TMs are enumerable, we could apply H to all such TMs • Construct a table of the outputs of applying H to all TMs • If the machine won't halt, insert 0 or some other special value

  38. The Halting Problem • The halt detector is depicted below:

  39. The Halting Problem (cont.) • Question: What happens when we replace M and w with H and its encoding, resp.? So far so good…

  40. The Halting Problem (cont.)(“Retraining Meg”) • Now, define a machine D as follows… That is, D(x) calls H(x,x) and inverts the result. Question: What is the result of D(D)?

  41. Contradiction • D accepts D iff D doesn’t halt on D • Huh?

  42. The Halting Problem (cont.) • Conclusion: there can be no such machine, H • The Halting Problem is undecidable • Many problems are shown to be unsolvable by showing them to be logically equivalent to the Halting Problem • i.e., show that H => P • There are unsolvable problems • Just like there are unprovable propositions • Godel's Incompleteness Theorem

  43. A Non-recursive Language • Let P be the set of all pairs (M,w) such that the machine M halts on input w • This is r.e. because we can just input M and w into a UTM, U • U will either halt (accept), crash (reject), or hang (this is the very definition of r.e.) • In fact, U will halt on each element of P • By definition! • But we just showed that it is not recursive • Because the Halting Problem is undecidable

  44. A non-r.e. Language! • Consider P': • P' = {Set of all (M,w) where either M is not a TM encoding, or M does not halt on w} • If P' were r.e., then P and P' would both be recursive • Since we proved that if a language and its complement are r.e., they are both recursive! • So P‘ is not r.e.!

  45. Yet Another Look • There are more languages than there are Turing Machines • this will prove the existence of non r.e. languages • How can you prove this? • By showing that the number of languages is uncountable (not “enumerable”)

  46. Which Set is Larger? • A = {0, 1, 2, …} • B = {1, 2, 3, …}

  47. A 1-to-1 Correspondence • The function f: A => B defined asf(n) = n+1is a 1-to-1 correspondence between A and B • Therefore, their cardinality is the same • Welcome to infinity!

  48. How “Big” is a Language? • A Language is a subset of Σ* • We can write the elements of Σ* in lexicographical order • Therefore, there is a first one, a second one, etc. • So, the strings of a language are enumerable • Every language is a countable set of strings

  49. How Many Real Numbers are There? • The real numbers are uncountable • They cannot be mapped in a 1-to-1 fashion to the counting numbers • Proof: • Assume they can be • Arrange their digits in a table a[ ][ ] • The sequence a[n][n]+1 is not in the table!

  50. How Many Bit Strings are There? • This also has to be uncountable • Real numbers can be seen as bit strings • But if you need convincing, use diagonalization again: • Arrange the supposedly countable number of bits strings in a table • The bit string where you flip the diagonal bits is not in the table!

More Related