:: SFMASTR1 semantic presentation

definition
let i be Instruction of SCM+FSA ;
attr a1 is good means :Def1: :: SFMASTR1:def 1
Macro i is good;
end;

:: deftheorem Def1 defines good SFMASTR1:def 1 :
for i being Instruction of SCM+FSA holds
( i is good iff Macro i is good );

registration
let a be read-write Int-Location ;
let b be Int-Location ;
cluster a1 := a2 -> good ;
coherence
a := b is good
proof end;
cluster AddTo a1,a2 -> good ;
coherence
AddTo a,b is good
proof end;
cluster SubFrom a1,a2 -> good ;
coherence
SubFrom a,b is good
proof end;
cluster MultBy a1,a2 -> good ;
coherence
MultBy a,b is good
proof end;
end;

registration
cluster parahalting good Element of the Instructions of SCM+FSA ;
existence
ex b1 being Instruction of SCM+FSA st
( b1 is good & b1 is parahalting )
proof end;
end;

registration
let a be read-write Int-Location , b be read-write Int-Location ;
cluster Divide a1,a2 -> good ;
coherence
Divide a,b is good
proof end;
end;

registration
let l be Instruction-Location of SCM+FSA ;
cluster goto a1 -> good ;
coherence
goto l is good
proof end;
end;

registration
let a be Int-Location ;
let l be Instruction-Location of SCM+FSA ;
cluster a1 =0_goto a2 -> good ;
coherence
a =0_goto l is good
proof end;
cluster a1 >0_goto a2 -> good ;
coherence
a >0_goto l is good
proof end;
end;

registration
let a be Int-Location ;
let f be FinSeq-Location ;
let b be read-write Int-Location ;
cluster a3 := a2,a1 -> good ;
coherence
b := f,a is good
proof end;
end;

registration
let f be FinSeq-Location ;
let b be read-write Int-Location ;
cluster a2 :=len a1 -> good ;
coherence
b :=len f is good
proof end;
end;

registration
let f be FinSeq-Location ;
let a be Int-Location ;
cluster a1 :=<0,...,0> a2 -> good ;
coherence
f :=<0,...,0> a is good
proof end;
let b be Int-Location ;
cluster a1,a2 := a3 -> good ;
coherence
f,a := b is good
proof end;
end;

registration
cluster good Element of the Instructions of SCM+FSA ;
existence
ex b1 being Instruction of SCM+FSA st b1 is good
proof end;
end;

registration
let i be good Instruction of SCM+FSA ;
cluster Macro a1 -> good ;
coherence
Macro i is good
by ;
end;

registration
let i be good Instruction of SCM+FSA , j be good Instruction of SCM+FSA ;
cluster a1 ';' a2 -> good ;
coherence
i ';' j is good
proof end;
end;

registration
let i be good Instruction of SCM+FSA ;
let I be good Macro-Instruction;
cluster a1 ';' a2 -> good ;
coherence
i ';' I is good
proof end;
cluster a2 ';' a1 -> good ;
coherence
I ';' i is good
proof end;
end;

registration
let a be read-write Int-Location , b be read-write Int-Location ;
cluster swap a1,a2 -> good ;
coherence
swap a,b is good
proof end;
end;

registration
let I be good Macro-Instruction;
let a be read-write Int-Location ;
cluster Times a2,a1 -> good ;
coherence
Times a,I is good
proof end;
end;

theorem Th1: :: SFMASTR1:1
for a being Int-Location
for I being Macro-Instruction st not a in UsedIntLoc I holds
I does_not_destroy a
proof end;

set D = Int-Locations \/ FinSeq-Locations ;

theorem Th2: :: SFMASTR1:2
for I being Macro-Instruction holds (I +* (Start-At (insloc 0))) | (Int-Locations \/ FinSeq-Locations ) = {}
proof end;

theorem Th3: :: SFMASTR1:3
for S being State of SCM+FSA
for I, J being Macro-Instruction st I is_halting_on Initialize S & I is_closed_on Initialize S & J is_closed_on IExec I,S holds
I ';' J is_closed_on Initialize S
proof end;

theorem Th4: :: SFMASTR1:4
for S being State of SCM+FSA
for I, J being Macro-Instruction st I is_halting_on Initialize S & J is_halting_on IExec I,S & I is_closed_on Initialize S & J is_closed_on IExec I,S holds
I ';' J is_halting_on Initialize S
proof end;

