foundations of computer science lecture 26 turing machines
play

Foundations of Computer Science Lecture 26 Turing Machines The - PowerPoint PPT Presentation

Foundations of Computer Science Lecture 26 Turing Machines The Turing Machine: DFA with Random Access Memory (RAM) Transducer Turing Machines Infinite Loops Encodings of Turing Machines Last Time: CFGs and Pushdown Automata L = { w # w r | w


  1. Foundations of Computer Science Lecture 26 Turing Machines The Turing Machine: DFA with Random Access Memory (RAM) Transducer Turing Machines Infinite Loops Encodings of Turing Machines

  2. Last Time: CFGs and Pushdown Automata L = { w # w r | w ∈ { 0 , 1 } ∗ } S → # | 0 S 0 | 1 S 1 0 # 0 0 1 1 0 0 1 1 0 DFA with stack memory (push, pop, read). q 0 q 7 q 1 yes Push the first half of the string. or q 6 q 2 0 For each bit in the second half, pop the stack and compare. q 5 q 3 no q 4 DFAs with stack memory closely related to CFGs. Creator: Malik Magdon-Ismail Turing Machines: 2 / 13 Non Context Free →

  3. Non Context Free repetition { w # w } { 0 • n 1 • n 0 • n } multiple-equality { 0 • n 2 } , { 0 • n 1 • n 2 } squaring { 0 • 2 n } , { 0 • n 1 • 2 n } exponentiation w # w r 0 • n 1 • n 0 • n w # w 0 0 1 1 # 1 1 0 0 0 0 1 1 0 0 1 1 # 0 0 1 1 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 p o match; pop p match; pop 1 ; h c t a 1 1 1 m 1 1 0 0 0 0 0 0 0 0011 is pushed. 0011 is pushed. 000111 is pushed onto the stack. DFA matches 1100 by popping. DFA needs bottom-access to match. DFA needs random access to match. The file clerk who only has access to the top of his stack of papers has fundamentally less power than the file clerk who has a filing cabinet with access to all his papers. We need a new model, one with Random Access Memory (RAM). Creator: Malik Magdon-Ismail Turing Machines: 3 / 13 Today →

  4. Today: Turing Machines Solving a non context free language: w # w r . 1 Transducer Turing Machines. 2 Infinite Loops 3 Encodings of Turing Machines 4 Creator: Malik Magdon-Ismail Turing Machines: 4 / 13 Turing’s 1936 Miracle →

  5. Turing’s 1936 Miracle “On Computable Numbers with an Application to the Entscheidungsproblem” A classic which epitomizes the beauty of pure thought, where Alan Turing Invented a notion of what it means for a number to be computable. Invented the computer. Invented and used subroutines. Invented the programmable computer. Gave a negative answer to Hilbert’s Entscheidungsproblem. All this before the world even saw its first computer. Wow! (Oh, and by the way, he helped Britain win WWII against Hitler by decrypting the Enigma machine.) . . . and for all this, society drove him to suicide. Go figure! Creator: Malik Magdon-Ismail Turing Machines: 5 / 13 Turing’s Machine →

  6. Turing’s Machine L R q 0 q 5 q 1 q 4 q 3 q 2 ␣ ␣ ␣ * ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ 0 0 1 0 0 1 # States. Can move L/R (or stay put) giving random access to an infinite read-write tape. Input written on the tape to start. Instructions specify what to do based on state and what is on the tape. Beacon symbol ∗ (start of the tape). Let’s see the capabilities of this machine on the non context free problem L = { w # w } . Creator: Malik Magdon-Ismail Turing Machines: 6 / 13 Solving w # w →

  7. Solving w # w 001 # 001 * 0 0 1 # 0 0 1 ␣ ✓ 1: Check for one “ # ”, otherwise reject (a DFA can do this). * 0 0 1 # 0 0 1 ␣ 2: Return to “ ∗ ”. ✓ ✓ * 0 0 1 # 0 0 1 ␣ 3: Move right to first non-marked bit before “ # ”. Mark the location and remember the bit. ✓ ✓ 2: * 0 0 1 # 0 0 1 ␣ (If you reach “ # ” before any non-marked bit, goto step 5.) 4: Move right to first non-marked bit after “ # ”. ✓ ✓ ✓ 3: * 0 0 1 # 0 0 1 ␣ If you reach “ ␣ ” before any non-marked bit, reject . If the bit does not match the bit from step 3, reject . ✓ ✓ ✓ ✓ 4: * 0 0 1 # 0 0 1 ␣ Otherwise (bit matches), mark the location. goto step 2. 5: Move right to first non-marked bit after “ # ”. ✓ ✓ ✓ ✓ 2: * 0 0 1 # 0 0 1 ␣ If you reach “ ␣ ” before any non-marked bit, accept . If you find a bit (string on the right is too long), reject . ✓ ✓ ✓ ✓ ✓ 3: * 0 0 1 # 0 0 1 ␣ ✓ ✓ ✓ ✓ ✓ ✓ 4: * 0 0 1 # 0 0 1 ␣ ✓ ✓ ✓ ✓ ✓ ✓ 2: * 0 0 1 # 0 0 1 ␣ yes ✓ ✓ ✓ ✓ ✓ ✓ 3,5: * 0 0 1 # 0 0 1 ␣ Creator: Malik Magdon-Ismail Turing Machines: 7 / 13 Turing Machine Instructions →

  8. Turing Machine Instructions DFA instruction: q 1 0 q 3 ← if in q 1 and read 0, transition to q 3 { q 1 } { 0 } → { q 3 } { 1 } { R } {0}{1}{ R } q 1 q 3 move current state read next state write q 3 q 0 q 3 q 0 q 2 q 1 q 2 q 1 ␣ ␣ ␣ ␣ * 0 0 1 # 0 0 1 * 1 0 1 # 0 0 1 Creator: Malik Magdon-Ismail Turing Machines: 8 / 13 Building the Turing Machine →

  9. Building the Turing Machine that Solves w # w Check for one “ # ”, otherwise reject (a DFA can do this). 1 Return to “ ∗ ”. 2 Move right to first non-marked bit before “ # ”. 3 Mark and remember the bit. If you reached “ # ” before any non-marked bit, goto step 5. Move right to first non-marked bit after “ # ”. 4 If you reach “ ␣ ” or bit does not match, reject . If bit matches, mark the location. goto step 2. Move right to first non-marked bit after “ # ”. 5 If you reach “ ␣ ”, accept . If you come to a non-marked bit, reject . { ∗ ,0,1}{}{ R } {0,1}{}{ R } { # }{}{ R } q 1 step 1 {0,1}{}{ R } { ✓ }{}{ R } { # }{}{} { # }{}{ R } z 4 z 4 z 5 { ␣ }{}{} {0}{ ✓ }{} { ␣ }{}{} {0}{ ✓ }{ R } { ∗ , ✓ }{}{ R } {1, ␣ }{}{} { ∗ }{}{} step 4 step 2 step 2 step 3 step 3 step 2 E E {1}{ ✓ }{ R } { # }{}{ R } {1}{ ✓ }{} {0, ␣ }{}{} { ␣ ,0,1, # }{}{ L } {0,1}{}{} o 4 o 4 o 5 step 5 step 5 { # }{}{ R } halt and accept A { ␣ }{}{} halt and reject E {0,1}{}{ R } { ✓ }{}{ R } { ✓ }{}{ R } A Creator: Malik Magdon-Ismail Turing Machines: 9 / 13 Turing Machine for Multiplication →

  10. Turing Machine for Multiplication L mult = { 0 • i # 1 • j # 0 • k | i, j > 0 and k = i × j } ␣ * ␣ 0 0 1 1 1 0 0 0 0 0 0 # # ✓ ✓ ✓ ✓ ✓ ␣ ␣ * 0 0 # 1 1 1 # 0 0 0 0 0 0 Multiplication is repeated addition. Pair each left-0 with a block of right-0s equal to the number of 1s ✓ ✓ ✓ ✓ ✓ ␣ ␣ * 0 0 # 1 1 1 # 0 0 0 0 0 0 1: Verify the input format is 0 • i # 1 • j # 0 • k (A DFA can solve this). 2: Return to ∗ . ✓ ✓ ✓ ✓ ✓ 3: Move right to mark first unmarked left-0, then right to “ # ”. ␣ ␣ * 0 0 # 1 1 1 # 0 0 0 0 0 0 If no unmarked left-0’s (you reach “ # ”), goto step 6. 4: Move right and mark first unmarked 1. If all 1’s marked (reach “ # ”) move left, unmarking 1’s. goto step 2. ✓ ✓ ✓ ✓ ✓ ✓ ✓ ␣ ␣ * 0 0 # 1 1 1 # 0 0 0 0 0 0 5: Move right to find an unmarked right-0. If no unmarked right-0’s (come to “ ␣ ”), reject Otherwise, mark the 0, move left to first marked 1. goto step 4. ✓ ✓ ✓ ✓ ✓ ✓ ✓ ␣ ␣ 6: Move right to verify there are no unmarked right-zeros. * 0 0 # 1 1 1 # 0 0 0 0 0 0 If come to unmarked right-zero, reject ; if come to “ ␣ ” accept . ✓ ✓ ✓ ✓ ✓ ✓ ✓ ␣ ␣ * 0 0 # 1 1 1 # 0 0 0 0 0 0 ✓ ✓ ✓ ✓ ␣ ␣ * 0 0 # 1 1 1 # 0 0 0 0 0 0 Creator: Malik Magdon-Ismail Turing Machines: 10 / 13 Transducer Turing Machine →

  11. Transducer Turing Machine That Multiplies → ␣ * ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ * ␣ 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 # # # ✓ ✓ ␣ * 0 ␣ ␣ ␣ ␣ ␣ ␣ 0 0 0 # # 1 1 1 1 1 1 # # 0 Algorithm is basically the same. Instead of marking right-0s, write. ✓ ✓ ✓ ␣ ␣ ␣ ␣ ␣ ␣ * 0 0 1 1 1 0 0 # # ✓ ✓ ✓ ␣ ␣ ␣ ␣ ␣ ␣ * 0 0 1 1 1 0 0 # # ✓ ✓ ✓ ✓ ␣ ␣ ␣ ␣ ␣ * 0 0 1 1 1 0 0 0 # # ✓ ✓ ✓ ✓ ␣ ␣ ␣ ␣ ␣ * 0 0 1 1 1 0 0 0 # # ✓ ✓ ✓ ✓ ␣ ␣ ␣ ␣ ␣ * 0 0 # 1 1 1 # 0 0 0 ✓ ␣ ␣ ␣ ␣ ␣ * 0 0 1 1 1 0 0 0 # # Creator: Malik Magdon-Ismail Turing Machines: 11 / 13 Infinite Loops →

  12. Infinite Loops { ∗ ,1}{}{ R }  Halts in an accept state → accept {0}{}{ R }       q 0 q 1  M ( w ) =  Halts in a reject state → reject  {1}{}{ L }    Loops forever → ?     { #,␣ }{}{} {0, #,␣ }{}{} E A What happens if the input is 01? Turing Machine M is a recognizer for language L ( M ) : w ∈ L ( M ) ↔ M ( w ) = halt with a yes ; w �∈ L ( M ) ↔ M ( w ) = halt with a no or loop forever. Turing Machine M is a decider for language L ( M ) : w ∈ L ( M ) ↔ M ( w ) = halt with a yes ; w �∈ L ( M ) ↔ M ( w ) = halt with a no . Practical algorithms must halt! Practical algorithms correspond to deciders. Creator: Malik Magdon-Ismail Turing Machines: 12 / 13 Encoding a Turing Machine →

Recommend


More recommend