reserve m,n for Nat,
  a,b for Int_position,
  i,j for Instruction of SCMPDS,
  s,s1,s2 for State of SCMPDS,
  I,J for Program of SCMPDS;
reserve P,P1,P2 for Instruction-Sequence of SCMPDS;

theorem Th12:
  for s being State of SCMPDS st GCD-Algorithm c= P
  & IC s =  5 & s.SBP >0 & s.GBP=0 &
  s.DataLoc(s.SBP,3) >= 0 & s.DataLoc(s.SBP,2) >= s.DataLoc(s.SBP,3) holds
  ex n st CurInstr(P,Comput(P,s,n)) =
  return SBP &
  s.SBP=Comput(P,s,n).SBP & Comput(P,s,n).DataLoc(s.SBP,2)
  =s.DataLoc(s.SBP,2) gcd s.DataLoc(s.SBP,3) &
  for j be Nat st 1<j & j <= s.SBP+1 holds
  s.intpos j=Comput(P,s,n).intpos j
proof
  set GA=GCD-Algorithm;
  defpred P[Nat] means for s being State of SCMPDS st
   GA c= P
  & IC s =  5 & s.SBP >0 & s.GBP=0 & s.DataLoc(s.SBP,3) <= $1 &
  s.DataLoc(s.SBP,3) >= 0 & s.DataLoc(s.SBP,2) >= s.DataLoc(s.SBP,3)
  holds ex n st CurInstr(P,Comput(P,s,n)) =
  return SBP &
  s.SBP=Comput(P,s,n).SBP & Comput(P,s,n).DataLoc(s.SBP,2)
  =s.DataLoc(s.SBP,2) gcd s.DataLoc(s.SBP,3) &
  (for j be Nat st 1<j & j <= s.SBP+1 holds
  s.intpos j=Comput(P,s,n).intpos j);
  now
    let s be State of SCMPDS;
    set x=s.DataLoc(s.SBP,2), y=s.DataLoc(s.SBP,3);
    assume
A1: GA c= P;
    assume
A2: IC s =  5;
    assume s.SBP >0;
    assume s.GBP=0;
    assume
A3: y <= 0;
    assume
A4: y >= 0;
    assume
A5: x >= y;
A6:  P/.IC s = P.IC s by PBOOLE:143;
A7:  P/.IC Comput(P,s,1) = P.IC Comput(P,s,1) by PBOOLE:143;
A8: Comput(P,s,1+0) = Following(P,Comput(P,s,0)) by EXTPRO_1:3
      .= Following(P,s) by EXTPRO_1:2
      .= Exec(i05,s) by A2,A6,Lm1,A1;
    then
A9: IC Comput(P,s,1)= ICplusConst(s,9) by A3,SCMPDS_2:56
      .=  (5+9) by A2,SCMPDS_6:12;
     reconsider n=1 as Nat;
    take n;
    thus CurInstr(P,Comput(P,s,n))=P. 14 by A9,A7
      .=i14 by Lm1,A1;
    thus Comput(P,s,n).SBP=s.SBP by A8,SCMPDS_2:56;
A10: y = 0 by A3,A4;
    then
A11: |.y.|= 0 by ABSVALUE:def 1;
    thus Comput(P,s,n).DataLoc(s.SBP,2)=x by A8,SCMPDS_2:56
      .=|.x.| by A5,A10,ABSVALUE:def 1
      .=|.x.| gcd |.y.| by A11,NEWTON:52
      .=x gcd y by INT_2:34;
    thus for j be Nat st 1<j & j <= s.SBP+1 holds
    s.intpos j=Comput(P,s,n).intpos j by A8,SCMPDS_2:56;
  end;
  then
A12: P[0];
A13: now
    let k be Nat;
    assume
A14: P[k];
    now
      let s be State of SCMPDS;
      set x=s.DataLoc(s.SBP,2), y=s.DataLoc(s.SBP,3), yy=y;
      assume
A15:  GA c= P;
      assume
A16:  IC s =  5;
      assume
A17:  s.SBP >0;
      assume
A18:  s.GBP=0;
      assume
A19:  y <= k+1;
      assume
A20:  y >= 0;
      assume
A21:  x >= y;
      then