theorem Th5: :: SFMASTR1:5
for s being State of SCM+FSA
for I, J being Macro-Instruction st I is_closed_on s & I +* (Start-At (insloc 0)) c= s & s is halting holds
for m being Element of NAT st m <= LifeSpan s holds
(Computation s) . m,(Computation (s +* (I ';' J))) . m equal_outside the Instruction-Locations of SCM+FSA
proof end;

Lemma96: for I being good Macro-Instruction
for J being Macro-Instruction
for s being State of SCM+FSA st s . (intloc 0) = 1 & I is_halting_on s & J is_halting_on IExec I,s & I is_closed_on s & J is_closed_on IExec I,s & Initialized (I ';' J) c= s holds
( IC ((Computation s) . ((LifeSpan (s +* I)) + 1)) = insloc (card I) & ((Computation s) . ((LifeSpan (s +* I)) + 1)) | (Int-Locations \/ FinSeq-Locations ) = (((Computation (s +* I)) . (LifeSpan (s +* I))) +* (Initialized J)) | (Int-Locations \/ FinSeq-Locations ) & ProgramPart (Relocated J,(card I)) c= (Computation s) . ((LifeSpan (s +* I)) + 1) & ((Computation s) . ((LifeSpan (s +* I)) + 1)) . (intloc 0) = 1 & s is halting & LifeSpan s = ((LifeSpan (s +* I)) + 1) + (LifeSpan ((Result (s +* I)) +* (Initialized J))) & ( J is good implies (Result s) . (intloc 0) = 1 ) )
proof end;

theorem Th6: :: SFMASTR1:6
for s being State of SCM+FSA
for J being Macro-Instruction
for Ig being good Macro-Instruction st Ig is_halting_on Initialize s & J is_halting_on IExec Ig,s & Ig is_closed_on Initialize s & J is_closed_on IExec Ig,s holds
LifeSpan (s +* (Initialized (Ig ';' J))) = ((LifeSpan (s +* (Initialized Ig))) + 1) + (LifeSpan ((Result (s +* (Initialized Ig))) +* (Initialized J)))
proof end;

theorem Th7: :: SFMASTR1:7
for s being State of SCM+FSA
for J being Macro-Instruction
for Ig being good Macro-Instruction st Ig is_halting_on Initialize s & J is_halting_on IExec Ig,s & Ig is_closed_on Initialize s & J is_closed_on IExec Ig,s holds
IExec (Ig ';' J),s = (IExec J,(IExec Ig,s)) +* (Start-At ((IC (IExec J,(IExec Ig,s))) + (card Ig)))
proof end;

E129: now
let I be Macro-Instruction;
assume I is parahalting ;
then reconsider I' = I as parahalting Macro-Instruction ;
I' is paraclosed ;
hence I is paraclosed ;
end;

theorem Th8: :: SFMASTR1:8
for s being State of SCM+FSA
for J being Macro-Instruction
for Ig being good Macro-Instruction
for a being Int-Location st ( Ig is parahalting or ( Ig is_halting_on Initialize s & Ig is_closed_on Initialize s ) ) & ( J is parahalting or ( J is_halting_on IExec Ig,s & J is_closed_on IExec Ig,s ) ) holds
(IExec (Ig ';' J),s) . a = (IExec J,(IExec Ig,s)) . a
proof end;

theorem Th9: :: SFMASTR1:9
for s being State of SCM+FSA
for J being Macro-Instruction
for Ig being good Macro-Instruction
for f being FinSeq-Location st ( Ig is parahalting or ( Ig is_halting_on Initialize s & Ig is_closed_on Initialize s ) ) & ( J is parahalting or ( J is_halting_on IExec Ig,s & J is_closed_on IExec Ig,s ) ) holds
(IExec (Ig ';' J),s) . f = (IExec J,(IExec Ig,s)) . f
proof end;

theorem Th10: :: SFMASTR1:10
for s being State of SCM+FSA
for J being Macro-Instruction
for Ig being good Macro-Instruction st ( Ig is parahalting or ( Ig is_halting_on Initialize s & Ig is_closed_on Initialize s ) ) & ( J is parahalting or ( J is_halting_on IExec Ig,s & J is_closed_on IExec Ig,s ) ) holds
(IExec (Ig ';' J),s) | (Int-Locations \/ FinSeq-Locations ) = (IExec J,(IExec Ig,s)) | (Int-Locations \/ FinSeq-Locations )
proof end;

