Article SCMP_GCD, MML version 4.99.1005

:: SCMP_GCD:th 3
theorem
for b1 being Element of NAT
for b2 being integer set
      st inspos b1 = b2
   holds inspos (b1 + 2) = (abs b2) + 2;

:: SCMP_GCD:funcnot 1 => SCMP_GCD:func 1
definition
  let a1 be natural set;
  func intpos A1 -> Int_position equals
    dl. a1;
end;

:: SCMP_GCD:def 1
theorem
for b1 being natural set holds
   intpos b1 = dl. b1;

:: SCMP_GCD:th 5
theorem
for b1, b2 being Element of NAT holds
DataLoc(b1,b2) = intpos (b1 + b2);

:: SCMP_GCD:th 6
theorem
for b1 being Element of product the Object-Kind of SCMPDS
for b2, b3 being Element of NAT
      st IC b1 = inspos (b2 + b3)
   holds ICplusConst(b1,- b3) = inspos b2;

:: SCMP_GCD:funcnot 2 => SCMP_GCD:func 2
definition
  func GBP -> Int_position equals
    intpos 0;
end;

:: SCMP_GCD:def 2
theorem
GBP = intpos 0;

:: SCMP_GCD:funcnot 3 => SCMP_GCD:func 3
definition
  func SBP -> Int_position equals
    intpos 1;
end;

:: SCMP_GCD:def 3
theorem
SBP = intpos 1;

:: SCMP_GCD:th 7
theorem
GBP <> SBP;

:: SCMP_GCD:th 8
theorem
for b1 being Element of the Instructions of SCMPDS
for b2 being finite programmed initial Element of sproduct the Object-Kind of SCMPDS holds
   card (b2 ';' b1) = (card b2) + 1;

:: SCMP_GCD:th 9
theorem
for b1, b2 being Element of the Instructions of SCMPDS holds
card (b1 ';' b2) = 2;

:: SCMP_GCD:th 10
theorem
for b1 being Element of the Instructions of SCMPDS
for b2 being finite programmed initial Element of sproduct the Object-Kind of SCMPDS holds
   (b2 ';' b1) . inspos card b2 = b1 & inspos card b2 in proj1 (b2 ';' b1);

:: SCMP_GCD:th 11
theorem
for b1 being Element of the Instructions of SCMPDS
for b2, b3 being finite programmed initial Element of sproduct the Object-Kind of SCMPDS holds
((b2 ';' b1) ';' b3) . inspos card b2 = b1;

:: SCMP_GCD:funcnot 4 => SCMP_GCD:func 4
definition
  func GCD-Algorithm -> finite programmed initial Element of sproduct the Object-Kind of SCMPDS equals
    ((((((((((((((GBP := 0) ';' (SBP := 7)) ';' saveIC(SBP,RetIC)) ';' goto 2) ';' halt SCMPDS) ';' ((SBP,3)<=0_goto 9)) ';' ((SBP,6):=(SBP,3))) ';' Divide(SBP,2,SBP,3)) ';' ((SBP,7):=(SBP,3))) ';' ((SBP,4 + RetSP):=(GBP,1))) ';' AddTo(GBP,1,4)) ';' saveIC(SBP,RetIC)) ';' goto - 7) ';' ((SBP,2):=(SBP,6))) ';' return SBP;
end;

:: SCMP_GCD:def 4
theorem
GCD-Algorithm = ((((((((((((((GBP := 0) ';' (SBP := 7)) ';' saveIC(SBP,RetIC)) ';' goto 2) ';' halt SCMPDS) ';' ((SBP,3)<=0_goto 9)) ';' ((SBP,6):=(SBP,3))) ';' Divide(SBP,2,SBP,3)) ';' ((SBP,7):=(SBP,3))) ';' ((SBP,4 + RetSP):=(GBP,1))) ';' AddTo(GBP,1,4)) ';' saveIC(SBP,RetIC)) ';' goto - 7) ';' ((SBP,2):=(SBP,6))) ';' return SBP;

:: SCMP_GCD:th 12
theorem
card GCD-Algorithm = 15;

:: SCMP_GCD:th 13
theorem
for b1 being Element of NAT holds
      b1 < 15
   iff
      inspos b1 in proj1 GCD-Algorithm;