A22:  x >= 0 by A20;
      reconsider y as Element of NAT by A20,INT_1:3;
      per cases by A19,NAT_1:8;
      suppose y <= k;
        hence ex n st CurInstr(P,Comput(P,s,n))
         = return SBP &
        s.SBP=Comput(P,s,n).SBP &
        Comput(P,s,n).DataLoc(s.SBP,2)= x gcd yy &
        for j be Nat st 1<j & j <= s.SBP+1 holds
        s.intpos j=Comput(P,s,n).intpos j by A14,A16,A17,A18,A21,A15;
      end;
      suppose
A23:    y = k+1;
        then
A24:    y>0;
        reconsider pn=s.SBP as Element of NAT by A17,INT_1:3;
A25:    pn=s.SBP;
        then
A26:    IC Comput(P,s,7) = 5+7 by A16,A18,A24,Lm4,A15;
A27:    Comput(P,s,8) = Exec(i12,Comput(P,s,7)) by A16,A18,A24,A25,Lm4,A15;
A28:    Comput(P,s,7).SBP= pn+4 by A16,A18,A24,Lm4,A15;
A29:    Comput(P,s,7).GBP=0 by A16,A18,A24,A25,Lm4,A15;
A30:    Comput(P,s,7).intpos(pn+7) = x mod y by A16,A18,A24,Lm4,A15;
A31:    Comput(P,s,7).intpos(pn+6) = y by A16,A18,A24,Lm4,A15;
A32:    Comput(P,s,7).intpos(pn+4) = pn by A16,A18,A24,Lm4,A15;
A33:    Comput(P,s,7).intpos(pn+5) =  11 by A16,A18,A24,Lm4,A15;
        set s8=Comput(P,s,8), P8 = P;
A34:    IC s8= ICplusConst(Comput(P,s,7),-7) by A27,SCMPDS_2:54
          .=  5 by A26,Th2;
A35:    GA c= P8 by A15;
A36:    s8.SBP=pn+4 by A27,A28,SCMPDS_2:54;
A37:    4<=pn+4 by NAT_1:11;
A38:    s8.SBP > 0 by A36;
A39:    s8.GBP=0 by A27,A29,SCMPDS_2:54;
        set x1=s8.DataLoc(s8.SBP,2), y1=s8.DataLoc(s8.SBP,3);
A40:    x1=s8.intpos(pn+4+2) by A36,Th1
          .=y by A27,A31,SCMPDS_2:54;
A41:    y1=s8.intpos(pn+4+3) by A36,Th1
          .=x mod y by A27,A30,SCMPDS_2:54;
        then
A42:    y1<y by A23,NEWTON:65;
        then y1 <= k by A23,INT_1:7;
        then consider m such that
A43:    CurInstr(P,Comput(P,s8,m)) =
return SBP and
A44:    s8.SBP=Comput(P,s8,m).SBP and
A45:    Comput(P,s8,m).DataLoc(s8.SBP,2)= x1 gcd y1 and
A46:    for j be Nat st 1<j & j <= s8.SBP+1 holds s8.intpos j=
        Comput(P,s8,m).intpos j
        by A14,A34,A35,A38,A39,A40,A41,A42,NEWTON:64;
        set s9=Comput(P,s,m+8);
A47:    s8.SBP=s9.SBP by A44,EXTPRO_1:4;
A48: Comput(P,s,m+8)
 = Comput(P,Comput(P,s,8),m) by EXTPRO_1:4;
A49:    Comput(P,s,m+(8+1))=Comput(P,s,m+8+1)
          .= Following(P,s9) by EXTPRO_1:3
          .= Exec(CurInstr(P, s9),s9)
          .= Exec(CurInstr(P,Comput(P,s8,m)),s9) by A48
          .= Exec(return SBP,s9) by A43;
A50:    1 < pn+4 by A37,XXREAL_0:2;
        pn+4 < s8.SBP+1 by A36,XREAL_1:29;
        then
A51:    s8.intpos(pn+4)=Comput(P,s8,m).intpos (pn+4) by A46,A50
          .=s9.intpos(pn+4) by EXTPRO_1:4;
        5<=pn+5 by NAT_1:11;
        then
A52:    1 <pn+5 by XXREAL_0:2;
A53:     11=s8.intpos(pn+5) by A27,A33,SCMPDS_2:54
          .=Comput(P,s8,m).intpos (pn+5) by A36,A46,A52
          .=s9.intpos(pn+4+1) by EXTPRO_1:4
          .=s9.DataLoc(s9.SBP,RetIC) by A36,A47,Th1,SCMPDS_I:def 14;
