reserve a,b,p,k,l,m,n,s,h,i,j,t,i1,i2 for natural Number;

theorem
  for a,b being Integer ex s,t being Integer st a gcd b = s * a + t * b
proof
  let a,b be Integer;
A1: for a,b being Integer st a > 0 & b > 0 holds ex s,t being Integer st (a
  gcd b) = (s * a + t * b)
  proof
    let a,b be Integer;
    assume that
A2: a > 0 and
A3: b > 0;
    reconsider a,b as Element of NAT by A2,A3,INT_1:3;
    set M = {z where z is Element of NAT : ex s,t being Integer st z = s * a +
    t * b};
    defpred P[Nat] means ($1 in M & $1 <> 0);
    a = 1 * a + 0 * b;
    then
A4: a in M;
    then
A5: ex k being Nat st P[k] by A2;
    consider g being Nat such that
A6: P[g] & for n being Nat st P[n] holds g <= n from NAT_1:sch 5(A5);
    set G = {zz where zz is Element of NAT : ex s being Element of NAT st zz =
    s * g};
    ex z being Element of NAT st z = g & ex s,t being Integer st z = s * a
    + t * b by A6;
    then consider s,t being Integer such that
A7: g = s * a + t * b;
A8: for x being object holds x in M implies x in G
    proof
      let x be object;
      assume x in M;
      then consider x9 being Element of NAT such that
A9:   x9 = x and
A10:  ex u,v being Integer st x9 = u * a + v * b;
      consider u,v being Integer such that
A11:  x = u * a + v * b by A9,A10;
      consider r being Nat such that
A12:  x9 = g * (x9 div g) + r and
A13:  r < g by A6,Def1;
A14:  r in NAT by ORDINAL1:def 12;
      r = x9 - g * (x9 div g) by A12
        .= a * (u + -(s * (x9 div g))) + b * (v + -(t * (x9 div g)))
         by A7,A9,A11;
      then r in M by A14;
      then r = 0 by A6,A13;
      hence thesis by A9,A12;
    end;
    for x being object holds x in G implies x in M
    proof
      let x be object;
      assume x in G;
      then
A15:  ex x9 being Element of NAT st x9 = x & ex u being Element of NAT st
      x9 = u * g;
      then consider u being Integer such that
A16:  x = u * g;
      x = (u * s) * a + (u * t) * b by A7,A16;
      hence thesis by A15;
    end;
    then
A17: G = M by A8,TARSKI:2;
A18: |.b.| = b by ABSVALUE:def 1;
A19: |.a.| = a by ABSVALUE:def 1;
A20: for m being Nat st m divides |.a.| & m divides |.b.| holds m divides g
    proof
      ex g9 being Element of NAT st g9 = g & ex s,t being Integer st g9 =
      s * a + t * b by A6;
      then consider s,t being Integer such that
A21:  g = s * a + t * b;
      let m be Nat;
      assume that
A22:  m divides |.a.| and
A23:  m divides |.b.|;
      consider u being Nat such that
A24:  a = m * u by A19,A22;
      consider v being Nat such that
A25:  b = m * v by A18,A23;
A26:  g = m * (s * u + t * v) by A24,A25,A21;
      then s * u + t * v >= 0 by A6;
      then s * u + t * v is Element of NAT by INT_1:3;
      hence thesis by A26;
    end;
    b = 0 * a + 1 * b;
    then b in M;
    then
    ex b9 being Element of NAT st b9 = b & ex t being Element of NAT st b9
    = t * g by A17;
    then
A27: g divides |.b.| by A18;
    ex a9 being Element of NAT st a9 = a & ex s being Element of NAT st a9
    = s * g by A4,A17;
    then g divides |.a.| by A19;
    then g = |.a.| gcd |.b.| by A27,A20,Def5
      .= a gcd b by INT_2:34;
    hence thesis by A7;
  end;
  now
    per cases;
    case
A28:  a = 0 or b = 0;
A29:  for a,b being Integer holds a = 0 implies a gcd b = |.b.|
      proof
        let a,b be Integer;
        assume a = 0;
        then |.a.| = 0 by ABSVALUE:def 1;
        then
A30:    |.b.| divides |.a.| by Th6;
        a gcd b = |.a.| gcd |.b.| & for m being Nat st m divides |.a.|
        & m divides |.b.| holds m divides |.b.| by INT_2:34;
        hence thesis by A30,Def5;
      end;
      now
        per cases by A28;
        case
          a = 0;
          then
A31:      a gcd b = |.b.| by A29;
          now
            per cases;
            case
              b >= 0;
              hence a gcd b = 0 * a + 1 * b by A31,ABSVALUE:def 1;
            end;
            case
              b < 0;
              hence a gcd b = -(b * 1) by A31,ABSVALUE:def 1
                .= 0 * a + (-1) * b;
            end;
          end;
          hence thesis;
        end;
        case
          b = 0;
          then
A32:      a gcd b = |.a.| by A29;
          now
            per cases;
            case
              a >= 0;
              hence a gcd b = 1 * a + 0 * b by A32,ABSVALUE:def 1;
            end;
            case
              a < 0;
              hence a gcd b = -(a * 1) by A32,ABSVALUE:def 1
                .= 0 * b + (-1) * a;
            end;
          end;
          hence thesis;
        end;
      end;
      hence thesis;
    end;
    case
A33:  a <> 0 & b <> 0;
      now
        per cases;
        case
          a >= 0 & b >= 0;
          hence thesis by A1,A33;
        end;
        case
A34:      a < 0 & b >= 0;
          then -a > 0 by XREAL_1:58;
          then consider s,t being Integer such that
A35:      -a gcd b = s * -a + t * b by A1,A33,A34;
A36:      a gcd b = |.a.| gcd |.b.| by INT_2:34
            .= |.-a.| gcd |.b.| by COMPLEX1:52
            .= -a gcd b by INT_2:34;
          s * -a + t * b = (-s) * a + t * b;
          hence thesis by A35,A36;
        end;
        case
A37:      a >= 0 & b < 0;
          then -b > 0 by XREAL_1:58;
          then consider s,t being Integer such that
A38:      a gcd -b = s * a + t * -b by A1,A33,A37;
A39:      a gcd b = |.a.| gcd |.b.| by INT_2:34
            .= |.a.| gcd |.-b.| by COMPLEX1:52
            .= a gcd -b by INT_2:34;
          s * a + t * -b = s * a + (-t) * b;
          hence thesis by A38,A39;
        end;
        case
          a < 0 & b < 0;
          then -a > 0 & -b > 0 by XREAL_1:58;
          then consider s,t being Integer such that
A40:      -a gcd -b = s * -a + t * -b by A1;
A41:      a gcd b = |.a.| gcd |.b.| by INT_2:34
            .= |.a.| gcd |.-b.| by COMPLEX1:52
            .= |.-a.| gcd |.-b.| by COMPLEX1:52
            .= -a gcd -b by INT_2:34;
          s * -a + t * -b = (-s) * a + (-t) * b;
          hence thesis by A40,A41;
        end;
      end;
      hence thesis;
    end;
  end;
  hence thesis;
end;
