Title: Boehm - Jacopini Theorem
1Boehm - Jacopini Theorem
The essence of the theorem is that every program
that uses goto instructions can be expressed via
if and while.
In other words, a language that includes if and
while is functionally equivalent to the same
language with go.
2Boehm - Jacopini Theorem
Begin with a segment of code, including goto
instructions
S1 S2 ... SN
Step 1 Relabel every instruction (Sj) with Lj
and update gotos to match.
L1 S1 L2 S2 ... LN SN
Step 2 Select an integer variable, call it loc,
not used in the program. Wrap the
following around the entire program loc
1 while (loc ! N)
translatedCodeGoesHere
3Step 3 Replace each instruction (Sj) according
to these rules goto Rule Replace
Lk goto Lm with if
(lock) loc m if-goto
Rule Replace Lk if (cond) goto Lm
with if (lock) if (cond)
locm else loc other
Rule Replace Lk instructionk
with if (lock) instructionk
loc
4Example
loc 1 while (loc!7) if (loc1)
j1 loc if (loc2) if (jgtN)
loc 6 else loc
if (loc3) aj0 loc
if (loc4) j j 1 loc
if (loc5) loc2 if (loc6)
write(the end) loc
Original j 1 Top if (jgtN) goto
Done aj 0 j j 1
goto Top Done write( the end)
The End!