reserve n for Nat;

theorem
for R being domRing,
    p,q being Polynomial of R
st (ex S being Subset of R
    st card S = max(deg p,deg q) + 1 &
       for a being Element of R st a in S holds eval(p,a) = eval(q,a))
holds p = q
proof
let R be domRing, p,q be Polynomial of R;
assume ex S being Subset of R
       st card S = max(deg p,deg q) + 1 &
          for a being Element of R st a in S holds eval(p,a) = eval(q,a);
then consider S being Subset of R such that
A0: card S = max(deg p,deg q) + 1 &
    for a being Element of R st a in S holds eval(p,a) = eval(q,a);
now assume HH: p <> q;
max(deg p,deg q) + 1 is Element of NAT
  proof
  D: max(deg p,deg q) >= deg p by XXREAL_0:25;
  deg p >= - 1
    proof
    per cases;
    suppose p = 0_.(R); hence thesis by HURWITZ:20; end;
    suppose p <> 0_.(R); hence thesis by T8; end;
    end;
  then max(deg p,deg q) >= -1 by D,XXREAL_0:2;
  then max(deg p,deg q) + 1 >= -1 + 1 by XREAL_1:6;
  hence thesis by INT_1:3;
  end;
then reconsider S as finite Subset of the carrier of R by A0;
per cases;
suppose AS: p is zero;
  then q is non zero by HH; then
  reconsider q as non zero Element of the carrier of Polynom-Ring R
       by POLYNOM3:def 10;
  reconsider n = deg q as Element of NAT by AS,T8;
  deg p = -1 by AS,HURWITZ:20; then
  C0: max(deg p,deg q) + 1 = n + 1 by XXREAL_0:def 10;
  now let x be object;
    assume C: x in S;
    then reconsider a = x as Element of R;
    eval(q,a) = eval(p,a) by A0,C .= 0.R by AS,POLYNOM4:17;
    then a is_a_root_of q by POLYNOM5:def 7;
    hence x in Roots q by POLYNOM5:def 10;
    end;
  then C2: n + 1 <= card(Roots q) by A0,C0,NAT_1:43,TARSKI:def 3;
  card(Roots q) <= deg q by degpoly;
  then C4: n + 1 <= n by C2,XXREAL_0:2;
  n <= n + 1 by NAT_1:11;
  then n + 1 = n by C4,XXREAL_0:1;
  hence contradiction;
  end;
