reserve i,j,n,n1,n2,m,k,l,u for Nat,
        i1,i2,i3,i4,i5,i6 for Element of n,
        p,q for n-element XFinSequence of NAT,
        a,b,c,d,e,f for Integer;

theorem Th15:
  for P being INT -valued Polynomial of k+1,F_Real,n,i1,i2 st
    k+1 <= n & k in i1
  holds
    {p: for q be k+1-element XFinSequence of NAT st q = <%p.i1%>^(p|k) holds
         eval(P,@q),0 are_congruent_mod p.i2}
     is diophantine Subset of n -xtuples_of NAT
proof
  set k1=k+1;
  let P be INT -valued Polynomial of k1,F_Real,n,i1,i2 such that
A1: k+1 <= n & k in i1;
  reconsider FR=F_Real as Field;
  set X=n+1;
A2: n < X & k < n by A1,NAT_1:13;
  then n in Segm X by NAT_1:44;
  then reconsider N=n,I1=i1,I2=i2 as Element of X by HILB10_3:2;
  defpred P[XFinSequence of NAT] means
    1 * $1.N,0*$1.I1 are_congruent_mod 1*$1.I2;
A3: {p where p is X-element XFinSequence of NAT:P[p]}
    is diophantine Subset of X -xtuples_of NAT by HILB10_3:21;
  defpred QP[XFinSequence of NAT] means
    for q be k1-element XFinSequence of NAT st q = <%$1.I1%>^($1|k) holds
      1 * $1.N = eval(P,@q);
  defpred QM[XFinSequence of NAT] means
    for q be k1-element XFinSequence of NAT st q = <%$1.I1%>^($1|k) holds
      (-1) * $1.N = eval(P,@q);
  defpred Q[XFinSequence of NAT] means QP[$1] or QM[$1];
A4: k1 < X & k in I1 by A1,NAT_1:13;
  then
A5: {p where p is X-element XFinSequence of NAT:QP[p]}
    is diophantine Subset of X -xtuples_of NAT by Th14;
A6: {p where p is X-element XFinSequence of NAT:QM[p]}
    is diophantine Subset of X -xtuples_of NAT by Th14,A4;
  {p where p is X-element XFinSequence of NAT:QP[p]or QM[p]}
    is diophantine Subset of X -xtuples_of NAT from HILB10_3:sch 1(A5,A6);
  then
A7: {p where p is X-element XFinSequence of NAT:Q[p]}
    is diophantine Subset of X -xtuples_of NAT;
  set PQ = {p where p is X-element XFinSequence of NAT:P[p]&Q[p]};
A8: PQ is diophantine Subset of X -xtuples_of NAT from HILB10_3:sch 3(A3,A7);
  set PQr = {p|n where  p is X-element XFinSequence of NAT: p in PQ};
  defpred S[XFinSequence of NAT] means
    for q be k1-element XFinSequence of NAT st q = <%$1.i1%>^($1|k) holds
      eval(P,@q),0 are_congruent_mod $1.i2;
  set S={p: S[p]};
A9: PQr is diophantine Subset of n -xtuples_of NAT by HILB10_3:5,A2,A8;
A10:Segm k c= Segm n by A2,NAT_1:39;
A11: S c= PQr
  proof
    let y be object;
    assume y in S;
    then consider p such that
A12:  y=p & S[p];
A13:  len p=n & len <%p.i1%>=1 by CARD_1:def 7;
    then len (p|k) = k by A2,AFINSQ_1:54;
    then len (<%p.i1%>^(p|k))=k1 by A13,AFINSQ_1:17;
    then reconsider pi1pk=<%p.i1%>^(p|k) as k1-element XFinSequence of NAT
      by CARD_1:def 7;
    reconsider E=|.eval(P,@pi1pk).| as Element of NAT;
    reconsider pE = p^<%E%> as X-element XFinSequence of NAT;
A14:  pE|n = p by A13,AFINSQ_1:57;
A15:  pE.N = E by A13,AFINSQ_1:36;
A16:  pE.I1 = p.i1 & pE.I2 = p.i2 by A1,A14,HILB10_3:4;
A17:  pE|k = p|k by A10,A14,RELAT_1:74;
A18: now per cases by ABSVALUE:1;
      suppose E=eval(P,@pi1pk);
        hence QP[pE] or QM[pE] by A13,AFINSQ_1:36,A17,A16;
      end;
      suppose E=-eval(P,@pi1pk);
        hence QP[pE] or QM[pE] by A15,A10,A14,RELAT_1:74,A16;
      end;
    end;
    eval(P,@pi1pk),0 are_congruent_mod pE.i2 by A12,A16;
    then
A19:  pE.i2 divides -(eval(P,@pi1pk)-0) by INT_2:10,15;
    1 * pE.N,0*pE.I1 are_congruent_mod 1*pE.I2
    proof
      per cases by ABSVALUE:1;
      suppose E=eval(P,@pi1pk);
        hence thesis by A12,A16,A15;
      end;
      suppose E=-eval(P,@pi1pk);
        then pE.i2 divides (E - -0) by A19;
        hence thesis by A15,INT_2:15;
      end;
    end;
    then pE in PQ by A18;
    hence thesis by A12,A14;
  end;
  PQr c= S
  proof
    let y be object;
    assume y in PQr;
    then consider pP be X-element XFinSequence of NAT such that
A20:  y=pP|n & pP in PQ;
A21:  ex q be X-element XFinSequence of NAT st q=pP & P[q]&Q[q] by A20;
    len pP=X by CARD_1:def 7;
    then
A22:  len (pP|n) = n by A2,AFINSQ_1:54;
    then reconsider p=pP|n as n-element XFinSequence of NAT by CARD_1:def 7;
A23:  len <%p.i1%> = 1 by CARD_1:def 7;
    len (p|k) = k by A2,A22, AFINSQ_1:54;
    then len (<%p.i1%>^(p|k))=k1 by A23,AFINSQ_1:17;
    then reconsider pi1pk=<%p.i1%>^(p|k) as k1-element  XFinSequence of NAT
      by CARD_1:def 7;
A24: pP.I1 = p.i1 & pP.I2 = p.i2 by A1,HILB10_3:4;
A25: pP.I2 divides (pP.N -0) by A21,INT_2:15;
    eval(P,@pi1pk),0 are_congruent_mod p.i2
    proof
      pi1pk = <%pP.i1%>^(pP|k) by A24,A10,RELAT_1:74;
      then 1 * pP.N = eval(P,@pi1pk) or (- 1) * pP.N = eval(P,@pi1pk) by A21;
      then per cases;
        suppose pP.N = eval(P,@pi1pk);
          hence thesis by A21,A1,HILB10_3:4;
        end;
        suppose
A26:        pP.N = - eval(P,@pi1pk);
          p.i2 divides (-(pP.N) -0) by A25,INT_2:10,A24;
          hence thesis by A26,INT_2:15;
        end;
    end;
    then S[p];
    hence thesis by A20;
  end;
  hence thesis by A9,A11,XBOOLE_0:def 10;
end;
