theory of computation (fall 2014): step-counter theorem & program simulation
TRANSCRIPT
![Page 1: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/1.jpg)
Theory of Computation
Step Counter Theorem & Program Simulation
Vladimir Kulyukin
www.vkedco.blogspot.com
![Page 2: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/2.jpg)
Outline
● Review of Universality Theorem● Program Simulation● Step-Counter Theorem as Theoretical Basis of Program
Simulation
![Page 3: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/3.jpg)
Review of Universality Theorem
![Page 4: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/4.jpg)
Review: Universal Program
C
UlZlK
Ul
SP
Ul
Ul
pP
ZrU
KZLtK
K
pS
XZ
iZLti
Ur
K
Xn
ii
n
i
GOTO
2min
M GOTO 2)( IF
N GOTO | IF
A GOTO 1)( IF
N GOTO 0)( IF
E GOTO 01 IF C
1
1
)(
1)(
12
1
1
GOTO
1
GOTO
/
SYE
C
KKN
PSSA
N
PSSM
Part 01 Part 02
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
![Page 5: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/5.jpg)
Review: Theorem 3.1, Ch. 04
.computablepartially is ,,...,function the
,0each For :Theorem)ity (Universal 3.1 Theorem
1)( yxxΦ
n
nn
![Page 6: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/6.jpg)
Back to The Big Picture
GÖDEL Coder
GÖDEL Decoder
L Program Number Universal Program
Number
???
GÖDEL Coder = CompilerGÖDEL Decoder = Reverse CompilerUniversal Program = Operating System/VM/Interpreter
Universality Theorem
![Page 7: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/7.jpg)
Enumeration of Partially Computable Functions
. variables of functions computablepartially all enumerates
,...3,,...,,2,,...,,1,,...,,0,,...,
sequence the,0each For
1)(
1)(
1)(
1)(
n
xxΦxxΦxxΦxxΦ
n
nn
nn
nn
nn
![Page 8: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/8.jpg)
Remark on Notation
yxΦxΦxΦ
yxxΦxxΦ
yy
nn
nn
y
,,
:omittedoften is 1t Superscrip
,,...,,...,
)1(
1)(
1)(
![Page 9: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/9.jpg)
Program Simulation
![Page 10: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/10.jpg)
On To Program Simulation
● Suppose a universal program runs a program on some inputs● We can expect two mutually exclusive outcomes:
The program terminates (halts) after some finite number of steps and produces an output (a number);
The program does not terminate at all (e.g., it has an infinite loop)● In many situations, we would like to know if a program terminates
within a given number of steps without having to run the program● Enter Program Simulation
![Page 11: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/11.jpg)
The New Big Picture
GÖDEL Coder
GÖDEL Decoder
L Program Number Universal Program
Number
???
GÖDEL Coder = CompilerGÖDEL Decoder = Reverse CompilerUniversal Program = Operating System/VM/Interpreter
Universality Theorem
Simulator
Step-Counter Theorem
![Page 12: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/12.jpg)
Execution vs. Simulation
● Once a universal program (e.g., an operating system/interpreter) starts executing the program, it cannot stop
● If a program has an infinite loop, because there is a bug or because it is working on a problem with no solution, there is no way of stopping the program
● Simulation enables us to run a program for a specific number of steps: many IDEs have code steppers that allow the programmer to step through the program one instruction at a time
![Page 13: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/13.jpg)
Where Else Can Program Simulation Be Used?
● Many AI problems can be formally represented in terms of states, operators, goal tests, and path costs
● A state is a formal representation of the world in which a problem solver operates
● An operator is an action that the problem solver can carry out in the world.
● A goal test is a predicate that returns true when the problem solver’s goal is satisfied in a given state of the world and false otherwise
● A path cost is the cost of applying a sequence of operators that transforms the start state to a goal state
![Page 14: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/14.jpg)
Simulation Through Successive Snapshots
● Program snapshots can be used to simulate computations
● Suppose we have an L program P and a given snapshot
● We have defined the successor snapshot function● Basic idea: Use the successor function to compute a
sequence of snapshots that starts at a given snapshot and check if the last snapshot in that sequence is terminal
![Page 15: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/15.jpg)
Review: Snapshots
.0or 1 if terminalis
program. theof state a is
executed; be n toinstructio theofnumber theis
program; somein nsinstructio ofnumber theis
where,11 ),,( as defined is Snapshot
inis
i
Ln
niis
![Page 16: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/16.jpg)
Step-Counter Theorem as Theoretical Basis of Program Simulation
![Page 17: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/17.jpg)
STP Predicate: Two Definitions
otherwise. 0
;.,...,
inputs with beginning ,1length of
program ofn computatio a is thereif 1
,,,...,
otherwise. 0
steps;fewer or in
,..., inputson halts program if 1
,,,...,
11
)(
1
1)(
nn
n
n
nn
xx
t
y
tyxxSTP
t
xxy
tyxxSTP
![Page 18: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/18.jpg)
Theorem 3.2 (Ch. 4): STP Theorem
recursive. primitive is
,,,..., predicate the,0For 1)( tyxxSTPn n
n
![Page 19: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/19.jpg)
Proof Outline● Step 1: Encoding a program state● Step 2: Encoding the initial snapshot● Step 3: Extracting an instruction components● Step 4: Defining conditions of instruction simulation:
4a) When to simulate skipping instruction; 4b) When to simulate an increment; 4c) When to simulate a decrement; 4d) When to simulate a branch
● Step 5: Simulating the successor snapshot● Step 6: Figuring out when to terminate● Step 7: Simulating the n-th snapshot● Step 8: Putting it all together
![Page 20: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/20.jpg)
Step 1: Encoding a Program State
.,...,0,,0
where,, as encoded is ,
21 xxs
sii
![Page 21: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/21.jpg)
Step 2: Initial Snapshot
n
i
Xin
n ipxx1
21)( ,1,...,INIT
![Page 22: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/22.jpg)
Step 3: Extracting Instruction Components
label. GOTO theis This // 21,GTLBL 4.
n type.instructio is This// 1,INSTR 3.
variable.sn'instructio is This //11,VAR 2.
label. sn'instructio is This // 1,LABEL 1.
:have Then we .,,1 So, code.
source its ofnumber theis 1 Thus, number. program a be Let
i
i
i
i
i
yrlyi
yrlyi
yrryi
ylyi
cbay
yy
![Page 23: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/23.jpg)
Proof So Far• Step 1: Encoding a program state• Step 2: Encoding the initial snapshot• Step 3: Extracting an instruction components• Step 4: Defining conditions of instruction simulation:
– 4a) When to simulate skipping instruction;– 4b) When to simulate an increment;– 4c) When to simulate a decrement;– 4d) When to simulate a branch
• Step 5: Simulating the successor snapshot• Step 6: Figuring out when to terminate• Step 7: Simulating the n-th snapshot• Step 8: Putting it all together
![Page 24: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/24.jpg)
Step 4a: When to Skip
• Let y be a program number. Then y+1 is the source code number. Let x = <i,s> be the current snapshot
• Question: When should we skip instruction i?• Answer hint: There are 3 conditions
![Page 25: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/25.jpg)
Step 4a: When to Skip
Answer:1. When instruction i is of type V ← V and i is less than
or equal to the length of the program2. When instruction i is of type V ← V – 1 and V = 03. When instruction i is of type IF V != 0 GOTO L & V = 0
![Page 26: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/26.jpg)
Step 4a: Condition 1
1 & 0,INSTR :1Condition Formalized
program theoflength the
and type theof is n Instructio :1Condition
number. program a is snapshot, a be ,Let
yLtxlyxl
i
VVi
ysix
![Page 27: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/27.jpg)
Step 4a: Condition 2
s
V
xrpyxl
V VVi
ysix
yxlVAR
state thedivide
not does prime ingcorrespond theifonly and if 0 :Recall
| & 2,INSTR :2Condition Formalized
0 and 1 type theof is n Instructio :2Condition
number. program a is snapshot, a be ,Let
,
![Page 28: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/28.jpg)
Step 4a: Condition 3
xrpyxl
V
LVi
ysix
yxlVAR | & 2,INSTR :3Condition Formalized
0 and
GOTO 0! IF type theof isn Instructio :3Condition
number. program a is snapshot, a be ,Let
,
![Page 29: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/29.jpg)
Step 4a: Conditions 2 & 3
xrpyxl
xrpyxl
V
LVi
xrpyxl
V V - V i
ysix
yxlVAR
yxlVAR
yxlVAR
| & 2,INSTR :Combined 3&2 Conditions
| & 2,INSTR
.0 and
GOTO 0! IF type theof isn Instructio :3Condition
| & 2,INSTR
.0 and 1 type theof is n Instructio :2Condition
number. program a is snapshot, a be ,Let
,
,
,
![Page 30: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/30.jpg)
Step 4a: Summary
as" defined" means
| & 2,INSTR
1 & 0,INSTR
,SKIP
n?instructionext theskip weshouldWhen
number. program a is snapshot, a be ,Let
,
xrpyxl
yLtxlyxl
yx
ysix
yxlVAR
![Page 31: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/31.jpg)
Proof So Far• Step 1: Encoding a program state• Step 2: Encoding the initial snapshot• Step 3: Extracting an instruction components• Step 4: Defining conditions of instruction simulation:
– 4a) When to simulate skipping instruction;– 4b) When to simulate an increment;– 4c) When to simulate a decrement;– 4d) When to simulate a branch.
● Step 5: Simulating the successor snapshot● Step 6: Figuring out when to terminate● Step 7: Simulating the n-th snapshot● Step 8: Putting it all together
![Page 32: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/32.jpg)
Step 4b: When to Simulate an Increment
predicate. a is ,INCR that Note
.1,INSTR,INCR
.1
typeof is n instructiowhen increment an simulate We
state. program a is snapshot, a be ,Let
yx
yxlyx
V V
i
ysix
![Page 33: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/33.jpg)
Step 4c: When to Simulate a Decrement
predicate. a is ,DECR that Note
;|& 2,INSTR,DECR
0
and 1 typeof is n instructiowhen decrement We
state. program a is snapshot, a be ,Let
,
yx
xrpyxlyx
V
V - V i
ysix
yxlVAR
![Page 34: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/34.jpg)
Step 4d: When to Simulate a Branch
yxlyii
xrpyxl
yx
L V
L V i
ysix
yLt
yxlVAR
,GTLBL,LABEL
& |& 2,INSTR
,BRANCH
exists. label and 0
and GOTO 0! IF typeof is n instruction branch whe We
state. program a is snapshot, a be ,Let
1
,
![Page 35: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/35.jpg)
Proof So Far
• Step 1: Encoding a program state• Step 2: Encoding the initial snapshot• Step 3: Extracting an instruction components• Step 4: Defining conditions of instruction simulation:
– 4a) When to simulate skipping instruction;– 4b) When to simulate an increment;– 4c) When to simulate a decrement;– 4d) When to simulate a branch.
● Step 5: Simulating the successor snapshot● Step 6: Figuring out when to terminate● Step 7: Simulating the n-th snapshot● Step 8: Putting it all together
![Page 36: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/36.jpg)
Step 5: Successor Snapshot
.,SKIP if ,1,SUCC
s,other wordIn .,1,1
issnapshot next then theskipped, be tois n instructio If
number. program a is snapshot,current thebe ,Let
yxxrxlyx
xrxlsi
i
ysix
![Page 37: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/37.jpg)
Step 5: Successor Snapshot
.,INCR if ,1,SUCC
,INCR if s,other wordIn .,1 is
snapshotnext theincrement,an simulate tohave weIf
number. program a is snapshot, theis ,Let
,
,
yxpxrxlyx
yxpxrxl
ysix
yxlVAR
yxlVAR
![Page 38: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/38.jpg)
Step 5: Successor Snapshot
.,DECR if ,1,SUCC
s,other wordIn .,1
issnapshot next thedecrement, a simulate toneed weIf
number. program a is snapshot, thebe ,Let
,
,
yxp
xrxlyx
p
xrxl
ysix
yxlVAR
yxlVAR
![Page 39: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/39.jpg)
Step 5: Successor Snapshot
.,BRANCH if
,GTLBL,LABELmin,SUCC
s,other wordIn .,GTLBL,LABELmin
issnapshot next thebranch, tohave weIf
number. program a is snapshot, thebe ,Let
1
1
yx
xryxlyiyx
xryxlyi
ysix
yLti
yLti
![Page 40: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/40.jpg)
Step 5: Successor Snapshot
.simulation thestop webranch,or decrement,
increment, skip,not do weif s,other wordIn
;,11,SUCC
.,11,11snapshot terminal the togo we
dispatch, aor decrement, a increment,an skip, a simulatenot do weIf
number. program a is snapshot, thebe ,Let
xryLtyx
xryLtsyLt
ysix
![Page 41: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/41.jpg)
Step 5: Summary
otherwise. ,11
,BRANCH if
,GTLBL,LABELmin
,DECR if ,1
,INCR if ,1
,SKIP if ,1
,SUCC
1
,
,
xryLt
yx
xryxlyi
yxp
xrxl
yxpxrxl
yxxrxl
yx
yLti
yxlVAR
yxlVAR
![Page 42: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/42.jpg)
Proof So Far● Step 1: Encoding a program state● Step 2: Encoding the initial snapshot● Step 3: Extracting an instruction components● Step 4: Defining conditions of instruction simulation:
● 4a) When to simulate skipping instruction;● 4b) When to simulate an increment;● 4c) When to simulate a decrement;● 4d) When to simulate a branch.
● Step 5: Simulating the successor snapshot● Step 6: Figuring out when to terminate● Step 7: Simulating the n-th snapshot● Step 8: Putting it all together
![Page 43: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/43.jpg)
Step 6: Terminal Snapshot
.10,TERM
.1 or 0
s,other wordIn .1,1 when terminateWe
state. program a is ,snapshot thebe ,Let
yLtxlxlyx
yLti i
yLti
ysix
![Page 44: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/44.jpg)
Step 7: Simulating N-th Snapshot
ytyxxxtyxxx
xxxyxxx
yxxx
ysix
nn
nn
nn
nn
n
,,,,...,,SNAPSUCC1,,,...,,SNAP
,...,,INIT0,,,...,,SNAP
. toinputs are ,...,,
number, program a is snapshot, thebe ,Let
2121
2121
21
![Page 45: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/45.jpg)
Step 7: Examples
yyxxx
yyyxxx
yyxxxyxxx
yxxx
yyxxxyxxx
xxxyxxx
nn
nn
nn
nn
nn
nn
nn
nn
nn
,,,...,,INITSUCCSUCC
,,0,,,...,,SNAPSUCCSUCC
,1,,,...,,SNAPSUCC11,,,...,,SNAP
,,...,,INITSUCC
,0,,,...,,SNAPSUCC10,,,...,,SNAP
,...,,INIT0,,,...,,SNAP
21
21
2121
21
2121
2121
![Page 46: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/46.jpg)
Step 8: Putting It All Together
ytyxx
tyxx
nn
nn
,,,,...,SNAPTERM
,,,...,STP
1
1
![Page 47: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/47.jpg)
Proof Completed!• Step 1: Encoding a program state• Step 2: Encoding the initial snapshot• Step 3: Extracting an instruction components• Step 4: Defining conditions of instruction simulation:
– 4a) When to simulate skipping instruction;– 4b) When to simulate an increment;– 4c) When to simulate a decrement;– 4d) When to simulate a branch.
• Step 5: Simulating the successor snapshot• Step 6: Figuring out when to terminate• Step 7: Simulating the n-th snapshot• Step 8: Putting it all together
![Page 48: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/48.jpg)
Remember What We Have Proved?
![Page 49: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/49.jpg)
Theorem 3.2 (Ch. 4): STP Theorem
recursive. primitive is
,,,..., predicate the,0For 1)( tyxxSTPn n
n
![Page 50: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/50.jpg)
Back to The New Big Picture
GÖDEL Coder
GÖDEL Decoder
L Program Number Universal Program
Number
???
GÖDEL Coder = CompilerGÖDEL Decoder = Reverse CompilerUniversal Program = Operating System/VM/Interpreter
Universality Theorem
Simulator
Step-Counter Theorem
![Page 51: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/51.jpg)
Practical Implications
● We do not have to be tied to a specific universal program (operating system) to run our programs● Example: We do not need the L operating system to run L programs; for exam-
ple, we can implement an L simulator on Linux in C and run L programs● We can simulate one universal program (operating system) on another universal
program (operating system)● Example: VirtualBox (www.virtualbox.org) can be used simulate Linux on
Windows and Mac OS
![Page 52: Theory of Computation (Fall 2014): Step-Counter Theorem & Program Simulation](https://reader034.vdocuments.net/reader034/viewer/2022042700/55871d00d8b42a8b0b8b45e2/html5/thumbnails/52.jpg)
Reading Suggestions
● Ch. 4, Computability, Complexity, and Languages, 2nd Edition, by Davis, Weyuker, Sigal