A54:  P/.IC Comput(P,s,m+9) = P.IC Comput(P,s,m+9) by PBOOLE:143;
A55:    IC Comput(P,s,m+9)= (|.s9.DataLoc(s9.SBP,RetIC).|)+2
        by A49,SCMPDS_2:58
          .=  (11+2) by A53,ABSVALUE:29;
        then
A56:    CurInstr(P,Comput(P,s,m+9)) =P. 13 by A54
          .=i13 by Lm1,A15;
A57:    Comput(P,s,m+(9+1))=Comput(P,s,m+9+1)
          .= Following(P,Comput(P,s,m+9))
          by EXTPRO_1:3
          .= Exec(i13,Comput(P,s,m+9)) by A56;
A58:    Comput(P,s,m+9).SBP=s9.DataLoc(pn+4,RetSP)
        by A36,A47,A49,SCMPDS_2:58
          .=s9.intpos(pn+4+0) by Th1,SCMPDS_I:def 13
          .=pn by A27,A32,A51,SCMPDS_2:54;
A59:    Comput(P,s,m+9).intpos(pn+6)=s9.intpos(pn+4+2) by A49,Lm3,SCMPDS_2:58
          .=s9.DataLoc(s8.SBP,2) by A36,Th1
          .=x1 gcd y1 by A45,EXTPRO_1:4;
A60:  P/.IC Comput(P,s,m+10) = P.IC Comput(P,s,m+10) by PBOOLE:143;
        IC Comput(P,s,m+10)= IC Comput(P,s,m+9) + 1
by A57,SCMPDS_2:47
          .=  (13+1) by A55;
        then
A61:    CurInstr(P,Comput(P,s,m+10))=P. 14 by A60
          .=i14 by Lm1,A15;
        hereby
           reconsider n=m+10 as Nat;
          take n;
          thus CurInstr(P,Comput(
P,s,n)) =
          return SBP by A61;
A62:      DataLoc(Comput(P,s,m+9).SBP,2)=intpos(pn+2) by A58,Th1;
          hence Comput(P,s,n).SBP=s.SBP by A57,A58,Lm3,SCMPDS_2:47;
          thus Comput(P,s,n).DataLoc(s.SBP,2)
          =Comput(P,s,m+9).DataLoc(pn,6) by A57,A58,SCMPDS_2:47
            .=yy gcd (x mod yy) by A40,A41,A59,Th1
            .=x gcd yy by A22,A23,NAT_D:30;
          hereby
            let j be Nat;
            assume that
A63:        1<j and
A64:        j <= s.SBP+1;
            s.SBP <= s8.SBP by A36,NAT_1:11;
            then s.SBP +1 <= s8.SBP+1 by XREAL_1:6;
            then
A65:        j <= s8.SBP+1 by A64,XXREAL_0:2;
A66:        Comput(P,s,m+9).intpos j=s9.intpos j by A49,A63,AMI_3:10
,SCMPDS_2:58
              .=Comput(P,s8,m).intpos j by EXTPRO_1:4
              .=s8.intpos j by A46,A63,A65;
A67:        pn+1<pn+2 by XREAL_1:6;
            Comput(P,s,7).intpos j = s.intpos j
            by A16,A18,A23,A25,A63,A64,Lm5,A15;
            hence s.intpos j=s8.intpos j by A27,SCMPDS_2:54
              .=Comput(P,s,n).intpos j by A57,A62,A64,A66,A67,AMI_3:10
,SCMPDS_2:47;
          end;
        end;
      end;
    end;
    hence P[k+1];
  end;
A68: for n holds P[n] from NAT_1:sch 2(A12,A13);
  let s be State of SCMPDS;
  assume that
A69: GA c= P and
A70: IC s =  5 and
A71: s.SBP >0 and
A72: s.GBP=0 and
A73: s.DataLoc(s.SBP,3) >= 0 and
A74: s.DataLoc(s.SBP,2) >= s.DataLoc(s.SBP,3);
  reconsider m=s.DataLoc(s.SBP,3) as Element of NAT by A73,INT_1:3;
  P[m] by A68;
  hence thesis by A70,A71,A72,A74,A69;
end;
