Universal Turing

Lecture 20

1 CS 374 read move the move Variants don’t changewhich languages by one cell by one left or right write head are recognizable/decidable look-up table look-up next-

action

sequentially accessed finite memory finite memory infinite memory (state)

3 CS 374 Simulating aRandom AccessMachine Subroutines &Recursion Church-Turing Thesis Universal TM k Today -tape TM 4 CS 374 input initiallyontape 1;tapes2,3,..., k different independently controllable heads move allheads(possibly in different directions) print (possibly different) symbolsunder heads Extension: multiple tapes multiple Extension: k different (2-way infinite)tapes read symbolsunderallheads go tonew state Single move: k -tape TM

k

, blank.

5 CS 374 1 1 ʹ 1 1 k-tape k-tape TM transition δ the on scanned Symbols ( makes programming awholeloteasier q 0 0 , k a different tapes Example: 1 0 0 With single tape,need , a 2 1 1 ,... a Utility ofmultipletapes: 0 0 k ) =( # # ={ on the to written be Symbols 0 p, b w#w 1 k 1 different tapes ,b 0 2 , ...b |

w 0 Ω ∈ ( n k 1 , D

2 {0,1}* )

steps 1 1 , D (D to in move Directions

i is one of is one L, R, S 2

} , ...D after that backwards Scan it 2 copy till#to n With 2tapes, k +1 nd ) tape. steps: )

6 CS 374 M Theorem: If Can ʹ will use Idea: ʹ t compute more with k with tapes tmore compute L isacceptedbysome1-tapeTM M 2k ʹ uses L tracks to simulate tapes+heads of isacceptedbya k

tracks tosimulatetapesof k -tape TM k places at once? k places M can How M k has heads! BUT.... M M ʹ . , then ʹ M bein M 7

of head CSTrack 374Track =( δ move: Single ( q 1 q ,1,1) Snapshot of of simulation Snapshot 2 ,0,0,R,L) 2 2

i i holds position -1 i

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

M M ʹ q head head 2 head 1 2 q 1

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

M M ʹ q head

head 2 head 1 2 q 1,1,1

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

M M ʹ q head head 2 head 1 q 2 2,0,0,R,L

$ $ $ $ 0 0 0 0 1 0 1 0 ✓ 0 1 1 1 ✓ 1 0 1 1 0 0 0 0 1 1 1 1 ( 0 0 k = 2) 11 CS 374 =( δ move: Single implementing the ( q Sweep back, 1 q ,1,1) Snapshot of simulation of simulation Snapshot 2 changes ,0,0,R,L)

M M ʹ q head head 2 head 1 2 q

2 If M $ $ $ $ takes 0 0 0 0 ✓ 1 0 1 0 T steps, 0 1 0 1 1 0 1 0 M ✓ 0 0 0 0 ʹ takes 1 1 1 1 ( 0 0 k O ( = 2) T 2 ) steps 12 CS 374 Rename start stateof Rename start for Goal: M M willhavestatespace 1

calls from state Subroutine calls Subroutine ( Q 1 ∩ M Q 1

2 to “call” ={ M 2 q

call as , q q M q call call return 2

Q &haltstate on anargument returns to = } ) Q 1 ∪ Q 2

q

return q return

13 CS 374 ...... M M 1 1

.

work space work . work space work M Subroutine calls Subroutine . 2 . runs,andwhendone: ...... # q # q return a call b 1 1 a b 2 initially input to input initially 2 M 2 . .

work space: space: work M 2

. returned value returned . a . n M b

2 k 14 CS 374 Rename start stateof Rename start Mechanism for Goal: Now M M M 1 2 may just be a wrapper (“main” function) (“main” a wrapper may just be M

willhavestatespace can call itself (without adding more states).more adding itself (without call can 1

calls from state Subroutine calls Subroutine ( Q 1 ∩ M Q 1 Recursion

2 to “call” ={ M 2 q

call as , q q : M q call

call return 2

Q &haltstate on anargument returns to = } ) Q 1 ∪ Q 2

q

return q return

15 CS 374 n characters on Will needtoencode inputin Let Encode Σ M Alphabet there existsan"equivalent"TM ={1,2,…, M ʹ

= ( = ( i with ∈ Q Q

Γ ʹ M , , Γ in binary using inbinary Γ ’s tape Γ For anyTM ʹ d , , Σ ʹ Σ }, = , ʹ Σ B , Γ B ʹ , ={0,1}, q ={0,1,2,…, ʹ , start q → start ,

q , O( accept q accept

B n Σ ʹ =0 , * log q ⌈ using , reject log q k

reject -1} ( k ) ) k bits for ⌉

) bits B

{0,1}

=0)

M ʹ 16 CS 374 O( logO( becomes A singlestep | Q q 1 ʹ | =O( | 0/3,L

q 1/2,R 2 k

) k steps. p

log

2/1,L

q Alphabet Reduction Alphabet 3/1,R 3 k

⋅ | Q q 4 |)

MOVE WRITE READ q 1 x/x,L 0/1,L 0/1,L 0/0,R q 1/0,L 2 x/x,R 0/1,R p q 3 1/1/,R x/x.L 1/0,L 0/1,L 1/1,L q 4 x/x,R 1/0,R 17 CS 374 So far:foreachproblem wedesignanewTM Early “Programming” Rewire the computer! Universal Universal TM

Ruth Lichterman Ruth Marlyn Wescoff, Betty Jennings, Jennings, Betty Programmers Betty Snyder, Betty Kay McNulty, Kay (1946-1955) Fran Bilas, Fran ENIAC ENIAC

:

18 CS 374 Update thePC writing tootheraddresses) outthatinstruction Carry from the addressinPCregister Read aninstruction The alphabet ofthecomputer isalsothesame for The computer’s finitecontrol remains thesame, Modern : ProgramModern isjustdata doing thefollowinginaloop: (as specified bytheinstruction) (as specified Universal Universal TM all programs

(possibly readingfrom/

19 CS 374 where Modern Computers: ProgramModern isjustdata Will use3 tapes and alarger alphabet Simulates z U isinterpreted asthedescriptionofaTM ( z U # w Universal Universal TM ( and wasaninputtoit Accepts asinput z ) (with # acceptsiff w Universal TM theexecutionof ) haltsiff Σ = Γ ={0,1} M M z z ( ( w w U z#w ) ) : accepts halts ) M

z on

w :

Γ U binary alphabet binary

Already saw: reduced to1 tape and can be

20 CS 374 Then e.g., if z (which implicitlyspecifies Given astring is not of this form, isnot ofthisform, z z canjustspecifythetransitionfunction indicating is of the form isoftheform with For q start which rejects all inputs Universal Universal TM d M =0 ∈ z {1,2}, wefix ,

δ q ( accept q z , whatistheTM h , # i and ) =( Σ 0 =1 = M h 1 0 z , q D Γ

k q is the “nullTM” , 1 ={0,1} i reject =L 1 0 j , D Q , j =2 aswell) d 1 0 D ) etc. 2 =R , k , 1 0 M

z

d ?

# …

21 CS 374 tapes 2 &3. and update transition, find thecorrect Scan tape1to state intape3: until ahalting 3. Inaloop, 0 totape3 w 2. Copy syntax of 1. Check totape2,

z

A 3tapeUniversalTM: 0 1 . Universal Universal TM 0 0 . 1 1 . 1 0 . _ _ . _ _ . _ _ # _ _ 1 _ _ 0 _ _ 0 _ _ _ Head where (initialized to State of Tape of head is z#w M M M z z w

z ). ’s

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

23 CS 374 A “CPU”thatcandirectly accessanylocationinan JmpZero, LoadC, Store, Load, infinite arrayofintegers,byspecifyingits address A RAM Model: Higher-Level CPU hasafinitenumberofintegerregisters, (automatically incremented aftereachstep) Instructions writtenin theinfinitememory ⟨ Reg ⟨ ⟨ RAM: RandomAccessMachine Reg Reg including a“program ” ⟨ Reg ⟩ , ⟩ ⟩ , , ⟨ ⟩ addr , ⟨ ⟨ num addr ⟨ addr ⟩ ⟩ ⟩ ⟩ Halt Add, StoreI, LoadI, ⟨ Reg ⟨ Reg ⟨ ⟩ Reg , ⟩ ⟨ , ⟩ Reg

, ⟨ addr ⟨ ⟩ addr

⟩ ⟩ 24 CS 374 steps where Program counterinitializedto1andincremented after Realistic cost JmpZero, LoadC, Store, Load, each step(unlessoverwrittenbyaninstruction) A RAM Model: Higher-Level Input follows code. Rest of memory has0s. Input followscode.Restofmemory ⟨ Reg ⟨ ⟨ RAM: RandomAccessMachine Reg Reg k ⟨ ismaxofabsolutevalues oftheintegers Reg ⟩ : Executinganinstruction costs , ⟩ ⟩ , , ⟨ ⟩ addr , ⟨ ⟨ in theinstruction num addr ⟨ addr ⟩ ⟩ ⟩ ⟩ Halt Add, StoreI, LoadI, ⟨ Reg ⟨ Reg ⟨ ⟩ Reg , ⟩ ⟨ , ⟩ Reg , ⟨ addr O(log ⟨ ⟩ addr ⟩ ⟩ k )

25 CS 374 For eachRAMstep,our TMdoesthefollowing: - Update theregister tapes(shifting as necessary) & memory - Compute changes toregisters &memory. current instructiontothe worktape. ®ister for - Scanthememory tapeandcopyinformation Use atapetoholdtheregister contents,anothertoholdthe Initialized from codebuiltintofinitecontrol, and Memory tapeisalistofpairs (addr,val)Memory forallthelocations memory (array)contents.Also aninputtape&worktape. memory addressed bytheRAMsofar, +code+inputlocations. TM simulating a RAM TM simulating All integersare encodedinbinary

inputtape.

26 CS 374 For thisthe(addr,val) representation tape ofmemory Our TMuses is important. If memory tapesimulatedthearray Ifmemory is important. contiguously, willincurexponentialblow-up. If RAMtakes accessed atanystepare TM simulating a RAM TM simulating O ( T ) T tapecellsand timestepsthenthenumbers O polynomial( ( T ) bitslong. T )

time. 27 CS 374 (Open whether thesemodelsallow Remains trueeven with A TMA simulate can any of problems which aTMcannotsolve inpolynomial-time) A “centraldogma”ofComputerScience: Church-Turing Thesis and even model of . quantum computation probabilistic computation

“ physically realizable polynomial-time computation