theorem Th11: :: SFMASTR1:11
for s being State of SCM+FSA
for Ig being good Macro-Instruction st ( Ig is parahalting or ( Ig is_closed_on Initialize s & Ig is_halting_on Initialize s ) ) holds
(Initialize (IExec Ig,s)) | (Int-Locations \/ FinSeq-Locations ) = (IExec Ig,s) | (Int-Locations \/ FinSeq-Locations )
proof end;

theorem Th12: :: SFMASTR1:12
for s being State of SCM+FSA
for Ig being good Macro-Instruction
for j being parahalting Instruction of SCM+FSA
for a being Int-Location st ( Ig is parahalting or ( Ig is_halting_on Initialize s & Ig is_closed_on Initialize s ) ) holds
(IExec (Ig ';' j),s) . a = (Exec j,(IExec Ig,s)) . a
proof end;

theorem Th13: :: SFMASTR1:13
for s being State of SCM+FSA
for Ig being good Macro-Instruction
for j being parahalting Instruction of SCM+FSA
for f being FinSeq-Location st ( Ig is parahalting or ( Ig is_halting_on Initialize s & Ig is_closed_on Initialize s ) ) holds
(IExec (Ig ';' j),s) . f = (Exec j,(IExec Ig,s)) . f
proof end;

theorem Th14: :: SFMASTR1:14
for s being State of SCM+FSA
for Ig being good Macro-Instruction
for j being parahalting Instruction of SCM+FSA st ( Ig is parahalting or ( Ig is_halting_on Initialize s & Ig is_closed_on Initialize s ) ) holds
(IExec (Ig ';' j),s) | (Int-Locations \/ FinSeq-Locations ) = (Exec j,(IExec Ig,s)) | (Int-Locations \/ FinSeq-Locations )
proof end;

theorem Th15: :: SFMASTR1:15
for s being State of SCM+FSA
for J being Macro-Instruction
for i being parahalting good Instruction of SCM+FSA
for a being Int-Location st ( J is parahalting or ( J is_halting_on Exec i,(Initialize s) & J is_closed_on Exec i,(Initialize s) ) ) holds
(IExec (i ';' J),s) . a = (IExec J,(Exec i,(Initialize s))) . a
proof end;

theorem Th16: :: SFMASTR1:16
for s being State of SCM+FSA
for J being Macro-Instruction
for i being parahalting good Instruction of SCM+FSA
for f being FinSeq-Location st ( J is parahalting or ( J is_halting_on Exec i,(Initialize s) & J is_closed_on Exec i,(Initialize s) ) ) holds
(IExec (i ';' J),s) . f = (IExec J,(Exec i,(Initialize s))) . f
proof end;

theorem Th17: :: SFMASTR1:17
for s being State of SCM+FSA
for J being Macro-Instruction
for i being parahalting good Instruction of SCM+FSA st ( J is parahalting or ( J is_halting_on Exec i,(Initialize s) & J is_closed_on Exec i,(Initialize s) ) ) holds
(IExec (i ';' J),s) | (Int-Locations \/ FinSeq-Locations ) = (IExec J,(Exec i,(Initialize s))) | (Int-Locations \/ FinSeq-Locations )
proof end;

