reserve i,j,k for Nat;

theorem Th7:
  for s being 0-started State of SCM
  for P being Instruction-Sequence of SCM
   st Euclid-Algorithm c= P
   for x, y being Integer st s.dl.0 = x & s.dl.1 = y & x > 0 & y > 0 holds (
  Result(P,s)).dl.0 = x gcd y
proof
  let s be 0-started State of SCM;
  let P be Instruction-Sequence of SCM such that
A1: Euclid-Algorithm c= P;
  let x, y be Integer such that
A2: s.a = x & s.b = y and
A3: x > 0 and
A4: y > 0;
A5: |.y.| = y by A4,ABSVALUE:def 1;
  now
    per cases by XXREAL_0:1;
    case
      x > y;
      hence thesis by A1,A2,A4,Lm6;
    end;
    case
A6:   x = y;
      reconsider x9 = x, y9 = y as Element of NAT by A3,A4,INT_1:3;
      take s9 = Comput(P,s,4);
A7:   s = Comput(P,s,4*0) by EXTPRO_1:2;
A8:   s9 = Comput(P,s,4*(0+1));
      x mod y = x9 mod y9
        .= 0 by A6,NAT_D:25;
      then s9.b = 0 by A1,A2,A3,A4,A7,A8,Lm5;
      then IC s9 = 4 by A1,A2,A3,A4,A8,Lm4;
      then P halts_at IC s9 by A1,Lm3;
      hence (Result(P,s)).a = s9.a by EXTPRO_1:18
        .= y by A1,A2,A3,A4,A7,A8,Lm5
        .= x gcd y by A5,A6,NAT_D:32;
    end;
    case
A9:  y > x;
      reconsider x9 = x, y9 = y as Element of NAT by A3,A4,INT_1:3;
      take s9 = Comput(P,s,4);
A10:  s9 = Comput(P,s,4*(0+1));
A11:  s = Comput(P,s,4*0) by EXTPRO_1:2;
      then
A12:  s9.a = y by A1,A2,A3,A4,A10,Lm5;
      x mod y = x9 mod y9
        .= x9 by A9,NAT_D:24;
      then
A13:  s9.b = x by A1,A2,A3,A4,A11,A10,Lm5;
      then IC s9 = 0 by A1,A2,A3,A4,A10,Lm4;
      then
A14:  s9 is 0-started;
      then consider k0 being Nat such that
A15:  P halts_at IC Comput(P,s9,k0)
        by A3,A9,A12,A13,A1,Lm6;
A16:  P halts_at IC Comput(P,s,k0+4) by A15,EXTPRO_1:4;
      (Result(P,s9)).a = x gcd y by A3,A9,A12,A13,A14,A1,Lm6;
      hence thesis by A16,EXTPRO_1:21;
    end;
  end;
  hence thesis;
end;
