
theorem Th4:
  for E being EuclidianRing holds E is gcdDomain
proof
  let E be EuclidianRing;
  set d = the DegreeFunction of E;
  now
    let x,y be Element of E;
    now
      per cases;
      case
A1:     x = 0.E;
        y * 0.E = 0.E;
        then
A2:     y divides 0.E by GCD_1:def 1;
        for zz being Element of E st zz divides x & zz divides y holds zz
        divides y;
        hence ex z being Element of E st z divides x & z divides y & for zz
being Element of E st zz divides x & zz divides y holds zz divides z by A1,A2;
      end;
      case
A3:     x <> 0.E;
        set M = { z where z is Element of E: ex s,t being Element of E st z =
        s * x + t * y};
        defpred P[Nat] means ex z being Element of E st (z in M & z <> 0.E &
        $1 = d.z);
        1.E * x + 0.E * y = 1.E * x by RLVECT_1:def 4
          .= x;
        then
A4:     x in M;
        ex k being Element of NAT st k = d.x;
        then
A5:     ex k being Nat st P[k] by A3,A4;
        ex k being Nat st P[k] & for n being Nat st P[n] holds k <= n
        from NAT_1:sch 5(A5);
        then consider k being Nat such that
A6:     ( P[k])& for n being Nat st P[n] holds k <= n;
        consider g being Element of E such that
A7:     g in M and
A8:     g <> 0.E and
A9:     k = d.g & for n being Nat st (ex z being Element of E st z in
        M & z <> 0.E & n = d.z) holds k <= n by A6;
        set G = { z where z is Element of E: ex r being Element of E st z = r
        * g};
A10:    for z being object holds z in M implies z in G
        proof
          let z be object;
          assume z in M;
          then consider z2 being Element of E such that
A11:      z = z2 and
A12:      ex s,t being Element of E st z2 = s * x + t * y;
          consider u,v being Element of E such that
A13:      z2 = u * x + v * y by A12;
          reconsider z as Element of E by A11;
          consider q,r being Element of E such that
A14:      z = q * g + r and
A15:      r = 0.E or d.r < d.g by A8,Def9;
          r in M
          proof
            consider z1 being Element of E such that
A16:        g = z1 and
A17:        ex s,t being Element of E st z1 = s * x + t * y by A7;
            consider s,t being Element of E such that
A18:        z1 = s * x + t * y by A17;
            z + (-(q * g)) = r + ((q * g) + (-(q * g))) by A14,RLVECT_1:def 3
              .= r + 0.E by RLVECT_1:def 10
              .= r by RLVECT_1:def 4;
            then r = z + (-(q * (s * x) + q * (t * y))) by A16,A18,
VECTSP_1:def 7
              .= z + ((-(q * (s * x))) + (-(q * (t * y)))) by RLVECT_1:31
              .= ((u * x + v * y) + (-(q * (s * x)))) + (-(q * (t * y))) by A11
,A13,RLVECT_1:def 3
              .= ((u * x + (-(q * (s * x)))) + v * y) + (-(q * (t * y))) by
RLVECT_1:def 3
              .= (u * x + (-(q * (s * x)))) + (v * y + (-(q * (t * y)))) by
RLVECT_1:def 3
              .= (u * x + ((-q) * (s * x))) + (v * y + (-(q * (t * y)))) by
GCD_1:48
              .= (u * x + ((-q) * (s * x))) + (v * y + ((-q) * (t * y))) by
GCD_1:48
              .= (u * x + ((-q) * s) * x) + (v * y + ((-q) * (t * y))) by
GROUP_1:def 3
              .= (u * x + ((-q) * s) * x) + (v * y + ((-q) * t) * y) by
GROUP_1:def 3
              .= (u + ((-q) * s)) * x + (v * y + ((-q) * t) * y) by
VECTSP_1:def 7
              .= (u + ((-q) * s)) * x + (v + ((-q) * t)) * y by VECTSP_1:def 7;
            hence thesis;
          end;
          then r = 0.E by A9,A15;
          then z = q * g by A14,RLVECT_1:def 4;
          hence thesis;
        end;
A19:    for z being Element of E holds z divides x & z divides y implies
        z divides g
        proof
          let z be Element of E;
          assume that
A20:      z divides x and
A21:      z divides y;
          consider u being Element of E such that
A22:      x = z * u by A20,GCD_1:def 1;
          consider zz being Element of E such that
A23:      g = zz and
A24:      ex s,t being Element of E st zz = s * x + t * y by A7;
          consider s,t being Element of E such that
A25:      zz = s * x + t * y by A24;
          consider v being Element of E such that
A26:      y = z * v by A21,GCD_1:def 1;
          g = (s * u) * z + t * (v * z) by A22,A26,A23,A25,GROUP_1:def 3
            .= (s * u) * z + (t * v) * z by GROUP_1:def 3
            .= (s * u + t * v) * z by VECTSP_1:def 7;
          hence thesis by GCD_1:def 1;
        end;
        0.E * x + 1.E * y = 1.E * y by RLVECT_1:4
          .= y;
        then
A27:    y in M;
        for z being object holds z in G implies z in M
        proof
          let z be object;
          assume z in G;
          then consider z2 being Element of E such that
A28:      z = z2 and
A29:      ex s being Element of E st z2 = s * g;
          reconsider z as Element of E by A28;
          consider u being Element of E such that
A30:      z2 = u * g by A29;
          consider z1 being Element of E such that
A31:      g = z1 and
A32:      ex s,t being Element of E st z1 = s * x + t * y by A7;
          consider s,t being Element of E such that
A33:      z1 = s * x + t * y by A32;
          z = u * (s * x) + u * (t * y) by A28,A30,A31,A33,VECTSP_1:def 2
            .= (u * s) * x + u * (t * y) by GROUP_1:def 3
            .= (u * s) * x + (u * t) * y by GROUP_1:def 3;
          hence thesis;
        end;
        then
A34:    M = G by A10,TARSKI:2;
        g divides x & g divides y
        proof
          (ex zz being Element of E st x = zz & ex r being Element of E
st zz = r * g )& ex zzz being Element of E st y = zzz & ex r being Element of E
          st zzz = r * g by A4,A27,A34;
          hence thesis by GCD_1:def 1;
        end;
        hence ex z being Element of E st z divides x & z divides y & for zz
being Element of E st zz divides x & zz divides y holds zz divides z by A19;
      end;
    end;
    hence ex z being Element of E st z divides x & z divides y & for zz being
    Element of E st zz divides x & zz divides y holds zz divides z;
  end;
  hence thesis by GCD_1:def 11;
end;