definition
let d be Int-Location ;
redefine func { as {c1} -> Subset of Int-Locations ;
coherence
{d} is Subset of Int-Locations
proof end;
let e be Int-Location ;
redefine func { as {c1,c2} -> Subset of Int-Locations ;
coherence
{d,e} is Subset of Int-Locations
proof end;
let f be Int-Location ;
redefine func { as {c1,c2,c3} -> Subset of Int-Locations ;
coherence
{d,e,f} is Subset of Int-Locations
proof end;
let g be Int-Location ;
redefine func { as {c1,c2,c3,c4} -> Subset of Int-Locations ;
coherence
{d,e,f,g} is Subset of Int-Locations
proof end;
end;

Lemma146: for X being set st not X is finite holds
not X is empty
proof end;

definition
let L be finite Subset of Int-Locations ;
func RWNotIn-seq c1 -> Function of NAT , bool NAT means :Def2: :: SFMASTR1:def 2
( it . 0 = { k where k is Element of NAT : ( not intloc k in D & k <> 0 ) } & ( for i being Element of NAT
for sn being non empty Subset of NAT st it . i = sn holds
it . (i + 1) = sn \ {(min sn)} ) & ( for i being Element of NAT holds not it . i is finite ) );
existence
ex b1 being Function of NAT , bool NAT st
( b1 . 0 = { k where k is Element of NAT : ( not intloc k in L & k <> 0 ) } & ( for i being Element of NAT
for sn being non empty Subset of NAT st b1 . i = sn holds
b1 . (i + 1) = sn \ {(min sn)} ) & ( for i being Element of NAT holds not b1 . i is finite ) )
proof end;
uniqueness
for b1, b2 being Function of NAT , bool NAT st b1 . 0 = { k where k is Element of NAT : ( not intloc k in L & k <> 0 ) } & ( for i being Element of NAT
for sn being non empty Subset of NAT st b1 . i = sn holds
b1 . (i + 1) = sn \ {(min sn)} ) & ( for i being Element of NAT holds not b1 . i is finite ) & b2 . 0 = { k where k is Element of NAT : ( not intloc k in L & k <> 0 ) } & ( for i being Element of NAT
for sn being non empty Subset of NAT st b2 . i = sn holds
b2 . (i + 1) = sn \ {(min sn)} ) & ( for i being Element of NAT holds not b2 . i is finite ) holds
b1 = b2
proof end;
end;

:: deftheorem Def2 defines RWNotIn-seq SFMASTR1:def 2 :
for L being finite Subset of Int-Locations
for b2 being Function of NAT , bool NAT holds
( b2 = RWNotIn-seq L iff ( b2 . 0 = { k where k is Element of NAT : ( not intloc k in L & k <> 0 ) } & ( for i being Element of NAT
for sn being non empty Subset of NAT st b2 . i = sn holds
b2 . (i + 1) = sn \ {(min sn)} ) & ( for i being Element of NAT holds not b2 . i is finite ) ) );

registration
let L be finite Subset of Int-Locations ;
let n be Element of NAT ;
cluster (RWNotIn-seq a1) . a2 -> non empty ;
coherence
not (RWNotIn-seq L) . n is empty
by ;
end;

theorem Th18: :: SFMASTR1:18
for L being finite Subset of Int-Locations
for n being Element of NAT holds
( not 0 in (RWNotIn-seq L) . n & ( for m being Element of NAT st m in (RWNotIn-seq L) . n holds
not intloc m in L ) )
proof end;

theorem Th19: :: SFMASTR1:19
for L being finite Subset of Int-Locations
for n being Element of NAT holds min ((RWNotIn-seq L) . n) < min ((RWNotIn-seq L) . (n + 1))
proof end;

theorem Th20: :: SFMASTR1:20
for L being finite Subset of Int-Locations
for n, m being Element of NAT st n < m holds
min ((RWNotIn-seq L) . n) < min ((RWNotIn-seq L) . m)
proof end;

definition
let n be Element of NAT ;
let L be finite Subset of Int-Locations ;
func c1 -thRWNotIn c2 -> Int-Location equals :: SFMASTR1:def 3
intloc (min ((RWNotIn-seq n) . D));
correctness
coherence
intloc (min ((RWNotIn-seq L) . n)) is Int-Location
;
;
end;

:: deftheorem Def3 defines -thRWNotIn SFMASTR1:def 3 :
for n being Element of NAT
for L being finite Subset of Int-Locations holds n -thRWNotIn L = intloc (min ((RWNotIn-seq L) . n));

notation
let n be Element of NAT ;
let L be finite Subset of Int-Locations ;
synonym c1 -stRWNotIn c2 for c1 -thRWNotIn c2;
synonym c1 -ndRWNotIn c2 for c1 -thRWNotIn c2;
synonym c1 -rdRWNotIn c2 for c1 -thRWNotIn c2;
end;

registration
let n be Element of NAT ;
let L be finite Subset of Int-Locations ;
cluster a1 -thRWNotIn a2 -> read-write ;
coherence
not n -thRWNotIn L is read-only
proof end;
end;

theorem Th21: :: SFMASTR1:21
for L being finite Subset of Int-Locations
for n being Element of NAT holds not n -thRWNotIn L in L
proof end;

theorem Th22: :: SFMASTR1:22
for L being finite Subset of Int-Locations
for n, m being Element of NAT st n <> m holds
n -thRWNotIn L <> m -thRWNotIn L
proof end;

definition
let n be Element of NAT ;
let p be programmed FinPartState of SCM+FSA ;
func c1 -thNotUsed c2 -> Int-Location equals :: SFMASTR1:def 4
D -thRWNotIn (UsedIntLoc n);
correctness
coherence
n -thRWNotIn (UsedIntLoc p) is Int-Location
;
;
end;

:: deftheorem Def4 defines -thNotUsed SFMASTR1:def 4 :
for n being Element of NAT
for p being programmed FinPartState of SCM+FSA holds n -thNotUsed p = n -thRWNotIn (UsedIntLoc p);

notation
let n be Element of NAT ;
let p be programmed FinPartState of SCM+FSA ;
synonym c1 -stNotUsed c2 for c1 -thNotUsed c2;
synonym c1 -ndNotUsed c2 for c1 -thNotUsed c2;
synonym c1 -rdNotUsed c2 for c1 -thNotUsed c2;
end;

registration
let n be Element of NAT ;
let p be programmed FinPartState of SCM+FSA ;
cluster a1 -thNotUsed a2 -> read-write ;
coherence
not n -thNotUsed p is read-only
;
end;

theorem Th23: :: SFMASTR1:23
for a, b being Int-Location holds
( a in UsedIntLoc (swap a,b) & b in UsedIntLoc (swap a,b) )
proof end;

definition
let N be Int-Location , result be Int-Location ;
set next = 1 -stRWNotIn {N,result};
set aux = 1 -stRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})));
set Nsave = 2 -ndRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})));
func Fib_macro c1,c2 -> Macro-Instruction equals :: SFMASTR1:def 5
((((((2 -ndRWNotIn (UsedIntLoc (swap N,(1 -stRWNotIn {D,N})))) := D) ';' (SubFrom N,N)) ';' ((1 -stRWNotIn {D,N}) := (intloc 0))) ';' ((1 -stRWNotIn (UsedIntLoc (swap N,(1 -stRWNotIn {D,N})))) := (2 -ndRWNotIn (UsedIntLoc (swap N,(1 -stRWNotIn {D,N})))))) ';' (Times (1 -stRWNotIn (UsedIntLoc (swap N,(1 -stRWNotIn {D,N})))),((AddTo N,(1 -stRWNotIn {D,N})) ';' (swap N,(1 -stRWNotIn {D,N}))))) ';' (D := (2 -ndRWNotIn (UsedIntLoc (swap N,(1 -stRWNotIn {D,N})))));
correctness
coherence
((((((2 -ndRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))) := N) ';' (SubFrom result,result)) ';' ((1 -stRWNotIn {N,result}) := (intloc 0))) ';' ((1 -stRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))) := (2 -ndRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))))) ';' (Times (1 -stRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))),((AddTo result,(1 -stRWNotIn {N,result})) ';' (swap result,(1 -stRWNotIn {N,result}))))) ';' (N := (2 -ndRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result}))))) is Macro-Instruction
;
;
end;

:: deftheorem Def5 defines Fib_macro SFMASTR1:def 5 :
for N, result being Int-Location holds Fib_macro N,result = ((((((2 -ndRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))) := N) ';' (SubFrom result,result)) ';' ((1 -stRWNotIn {N,result}) := (intloc 0))) ';' ((1 -stRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))) := (2 -ndRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))))) ';' (Times (1 -stRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))),((AddTo result,(1 -stRWNotIn {N,result})) ';' (swap result,(1 -stRWNotIn {N,result}))))) ';' (N := (2 -ndRWNotIn (UsedIntLoc (swap result,(1 -stRWNotIn {N,result})))));

theorem Th24: :: SFMASTR1:24
for s being State of SCM+FSA
for N, result being read-write Int-Location st N <> result holds
for n being Element of NAT st n = s . N holds
( (IExec (Fib_macro N,result),s) . result = Fib n & (IExec (Fib_macro N,result),s) . N = s . N )
proof end;