suppose p is non zero;
  then reconsider n = deg p as Element of NAT by T8;
  H2: n = len p - 1 by HURWITZ:def 2;
  then H2a: len p = n + 1;
  per cases by XXREAL_0:1;
  suppose D: len q < len p;
  then len q + 1 <= len p by INT_1:7;
  then len q + 1 - 1 <= len p - 1 by XREAL_1:9;
  then q.n = 0.R by H2,ALGSEQ_1:8;
  then H3: q.n <> p.n by H2a,ALGSEQ_1:10;
  deg q = len q - 1 & deg p = len p - 1 by HURWITZ:def 2; then
  H4: max(deg p,deg q) = n by D,XREAL_1:9,XXREAL_0:def 10;
  defpred P[Nat] means p.($1) <> q.($1);
  A2: for k being Nat st P[k] holds k <= n
      proof
      let k be Nat; assume B0: P[k];
      now let i be Nat; assume i > n;
        then B1: i >= len p by H2a,NAT_1:13;
        hence p.i = 0.R by ALGSEQ_1:8
                 .= q.i by B1,D,XXREAL_0:2,ALGSEQ_1:8;
        end;
      hence thesis by B0;
      end;
  A3: ex k being Nat st P[k] by H3;
  consider m being Nat such that
  A4: P[m] & for i being Nat st P[i] holds i <= m from NAT_1:sch 6(A2,A3);
  A5: p.m <> q.m & m <= n by A2,A4;
  A6: now assume A7: (p - q).m = 0.R;
      p.m + 0.R = p.m + (-q.m + q.m) by RLVECT_1:5
               .= (p.m + -q.m) + q.m by RLVECT_1:def 3
               .= (p.m - q.m) + q.m by RLVECT_1:def 11
               .= 0.R + q.m by A7,NORMSP_1:def 3;
      hence contradiction by A4;
      end;
  then p - q <> 0_.(R) by FUNCOP_1:7,ORDINAL1:def 12;
  then reconsider r = p - q as non zero Polynomial of R by UPROOTS:def 5;
  now let x be object;
    assume C2: x in S;
    then reconsider a = x as Element of R;
    eval(r,a) = eval(p,a) - eval(q,a) by POLYNOM4:21
             .= eval(p,a) - eval(p,a) by C2,A0
             .= 0.R by RLVECT_1:15;
    then a is_a_root_of r by POLYNOM5:def 7;
    hence x in Roots r by POLYNOM5:def 10;
    end;
  then C2: n + 1 <= card Roots r by A0,H4,NAT_1:43,TARSKI:def 3;
  len r = m + 1
    proof
    E1: now let i be Nat;
       assume i >= m+1;
       then not(i <= m) by NAT_1:13;
       then X: p.i = q.i by A4;
       thus r.i = p.i - q.i by NORMSP_1:def 3 .= 0.R by X,RLVECT_1:15;
       end;
    for k be Nat st k is_at_least_length_of r holds m+1 <= k by A6,NAT_1:13;
    hence thesis by E1,ALGSEQ_1:def 2,ALGSEQ_1:def 3;
    end;
  then len r - 1 = m;
  then C3: deg r = m by HURWITZ:def 2;
  card(Roots r) <= deg r by degpoly;
  then n + 1 <= m by C2,C3,XXREAL_0:2;
  then C4: n + 1 <= n by A5,XXREAL_0:2;
  n <= n + 1 by NAT_1:11;
  then n + 1 = n by C4,XXREAL_0:1;
  hence contradiction;
  end;
  suppose D: len p < len q;
  then len p + 1 <= len q by INT_1:7;
  then D1: len p + 1 - 1 <= len q - 1 by XREAL_1:9;
  len p - 1 < len q - 1 by D,XREAL_1:9;
  then deg p < len q - 1 by HURWITZ:def 2;
  then deg p < deg q & 0 <= n by HURWITZ:def 2;
  then reconsider l = deg q as Element of NAT by INT_1:3;
  H2b: l = len q - 1 by HURWITZ:def 2;
  then H2c: len q = l + 1;
  p.l = 0.R by D1,H2b,ALGSEQ_1:8;
  then H3: q.l <> p.l by H2c,ALGSEQ_1:10;
  deg q = len q - 1 & deg p = len p - 1 by HURWITZ:def 2; then
  H4: max(deg p,deg q) = l by D,XREAL_1:9,XXREAL_0:def 10;
  defpred P[Nat] means p.($1) <> q.($1);
  A2: for k being Nat st P[k] holds k <= l
      proof
      let k be Nat; assume B0: P[k];
      now let i be Nat; assume i > l;
        then B1: i >= len q by H2c,NAT_1:13;
        hence q.i = 0.R by ALGSEQ_1:8
                 .= p.i by B1,D,XXREAL_0:2,ALGSEQ_1:8;
        end;
      hence thesis by B0;
      end;
  A3: ex k being Nat st P[k] by H3;
  consider m being Nat such that
  A4: P[m] & for i being Nat st P[i] holds i <= m from NAT_1:sch 6(A2,A3);
  A5: p.m <> q.m & m <= l by A2,A4;
  A6: now assume A7: (p - q).m = 0.R;
      p.m + 0.R = p.m + (-q.m + q.m) by RLVECT_1:5
               .= (p.m + -q.m) + q.m by RLVECT_1:def 3
               .= (p.m - q.m) + q.m by RLVECT_1:def 11
               .= 0.R + q.m by A7,NORMSP_1:def 3;
      hence contradiction by A4;
      end;
  then p - q <> 0_.(R) by FUNCOP_1:7,ORDINAL1:def 12;
  then reconsider r = p - q as non zero Polynomial of R by UPROOTS:def 5;
  now let x be object;
    assume C2: x in S;
    then reconsider a = x as Element of R;
    eval(r,a) = eval(p,a) - eval(q,a) by POLYNOM4:21
             .= eval(p,a) - eval(p,a) by C2,A0
             .= 0.R by RLVECT_1:15;
    then a is_a_root_of r by POLYNOM5:def 7;
    hence x in Roots r by POLYNOM5:def 10;
    end;
  then C2: l + 1 <= card Roots r by A0,H4,NAT_1:43,TARSKI:def 3;
  len r = m + 1
    proof
    E1: now let i be Nat;
       assume i >= m+1; then not(i <= m) by NAT_1:13;
       then X: p.i = q.i by A4;
       thus r.i = p.i - q.i by NORMSP_1:def 3 .= 0.R by X,RLVECT_1:15;
       end;
    for k be Nat st k is_at_least_length_of r holds m+1 <= k by A6,NAT_1:13;
    hence thesis by E1,ALGSEQ_1:def 2,ALGSEQ_1:def 3;
    end;
  then len r - 1 = m;
  then C3: deg r = m by HURWITZ:def 2;
  card(Roots r) <= deg r by degpoly;
  then l + 1 <= m by C2,C3,XXREAL_0:2;
  then C4: l + 1 <= l by A5,XXREAL_0:2;
  l <= l + 1 by NAT_1:11;
  then l + 1 = l by C4,XXREAL_0:1;
  hence contradiction;
  end;
  suppose D: len p = len q;
  n = len p - 1 by HURWITZ:def 2;
  then H2: len p = n + 1;
  H4: deg q = len q - 1 & deg p = len p - 1 by HURWITZ:def 2;
  consider k being Nat such that
  A1: k < len p & p.k <> q.k by HH,D,ALGSEQ_1:12;
  defpred P[Nat] means p.($1) <> q.($1);
  A2: for k being Nat st P[k] holds k <= n
      proof
      let k be Nat; assume B0: P[k];
      now let i be Nat; assume i > n;
        then B1: i >= len p by H2,NAT_1:13;
        hence p.i = 0.R  by ALGSEQ_1:8 .= q.i by D,B1,ALGSEQ_1:8;
        end;
      hence thesis by B0;
      end;
  A3: ex k being Nat st P[k] by A1;
  consider m being Nat such that
  A4: P[m] & for i being Nat st P[i] holds i <= m from NAT_1:sch 6(A2,A3);
  A5: p.m <> q.m & m <= n by A2,A4;
  A6: now assume A7: (p - q).m = 0.R;
      p.m + 0.R = p.m + (-q.m + q.m) by RLVECT_1:5
               .= (p.m + -q.m) + q.m by RLVECT_1:def 3
               .= (p.m - q.m) + q.m by RLVECT_1:def 11
               .= 0.R + q.m by A7,NORMSP_1:def 3;
      hence contradiction by A4;
      end;
  then p - q <> 0_.(R) by FUNCOP_1:7,ORDINAL1:def 12;
  then reconsider r = p - q as non zero Polynomial of R by UPROOTS:def 5;
  now let x be object;
    assume C2: x in S;
    then reconsider a = x as Element of R;
    eval(r,a) = eval(p,a) - eval(q,a) by POLYNOM4:21
             .= eval(p,a) - eval(p,a) by C2,A0
             .= 0.R by RLVECT_1:15;
    then a is_a_root_of r by POLYNOM5:def 7;
    hence x in Roots r by POLYNOM5:def 10;
    end;
  then C2: n + 1 <= card Roots r by H4,A0,D,NAT_1:43,TARSKI:def 3;
  len r = m + 1
    proof
    E1: now let i be Nat;
       assume i >= m+1;
       then not(i <= m) by NAT_1:13;
       then X: p.i = q.i by A4;
       thus r.i = p.i - q.i by NORMSP_1:def 3 .= 0.R by X,RLVECT_1:15;
       end;
    for k be Nat st k is_at_least_length_of r holds m+1 <= k by A6,NAT_1:13;
    hence thesis by E1,ALGSEQ_1:def 2,ALGSEQ_1:def 3;
    end;
  then len r - 1 = m;
  then C3: deg r = m by HURWITZ:def 2;
  card(Roots r) <= deg r by degpoly;
  then n + 1 <= m by C2,C3,XXREAL_0:2;
  then C4: n + 1 <= n by A5,XXREAL_0:2;
  n <= n + 1 by NAT_1:11;
  then n + 1 = n by C4,XXREAL_0:1;
  hence contradiction;
  end;
  end;
end;
hence thesis;
end;
