universal turing machine
play

Universal Turing Machine Lecture 20 1 Turing Machine move the head - PowerPoint PPT Presentation

Universal Turing Machine Lecture 20 1 Turing Machine move the head left or right by one cell sequentially accessed read write infinite memory finite memory (state) next- action look-up table CS 374 Variants dont change which


  1. Universal Turing Machine Lecture 20 1

  2. Turing Machine move the head 
 left or right 
 by one cell sequentially accessed read write infinite memory finite memory (state) next- action look-up table CS 374 Variants don’t change which languages 
 are recognizable/decidable

  3. Today k -tape TM Subroutines & Recursion Universal TM Simulating a Random Access Machine Church-Turing Thesis CS 374 3

  4. Extension: multiple tapes k -tape TM k different (2-way infinite) tapes k different independently controllable heads input initially on tape 1; tapes 2, 3, ..., k , blank. Single move: read symbols under all heads print (possibly different) symbols under heads CS 374 move all heads (possibly in different directions) go to new state 4

  5. k-tape TM transition function δ ( q , a 1 , a 2 ,... a k ) = ( p, b 1 ,b 2 , ... b k , D 1 , D 2 , ... D k ) Symbols scanned on Symbols to be written Directions to move in 
 the k different tapes on the k different tapes (D i is one of L, R, S) Utility of multiple tapes: 
 makes programming a whole lot easier Example: L = { w#w R | w ∈ {0,1}* } With 2 tapes, n +1 steps: 
 With single tape, need Ω ( n 2 ) steps copy till # to 
 2 nd tape. 
 1 1 0 0 1 0 # 0 1 0 0 1 1 CS 374 Scan it 
 backwards 
 1 ʹ 1 0 0 1 0 # after that 5

  6. Can ʹ t compute more with k tapes Theorem: If L is accepted by a k -tape TM M , then L is accepted by some 1-tape TM M ʹ . Idea: M ʹ uses k tracks to simulate tapes of M BUT.... M has k heads! How can M ʹ be in k places at once? CS 374 M ʹ will use 2k tracks to simulate tapes+heads of M 6

  7. Snapshot of simulation ( k = 2) head 1 0 0 1 1 0 1 Single 
 q 1 M move: 
 head 2 δ ( q 1 ,1,1) 
 0 1 1 1 0 1 0 = ( q 2 ,0,0,R,L) head $ 0 0 1 1 0 1 $ ✓ M ʹ q 1 $ 0 1 1 1 0 1 0 $ ✓ Track 2 i -1 holds tape i . CS 374 Track 2 i holds position of head i 7

  8. Snapshot of simulation ( k = 2) head 1 0 0 1 0 0 1 Single 
 q 2 M move: 
 head 2 δ ( q 1 ,1,1) 
 0 1 0 1 0 1 0 = ( q 2 ,0,0,R,L) head $ 0 0 1 1 0 1 $ ✓ M ʹ q 1 $ 0 1 1 1 0 1 0 Make two sweeps 
 $ ✓ CS 374 over the tape (up to the rightmost head) 8

  9. Snapshot of simulation ( k = 2) head 1 0 0 1 0 0 1 Single 
 q 2 M move: 
 head 2 δ ( q 1 ,1,1) 
 0 1 0 1 0 1 0 = ( q 2 ,0,0,R,L) head $ 0 0 1 1 0 1 $ ✓ q 1,1,1 M ʹ $ 0 1 1 1 0 1 0 First pass: record 
 $ ✓ CS 374 (old state, 
 head-1 symbol, 
 head-2 symbol) 9

  10. Snapshot of simulation ( k = 2) head 1 0 0 1 0 0 1 Single 
 q 2 M move: 
 head 2 δ ( q 1 ,1,1) 
 0 1 0 1 0 1 0 = ( q 2 ,0,0,R,L) head $ 0 0 1 1 0 1 $ ✓ q 2,0,0,R,L M ʹ $ 0 1 1 1 0 1 0 Update state to 
 $ ✓ CS 374 record the changes 
 to make 10

  11. Snapshot of simulation ( k = 2) head 1 0 0 1 0 0 1 Single 
 q 2 M move: 
 head 2 δ ( q 1 ,1,1) 
 0 1 0 1 0 1 0 = ( q 2 ,0,0,R,L) head $ 0 0 1 0 0 1 $ ✓ M ʹ q 2 $ 0 1 0 1 0 1 0 Sweep back, 
 $ ✓ CS 374 implementing the changes If M takes T steps, M ʹ takes O ( T 2 ) steps 11

  12. Subroutine calls Mechanism for M 1 to “call” M 2 on an argument Goal: M 1 calls from state q call returns to q return Rename start state of M 2 as q call & halt state q return M will have state space Q = Q 1 ∪ Q 2 
 ( Q 1 ∩ Q 2 = { q call , q return } ) CS 374 12

  13. Subroutine calls . . . . . . . . # a 1 a 2 . . a n M 2 work space: 
 M 1 work space initially input to M 2 q call M 2 runs, and when done: . . . . . . . . # b 1 b 2 . . . b k CS 374 M 2 returned value M 1 work space q return

  14. Subroutine calls Mechanism for M 1 to “call” M 2 on an argument Goal: M 1 calls from state q call returns to q return Rename start state of M 2 as q call & halt state q return M will have state space Q = Q 1 ∪ Q 2 
 ( Q 1 ∩ Q 2 = { q call , q return } ) Recursion: 
 CS 374 Now M 2 can call itself (without adding more states). 
 M 1 may just be a wrapper (“main” function) 14

  15. Alphabet Reduction For any TM 
 M = ( Q , Γ , Σ , B , q start , q accept , q reject ) 
 there exists an "equivalent" TM 
 M ʹ = ( Q ʹ , Γ ʹ , Σ ʹ , B ʹ , q start , q accept , q reject ) 
 with Γ ʹ = Σ ʹ ={0,1}, B ʹ =0 Will need to encode input in Σ * using {0,1} Let Σ = {1,2,…, d }, Γ = {0,1,2,…, k -1} ( B =0) Encode i ∈ Γ in binary using ⌈ log k ⌉ bits CS 374 n characters on M ’s tape → O( n log k ) bits for M ʹ 15

  16. Alphabet Reduction p p 0/0,R 1/1/,R 0/3,L 3/1,R 1/2,R 2 / 1 READ , L q 1 q 4 q 2 q 3 0/1,L 1/0,L 0/1,L 1/1,L | Q ʹ | = O( k log k ⋅ | Q |) WRITE 0/1,L 0/1,R 1/0,L 1/0,R A single step 
 MOVE becomes 
 16 CS 374 O( log k ) steps. x/x,L x/x,R x/x.L x/x,R q 1 q 2 q 3 q 4

  17. 
 
 
 
 
 
 Universal TM So far: for each problem we design a new TM Early Computer “Programming” 
 ENIAC (1946-1955) Programmers: Kay McNulty, Betty Jennings, Betty Snyder, Marlyn Wescoff, 
 Fran Bilas, 
 Ruth Lichterman CS 374 Rewire the computer! 17

  18. Universal TM Modern Computers: Program is just data The computer’s finite control remains the same, doing the following in a loop: Read an instruction from the address in PC register 
 Carry out that instruction (possibly reading from/ writing to other addresses) 
 Update the PC (as specified by the instruction) The alphabet of the computer is also the same for CS 374 all programs 18

  19. Universal TM Modern Computers: Program is just data Universal TM U : Accepts as input z#w 
 where z is interpreted as the description of a TM 
 (with Σ = Γ = {0,1} ) 
 and w as an input to it Already saw: can be Simulates the execution of M z on w : 
 reduced to 1 U ( z # w ) halts iff M z ( w ) halts 
 tape and U ( z # w ) accepts iff M z ( w ) accepts CS 374 binary alphabet Will use 3 tapes and a larger alphabet Γ U 19

  20. Universal TM Given a string z , what is the TM M z ? For M z we fix Σ = Γ = {0,1} , 
 q start = 0 , q accept = 1 , q reject = 2 , 
 Then z can just specify the transition function 
 (which implicitly specifies Q as well) e.g., z is of the form # 0 h 1 0 i 1 0 j 1 0 k 1 0 d # … 
 indicating δ ( q h , i ) = ( q k , j , D d ) etc. 
 with d ∈ {1,2}, and D 1 =L , D 2 =R CS 374 if z is not of this form, M z is the “null TM” 
 which rejects all inputs 20

  21. Universal TM 1. Check A 3 tape Universal TM: syntax of z z#w . . . . . . # 1 0 0 _ 2. Copy 
 w to tape 2, 
 Tape of M z 
 0 to tape 3 (initialized to w ). 1 0 1 0 _ _ _ _ _ _ _ 3. In a loop, Head where M z ’s 
 until a halting head is state in tape 3: 
 Scan tape 1 to find the correct State of M z 0 0 1 1 _ _ _ _ _ _ _ transition, 
 CS 374 and update 
 tapes 2 & 3. 21

  22. Language of Universal TM Language recognized by U : L ( U ) = { z#w | U accepts z#w } 
 = { z#w | M z accepts w } Will later see: L ( U ) is undecidable! CS 374 22

  23. A Higher-Level Model: RAM RAM: Random Access Machine A “CPU” that can directly access any location in an infinite array of integers, by specifying its address CPU has a finite number of integer registers, 
 including a “program counter” 
 (automatically incremented after each step) Instructions written in the infinite memory Load, ⟨ Reg ⟩ , ⟨ addr ⟩ LoadI, ⟨ Reg ⟩ , ⟨ addr ⟩ Store, ⟨ Reg ⟩ , ⟨ addr ⟩ StoreI, ⟨ Reg ⟩ , ⟨ addr ⟩ CS 374 LoadC, ⟨ Reg ⟩ , ⟨ num ⟩ Add, ⟨ Reg ⟩ , ⟨ Reg ⟩ JmpZero, ⟨ Reg ⟩ , ⟨ addr ⟩ Halt 23

  24. A Higher-Level Model: RAM RAM: Random Access Machine Input follows code. Rest of memory has 0s. Program counter initialized to 1 and incremented after each step (unless overwritten by an instruction) Realistic cost: Executing an instruction costs O(log k ) steps where k is max of absolute values of the integers in the instruction Load, ⟨ Reg ⟩ , ⟨ addr ⟩ LoadI, ⟨ Reg ⟩ , ⟨ addr ⟩ Store, ⟨ Reg ⟩ , ⟨ addr ⟩ StoreI, ⟨ Reg ⟩ , ⟨ addr ⟩ CS 374 LoadC, ⟨ Reg ⟩ , ⟨ num ⟩ Add, ⟨ Reg ⟩ , ⟨ Reg ⟩ JmpZero, ⟨ Reg ⟩ , ⟨ addr ⟩ Halt 24

  25. TM simulating a RAM Use a tape to hold the register contents, another to hold the memory (array) contents. Also an input tape & work tape. All integers are encoded in binary Memory tape is a list of pairs (addr,val) for all the locations addressed by the RAM so far, +code+input locations. Initialized from code built into finite control, and input tape. For each RAM step, our TM does the following: 
 - Scan the memory & register tape and copy information for 
 current instruction to the work tape. 
 - Compute changes to registers & memory. 
 CS 374 - Update the register & memory tapes (shifting as necessary) 25

  26. TM simulating a RAM If RAM takes T time steps then the numbers accessed at any step are O ( T ) bits long. 
 Our TM uses O ( T ) tape cells and polynomial( T ) time. For this the (addr,val) representation of memory tape is important. If memory tape simulated the array contiguously, will incur exponential blow-up. CS 374 26

Recommend


More recommend