reserve a,b,c,k,l,m,n for Nat,
  i,j,x,y for Integer;

theorem Th16:
  for x st a <> 0 holds (a + x*b) gcd b = a gcd b
proof
  let xx be Integer;
  set i = a gcd b;
A1: b = |.b.| by ABSVALUE:def 1;
  assume
A2: a <> 0;
A3: for m be Nat st m divides |.a + xx*b.| & m divides |.b.| holds m
  divides i
  proof
    let mm be Nat;
    assume that
A4: mm divides |.(a + xx*b).| and
A5: mm divides |.b.|;
    consider n being Nat such that
A6: b = mm*n by A1,A5,NAT_D:def 3;
    reconsider mm as Element of NAT by ORDINAL1:def 12;
    now
      per cases;
      suppose
        (a + xx*b) >= 0;
        then |.(a + xx*b).| = (a + xx*b) by ABSVALUE:def 1;
        then consider t being Integer such that
A7:     (a + xx*b) = mm*t by A4,INT_1:def 3;
A8:     a = mm*t - mm*(xx*n) by A6,A7,XCMPLX_1:26
          .= mm*(t - (xx*n));
        then (t - (xx*n)) >= 0 by A2;
        then reconsider tt = (t - (xx*n)) as Element of NAT by INT_1:3;
        a = mm*tt by A8;
        hence mm divides a by NAT_D:def 3;
      end;
      suppose
        (a + xx*b) < 0;
        then |.(a + xx*b).| = -(a + xx*b) by ABSVALUE:def 1;
        then consider t being Integer such that
A9:     -(a + xx*b) = mm*t by A4,INT_1:def 3;
A10:    a = -mm*t - mm*(xx*n) by A6,A9,XCMPLX_1:26
          .= mm*(-t - (xx*n));
        then (-t - (xx*n)) >= 0 by A2;
        then reconsider tt = (-t - (xx*n)) as Element of NAT by INT_1:3;
        a = mm*tt by A10;
        hence mm divides a by NAT_D:def 3;
      end;
    end;
    hence thesis by A1,A5,NEWTON:50;
  end;
  i divides a by NAT_D:def 5;
  then
A11: a = i*(a div i) by NAT_D:3;
A12: i divides b by NAT_D:def 5;
  then
A13: b = i*(b div i) by NAT_D:3;
  i divides |.a + xx*b.|
  proof
    per cases;
    suppose
      a + xx*b < 0;
      then
A14:  |.(a + xx*b).| = -(a + xx*b) by ABSVALUE:def 1;
      -(a + xx*b) = i * (-((a div i) + (xx*(b div i)))) by A11,A13;
      hence thesis by A14,INT_1:def 3;
    end;
    suppose
      (a + xx*b) >= 0;
      then
A15:  |.(a + xx*b).| = a + xx*b by ABSVALUE:def 1;
      a + xx*b = i*((a div i) + (xx*(b div i))) by A11,A13;
      hence thesis by A15,INT_1:def 3;
    end;
  end;
  then |.(a + xx*b).| gcd |.b.| = i by A1,A12,A3,NAT_D:def 5;
  hence thesis by INT_2:34;
end;
