:: RELOC semantic presentation

definition
let c1 be Instruction-Location of SCM ;
let c2 be Nat;
func c1 + c2 -> Instruction-Location of SCM means :Def1: :: RELOC:def 1
ex b1 being Nat st
( a1 = il. b1 & a3 = il. (b1 + a2) );
existence
ex b1 being Instruction-Location of SCM ex b2 being Nat st
( c1 = il. b2 & b1 = il. (b2 + c2) )
proof end;
uniqueness
for b1, b2 being Instruction-Location of SCM st ex b3 being Nat st
( c1 = il. b3 & b1 = il. (b3 + c2) ) & ex b3 being Nat st
( c1 = il. b3 & b2 = il. (b3 + c2) ) holds
b1 = b2
by AMI_3:53;
func c1 -' c2 -> Instruction-Location of SCM means :Def2: :: RELOC:def 2
ex b1 being Nat st
( a1 = il. b1 & a3 = il. (b1 -' a2) );
existence
ex b1 being Instruction-Location of SCM ex b2 being Nat st
( c1 = il. b2 & b1 = il. (b2 -' c2) )
proof end;
uniqueness
for b1, b2 being Instruction-Location of SCM st ex b3 being Nat st
( c1 = il. b3 & b1 = il. (b3 -' c2) ) & ex b3 being Nat st
( c1 = il. b3 & b2 = il. (b3 -' c2) ) holds
b1 = b2
by AMI_3:53;
end;

:: deftheorem Def1 defines + RELOC:def 1 :
for b1 being Instruction-Location of SCM
for b2 being Nat
for b3 being Instruction-Location of SCM holds
( b3 = b1 + b2 iff ex b4 being Nat st
( b1 = il. b4 & b3 = il. (b4 + b2) ) );

:: deftheorem Def2 defines -' RELOC:def 2 :
for b1 being Instruction-Location of SCM
for b2 being Nat
for b3 being Instruction-Location of SCM holds
( b3 = b1 -' b2 iff ex b4 being Nat st
( b1 = il. b4 & b3 = il. (b4 -' b2) ) );

theorem Th1: :: RELOC:1
for b1 being Instruction-Location of SCM
for b2 being Nat holds (b1 + b2) -' b2 = b1
proof end;

theorem Th2: :: RELOC:2
for b1, b2 being Instruction-Location of SCM
for b3 being Nat holds
( Start-At (b1 + b3) = Start-At (b2 + b3) iff Start-At b1 = Start-At b2 )
proof end;

theorem Th3: :: RELOC:3
for b1, b2 being Instruction-Location of SCM
for b3 being Nat st Start-At b1 = Start-At b2 holds
Start-At (b1 -' b3) = Start-At (b2 -' b3)
proof end;

definition
let c1 be Instruction of SCM ;
let c2 be Nat;
func IncAddr c1,c2 -> Instruction of SCM equals :Def3: :: RELOC:def 3
goto ((((@ a1) jump_address ) @ ) + a2) if InsCode a1 = 6
(((@ a1) cond_address ) @ ) =0_goto ((((@ a1) cjump_address ) @ ) + a2) if InsCode a1 = 7
(((@ a1) cond_address ) @ ) >0_goto ((((@ a1) cjump_address ) @ ) + a2) if InsCode a1 = 8
otherwise a1;
correctness
coherence
( ( InsCode c1 = 6 implies goto ((((@ c1) jump_address ) @ ) + c2) is Instruction of SCM ) & ( InsCode c1 = 7 implies (((@ c1) cond_address ) @ ) =0_goto ((((@ c1) cjump_address ) @ ) + c2) is Instruction of SCM ) & ( InsCode c1 = 8 implies (((@ c1) cond_address ) @ ) >0_goto ((((@ c1) cjump_address ) @ ) + c2) is Instruction of SCM ) & ( not InsCode c1 = 6 & not InsCode c1 = 7 & not InsCode c1 = 8 implies c1 is Instruction of SCM ) )
;
consistency
for b1 being Instruction of SCM holds
( ( InsCode c1 = 6 & InsCode c1 = 7 implies ( b1 = goto ((((@ c1) jump_address ) @ ) + c2) iff b1 = (((@ c1) cond_address ) @ ) =0_goto ((((@ c1) cjump_address ) @ ) + c2) ) ) & ( InsCode c1 = 6 & InsCode c1 = 8 implies ( b1 = goto ((((@ c1) jump_address ) @ ) + c2) iff b1 = (((@ c1) cond_address ) @ ) >0_goto ((((@ c1) cjump_address ) @ ) + c2) ) ) & ( InsCode c1 = 7 & InsCode c1 = 8 implies ( b1 = (((@ c1) cond_address ) @ ) =0_goto ((((@ c1) cjump_address ) @ ) + c2) iff b1 = (((@ c1) cond_address ) @ ) >0_goto ((((@ c1) cjump_address ) @ ) + c2) ) ) )
;
;
end;

:: deftheorem Def3 defines IncAddr RELOC:def 3 :
for b1 being Instruction of SCM
for b2 being Nat holds
( ( InsCode b1 = 6 implies IncAddr b1,b2 = goto ((((@ b1) jump_address ) @ ) + b2) ) & ( InsCode b1 = 7 implies IncAddr b1,b2 = (((@ b1) cond_address ) @ ) =0_goto ((((@ b1) cjump_address ) @ ) + b2) ) & ( InsCode b1 = 8 implies IncAddr b1,b2 = (((@ b1) cond_address ) @ ) >0_goto ((((@ b1) cjump_address ) @ ) + b2) ) & ( not InsCode b1 = 6 & not InsCode b1 = 7 & not InsCode b1 = 8 implies IncAddr b1,b2 = b1 ) );

theorem Th4: :: RELOC:4
for b1 being Nat holds IncAddr (halt SCM ),b1 = halt SCM by Def3, AMI_5:37;

theorem Th5: :: RELOC:5
for b1 being Nat
for b2, b3 being Data-Location holds IncAddr (b2 := b3),b1 = b2 := b3
proof end;

theorem Th6: :: RELOC:6
for b1 being Nat
for b2, b3 being Data-Location holds IncAddr (AddTo b2,b3),b1 = AddTo b2,b3
proof end;

theorem Th7: :: RELOC:7
for b1 being Nat
for b2, b3 being Data-Location holds IncAddr (SubFrom b2,b3),b1 = SubFrom b2,b3
proof end;

theorem Th8: :: RELOC:8
for b1 being Nat
for b2, b3 being Data-Location holds IncAddr (MultBy b2,b3),b1 = MultBy b2,b3
proof end;

theorem Th9: :: RELOC:9
for b1 being Nat
for b2, b3 being Data-Location holds IncAddr (Divide b2,b3),b1 = Divide b2,b3
proof end;

theorem Th10: :: RELOC:10
for b1 being Nat
for b2 being Instruction-Location of SCM holds IncAddr (goto b2),b1 = goto (b2 + b1)
proof end;

theorem Th11: :: RELOC:11
for b1 being Nat
for b2 being Instruction-Location of SCM
for b3 being Data-Location holds IncAddr (b3 =0_goto b2),b1 = b3 =0_goto (b2 + b1)
proof end;

theorem Th12: :: RELOC:12
for b1 being Nat
for b2 being Instruction-Location of SCM
for b3 being Data-Location holds IncAddr (b3 >0_goto b2),b1 = b3 >0_goto (b2 + b1)
proof end;

theorem Th13: :: RELOC:13
for b1 being Instruction of SCM
for b2 being Nat holds InsCode (IncAddr b1,b2) = InsCode b1
proof end;

theorem Th14: :: RELOC:14
for b1, b2 being Instruction of SCM
for b3 being Nat st ( InsCode b2 = 0 or InsCode b2 = 1 or InsCode b2 = 2 or InsCode b2 = 3 or InsCode b2 = 4 or InsCode b2 = 5 ) & IncAddr b1,b3 = b2 holds
b1 = b2
proof end;

definition
let c1 be programmed FinPartState of SCM ;
let c2 be Nat;
func Shift c1,c2 -> programmed FinPartState of SCM means :Def4: :: RELOC:def 4
( dom a3 = { (il. (b1 + a2)) where B is Nat : il. b1 in dom a1 } & ( for b1 being Nat st il. b1 in dom a1 holds
a3 . (il. (b1 + a2)) = a1 . (il. b1) ) );
existence
ex b1 being programmed FinPartState of SCM st
( dom b1 = { (il. (b2 + c2)) where B is Nat : il. b2 in dom c1 } & ( for b2 being Nat st il. b2 in dom c1 holds
b1 . (il. (b2 + c2)) = c1 . (il. b2) ) )
proof end;
uniqueness
for b1, b2 being programmed FinPartState of SCM st dom b1 = { (il. (b3 + c2)) where B is Nat : il. b3 in dom c1 } & ( for b3 being Nat st il. b3 in dom c1 holds
b1 . (il. (b3 + c2)) = c1 . (il. b3) ) & dom b2 = { (il. (b3 + c2)) where B is Nat : il. b3 in dom c1 } & ( for b3 being Nat st il. b3 in dom c1 holds
b2 . (il. (b3 + c2)) = c1 . (il. b3) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def4 defines Shift RELOC:def 4 :
for b1 being programmed FinPartState of SCM
for b2 being Nat
for b3 being programmed FinPartState of SCM holds
( b3 = Shift b1,b2 iff ( dom b3 = { (il. (b4 + b2)) where B is Nat : il. b4 in dom b1 } & ( for b4 being Nat st il. b4 in dom b1 holds
b3 . (il. (b4 + b2)) = b1 . (il. b4) ) ) );

theorem Th15: :: RELOC:15
for b1 being Instruction-Location of SCM
for b2 being Nat
for b3 being programmed FinPartState of SCM st b1 in dom b3 holds
(Shift b3,b2) . (b1 + b2) = b3 . b1
proof end;

theorem Th16: :: RELOC:16
for b1 being programmed FinPartState of SCM
for b2 being Nat holds dom (Shift b1,b2) = { (b3 + b2) where B is Instruction-Location of SCM : b3 in dom b1 }
proof end;

theorem Th17: :: RELOC:17
for b1 being programmed FinPartState of SCM
for b2 being Nat holds dom (Shift b1,b2) c= the Instruction-Locations of SCM
proof end;

definition
let c1 be programmed FinPartState of SCM ;
let c2 be Nat;
func IncAddr c1,c2 -> programmed FinPartState of SCM means :Def5: :: RELOC:def 5
( dom a3 = dom a1 & ( for b1 being Nat st il. b1 in dom a1 holds
a3 . (il. b1) = IncAddr (pi a1,(il. b1)),a2 ) );
existence
ex b1 being programmed FinPartState of SCM st
( dom b1 = dom c1 & ( for b2 being Nat st il. b2 in dom c1 holds
b1 . (il. b2) = IncAddr (pi c1,(il. b2)),c2 ) )
proof end;
uniqueness
for b1, b2 being programmed FinPartState of SCM st dom b1 = dom c1 & ( for b3 being Nat st il. b3 in dom c1 holds
b1 . (il. b3) = IncAddr (pi c1,(il. b3)),c2 ) & dom b2 = dom c1 & ( for b3 being Nat st il. b3 in dom c1 holds
b2 . (il. b3) = IncAddr (pi c1,(il. b3)),c2 ) holds
b1 = b2
proof end;
end;

:: deftheorem Def5 defines IncAddr RELOC:def 5 :
for b1 being programmed FinPartState of SCM
for b2 being Nat
for b3 being programmed FinPartState of SCM holds
( b3 = IncAddr b1,b2 iff ( dom b3 = dom b1 & ( for b4 being Nat st il. b4 in dom b1 holds
b3 . (il. b4) = IncAddr (pi b1,(il. b4)),b2 ) ) );

theorem Th18: :: RELOC:18
for b1 being programmed FinPartState of SCM
for b2 being Nat
for b3 being Instruction-Location of SCM st b3 in dom b1 holds
(IncAddr b1,b2) . b3 = IncAddr (pi b1,b3),b2
proof end;

theorem Th19: :: RELOC:19
for b1 being Nat
for b2 being programmed FinPartState of SCM holds Shift (IncAddr b2,b1),b1 = IncAddr (Shift b2,b1),b1
proof end;

definition
let c1 be FinPartState of SCM ;
let c2 be Nat;
func Relocated c1,c2 -> FinPartState of SCM equals :: RELOC:def 6
((Start-At ((IC a1) + a2)) +* (IncAddr (Shift (ProgramPart a1),a2),a2)) +* (DataPart a1);
correctness
coherence
((Start-At ((IC c1) + c2)) +* (IncAddr (Shift (ProgramPart c1),c2),c2)) +* (DataPart c1) is FinPartState of SCM
;
;
end;

:: deftheorem Def6 defines Relocated RELOC:def 6 :
for b1 being FinPartState of SCM
for b2 being Nat holds Relocated b1,b2 = ((Start-At ((IC b1) + b2)) +* (IncAddr (Shift (ProgramPart b1),b2),b2)) +* (DataPart b1);

theorem Th20: :: RELOC:20
for b1 being Nat
for b2 being FinPartState of SCM holds dom (IncAddr (Shift (ProgramPart b2),b1),b1) c= SCM-Instr-Loc
proof end;

theorem Th21: :: RELOC:21
for b1 being FinPartState of SCM
for b2 being Nat holds DataPart (Relocated b1,b2) = DataPart b1
proof end;

theorem Th22: :: RELOC:22
for b1 being FinPartState of SCM
for b2 being Nat holds ProgramPart (Relocated b1,b2) = IncAddr (Shift (ProgramPart b1),b2),b2
proof end;

theorem Th23: :: RELOC:23
for b1 being Nat
for b2 being FinPartState of SCM holds dom (ProgramPart (Relocated b2,b1)) = { (il. (b3 + b1)) where B is Nat : il. b3 in dom (ProgramPart b2) }
proof end;

theorem Th24: :: RELOC:24
for b1 being FinPartState of SCM
for b2 being Nat
for b3 being Instruction-Location of SCM holds
( b3 in dom b1 iff b3 + b2 in dom (Relocated b1,b2) )
proof end;

theorem Th25: :: RELOC:25
for b1 being FinPartState of SCM
for b2 being Nat holds IC SCM in dom (Relocated b1,b2)
proof end;

theorem Th26: :: RELOC:26
for b1 being FinPartState of SCM
for b2 being Nat holds IC (Relocated b1,b2) = (IC b1) + b2
proof end;

theorem Th27: :: RELOC:27
for b1 being FinPartState of SCM
for b2 being Nat
for b3 being Instruction-Location of SCM
for b4 being Instruction of SCM st b3 in dom (ProgramPart b1) & b4 = b1 . b3 holds
IncAddr b4,b2 = (Relocated b1,b2) . (b3 + b2)
proof end;

theorem Th28: :: RELOC:28
for b1 being FinPartState of SCM
for b2 being Nat holds Start-At ((IC b1) + b2) c= Relocated b1,b2
proof end;

theorem Th29: :: RELOC:29
for b1 being data-only FinPartState of SCM
for b2 being FinPartState of SCM
for b3 being Nat st IC SCM in dom b2 holds
Relocated (b2 +* b1),b3 = (Relocated b2,b3) +* b1
proof end;

theorem Th30: :: RELOC:30
for b1 being Nat
for b2 being autonomic FinPartState of SCM
for b3, b4 being State of SCM st b2 c= b3 & Relocated b2,b1 c= b4 holds
b2 c= b3 +* (b4 | SCM-Data-Loc )
proof end;

theorem Th31: :: RELOC:31
for b1 being Nat
for b2 being State of SCM holds Exec (IncAddr (CurInstr b2),b1),(b2 +* (Start-At ((IC b2) + b1))) = (Following b2) +* (Start-At ((IC (Following b2)) + b1))
proof end;

theorem Th32: :: RELOC:32
for b1 being Instruction of SCM
for b2 being State of SCM
for b3, b4 being Nat st IC b2 = il. (b3 + b4) holds
Exec b1,(b2 +* (Start-At ((IC b2) -' b4))) = (Exec (IncAddr b1,b4),b2) +* (Start-At ((IC (Exec (IncAddr b1,b4),b2)) -' b4))
proof end;

theorem Th33: :: RELOC:33
for b1 being Nat
for b2 being autonomic FinPartState of SCM st IC SCM in dom b2 holds
for b3 being State of SCM st b2 c= b3 holds
for b4 being Nat holds (Computation (b3 +* (Relocated b2,b1))) . b4 = (((Computation b3) . b4) +* (Start-At ((IC ((Computation b3) . b4)) + b1))) +* (ProgramPart (Relocated b2,b1))
proof end;

theorem Th34: :: RELOC:34
for b1 being Nat
for b2 being autonomic FinPartState of SCM
for b3, b4, b5 being State of SCM st IC SCM in dom b2 & b2 c= b3 & Relocated b2,b1 c= b4 & b5 = b3 +* (b4 | SCM-Data-Loc ) holds
for b6 being Nat holds
( (IC ((Computation b3) . b6)) + b1 = IC ((Computation b4) . b6) & IncAddr (CurInstr ((Computation b3) . b6)),b1 = CurInstr ((Computation b4) . b6) & ((Computation b3) . b6) | (dom (DataPart b2)) = ((Computation b4) . b6) | (dom (DataPart (Relocated b2,b1))) & ((Computation b5) . b6) | SCM-Data-Loc = ((Computation b4) . b6) | SCM-Data-Loc )
proof end;

theorem Th35: :: RELOC:35
for b1 being autonomic FinPartState of SCM
for b2 being Nat st IC SCM in dom b1 holds
( b1 is halting iff Relocated b1,b2 is halting )
proof end;

theorem Th36: :: RELOC:36
for b1 being Nat
for b2 being autonomic FinPartState of SCM st IC SCM in dom b2 holds
for b3 being State of SCM st Relocated b2,b1 c= b3 holds
for b4 being Nat holds (Computation b3) . b4 = ((((Computation (b3 +* b2)) . b4) +* (Start-At ((IC ((Computation (b3 +* b2)) . b4)) + b1))) +* (b3 | (dom (ProgramPart b2)))) +* (ProgramPart (Relocated b2,b1))
proof end;

theorem Th37: :: RELOC:37
for b1 being Nat
for b2 being FinPartState of SCM st IC SCM in dom b2 holds
for b3 being State of SCM st b2 c= b3 & Relocated b2,b1 is autonomic holds
for b4 being Nat holds (Computation b3) . b4 = ((((Computation (b3 +* (Relocated b2,b1))) . b4) +* (Start-At ((IC ((Computation (b3 +* (Relocated b2,b1))) . b4)) -' b1))) +* (b3 | (dom (ProgramPart (Relocated b2,b1))))) +* (ProgramPart b2)
proof end;

theorem Th38: :: RELOC:38
for b1 being FinPartState of SCM st IC SCM in dom b1 holds
for b2 being Nat holds
( b1 is autonomic iff Relocated b1,b2 is autonomic )
proof end;

theorem Th39: :: RELOC:39
for b1 being autonomic halting FinPartState of SCM st IC SCM in dom b1 holds
for b2 being Nat holds DataPart (Result b1) = DataPart (Result (Relocated b1,b2))
proof end;

theorem Th40: :: RELOC:40
for b1 being PartFunc of FinPartSt SCM , FinPartSt SCM
for b2 being FinPartState of SCM st IC SCM in dom b2 & b1 is data-only holds
for b3 being Nat holds
( b2 computes b1 iff Relocated b2,b3 computes b1 )
proof end;