:: SCMP_GCD:th 14
theorem
GCD-Algorithm . inspos 0 = GBP := 0 &
 GCD-Algorithm . inspos 1 = SBP := 7 &
 GCD-Algorithm . inspos 2 = saveIC(SBP,RetIC) &
 GCD-Algorithm . inspos 3 = goto 2 &
 GCD-Algorithm . inspos 4 = halt SCMPDS &
 GCD-Algorithm . inspos 5 = (SBP,3)<=0_goto 9 &
 GCD-Algorithm . inspos 6 = (SBP,6):=(SBP,3) &
 GCD-Algorithm . inspos 7 = Divide(SBP,2,SBP,3) &
 GCD-Algorithm . inspos 8 = (SBP,7):=(SBP,3) &
 GCD-Algorithm . inspos 9 = (SBP,4 + RetSP):=(GBP,1) &
 GCD-Algorithm . inspos 10 = AddTo(GBP,1,4) &
 GCD-Algorithm . inspos 11 = saveIC(SBP,RetIC) &
 GCD-Algorithm . inspos 12 = goto - 7 &
 GCD-Algorithm . inspos 13 = (SBP,2):=(SBP,6) &
 GCD-Algorithm . inspos 14 = return SBP;

:: SCMP_GCD:th 15
theorem
for b1 being Element of product the Object-Kind of SCMPDS
      st Initialized GCD-Algorithm c= b1
   holds IC Computation(b1,4) = inspos 5 &
    (Computation(b1,4)) . GBP = 0 &
    (Computation(b1,4)) . SBP = 7 &
    (Computation(b1,4)) . intpos (7 + RetIC) = inspos 2 &
    (Computation(b1,4)) . intpos 9 = b1 . intpos 9 &
    (Computation(b1,4)) . intpos 10 = b1 . intpos 10;

:: SCMP_GCD:th 16
theorem
for b1 being Element of product the Object-Kind of SCMPDS
      st GCD-Algorithm c= b1 &
         IC b1 = inspos 5 &
         0 < b1 . SBP &
         b1 . GBP = 0 &
         0 <= b1 . DataLoc(b1 . SBP,3) &
         b1 . DataLoc(b1 . SBP,3) <= b1 . DataLoc(b1 . SBP,2)
   holds ex b2 being Element of NAT st
      CurInstr Computation(b1,b2) = return SBP &
       b1 . SBP = (Computation(b1,b2)) . SBP &
       (Computation(b1,b2)) . DataLoc(b1 . SBP,2) = (b1 . DataLoc(b1 . SBP,2)) gcd (b1 . DataLoc(b1 . SBP,3)) &
       (for b3 being Element of NAT
             st 1 < b3 & b3 <= (b1 . SBP) + 1
          holds b1 . intpos b3 = (Computation(b1,b2)) . intpos b3);

:: SCMP_GCD:th 17
theorem
for b1 being Element of product the Object-Kind of SCMPDS
      st GCD-Algorithm c= b1 &
         IC b1 = inspos 5 &
         0 < b1 . SBP &
         b1 . GBP = 0 &
         0 <= b1 . DataLoc(b1 . SBP,3) &
         0 <= b1 . DataLoc(b1 . SBP,2)
   holds ex b2 being Element of NAT st
      CurInstr Computation(b1,b2) = return SBP &
       b1 . SBP = (Computation(b1,b2)) . SBP &
       (Computation(b1,b2)) . DataLoc(b1 . SBP,2) = (b1 . DataLoc(b1 . SBP,2)) gcd (b1 . DataLoc(b1 . SBP,3)) &
       (for b3 being Element of NAT
             st 1 < b3 & b3 <= (b1 . SBP) + 1
          holds b1 . intpos b3 = (Computation(b1,b2)) . intpos b3);

:: SCMP_GCD:th 18
theorem
for b1 being Element of product the Object-Kind of SCMPDS
   st Initialized GCD-Algorithm c= b1
for b2, b3 being integer set
      st b1 . intpos 9 = b2 & b1 . intpos 10 = b3 & 0 <= b2 & 0 <= b3
   holds (Result b1) . intpos 9 = b2 gcd b3;

:: SCMP_GCD:th 19
theorem
for b1 being finite Element of sproduct the Object-Kind of SCMPDS
for b2, b3 being integer set
      st 0 <= b3 & b3 <= b2 & b1 = (intpos 9,intpos 10)-->(b2,b3)
   holds (Initialized GCD-Algorithm) +* b1 is autonomic(NAT, {INT}, SCMPDS);