reserve i,j,n,n1,n2,m,k,l,u for Nat,
        r,r1,r2 for Real,
        x,y for Integer,
        a,b for non trivial Nat,
        F for XFinSequence,
        cF,cF1,cF2 for complex-valued XFinSequence,
        c,c1,c2 for Complex;
reserve x,y,x1,u,w for Nat;
reserve n,m,k for Nat,
        p,q for n-element XFinSequence of NAT,
        i1,i2,i3,i4,i5,i6 for Element of n,
        a,b,d,f for Integer;

theorem
  for A being diophantine Subset of n -xtuples_of NAT
    for k,nk being Nat st k+nk = n holds
       {p/^nk : p in A} is diophantine Subset of k -xtuples_of NAT
proof
  let A be diophantine Subset of n -xtuples_of NAT;
  let k,nk be Nat such that A1: k+nk=n;
  consider nA be Nat, pA be INT -valued Polynomial of n+nA,F_Real such that
A2: for s be object holds
      s in A iff ex x be n-element XFinSequence of NAT,
                   y be nA-element XFinSequence of NAT st
                 s=x & eval(pA,@(x^y)) = 0 by HILB10_2:def 6;
  dom (id (n+nA))=n+nA;
  then reconsider I=id (n+nA) as XFinSequence by AFINSQ_1:5;
  set I1 = I|nk, I2= (I|n)/^nk,I3 = I/^n;
  Segm nk c= Segm n by NAT_1:39,NAT_1:11,A1;
  then
A3: (I|n)|nk = I1 by RELAT_1:74;
  then
A4: I = (I|n)^I3 & I|n = I1^I2;
  then
A5: rng (I|n) misses rng I3 by HILB10_2:1;
A6: len I = n+nA;
A7: n <= n+nA by NAT_1:11;
A8: len I3 = n+nA-'n =n+nA-n & len (I|n) = n
    by A6,AFINSQ_2:def 2,AFINSQ_1:54,NAT_1:11;
A9: len I2 = n-'nk =n-nk & len I1 = nk
    by A1,NAT_1:11,A8,AFINSQ_2:def 2,AFINSQ_1:54,A3;
A10: len (I2^I1^I3) = len (I2^I1) + len I3 & len (I2^I1) = len I2 + len I1
    by AFINSQ_1:17;
A11: rng I1 misses rng I2 by A4,HILB10_2:1;
A12: rng (I|n)\/ rng I3 = rng I by A4,AFINSQ_1:26;
A13: rng I1 \/rng I2= rng (I|n) & rng (I2^I1) = rng I2\/ rng I1
    by A4,AFINSQ_1:26;
  then rng (I2^I1^I3)=n+nA by A12,AFINSQ_1:26;
  then reconsider J = I2^I1^I3 as Function of n+nA,n+nA
    by A10,A8,A9,FUNCT_2:1;
A14: J is onto by A13,A12,AFINSQ_1:26;
A15: I2^I1 is one-to-one by A11,CARD_FIN:52;
  J is one-to-one by A13,A5,A15,CARD_FIN:52;
  then reconsider J as Permutation of (n+nA) by A14;
A16:  J=J"" by FUNCT_1:43;
  set h= pA permuted_by J";
  reconsider H=h as Polynomial of k+(nk+nA),F_Real by A1;
  rng h = rng pA c= INT by HILB10_2:26,RELAT_1:def 19;
  then reconsider H as INT -valued
  Polynomial of k+(nk+nA),F_Real by RELAT_1:def 19;
  set Y={p/^nk : p in A};
  Y c= k -xtuples_of NAT
  proof
    let y be object;
    assume y in Y;
    then consider p such that
A17:  y =p/^nk & p in A;
    len p=n by CARD_1:def 7;
    then p/^nk is k-element by A1,A9,AFINSQ_2:def 2;
    hence thesis by A17,HILB10_2:def 5;
  end;
  then reconsider Y as Subset of k -xtuples_of NAT;
  for s be object holds s in Y iff ex x be k-element XFinSequence of NAT,
      y be (nk+nA)-element XFinSequence of NAT st
      s=x & eval(H,@(x^y)) = 0
  proof
    let s be object;
    thus s in Y implies ex x be k-element XFinSequence of NAT,
    y be (nk+nA)-element XFinSequence of NAT st
    s=x & eval(H,@(x^y)) = 0
    proof
      assume s in Y;
      then consider w  be n-element XFinSequence of NAT such that
A18:    s= w/^nk & w in A;
      consider x be n-element XFinSequence of NAT,
               y be nA-element XFinSequence of NAT such that
A19:  w=x & eval(pA,@(x^y)) = 0 by A2,A18;
A20:  eval(pA,@(x^y)) = eval(h,@(x^y)*J"") by HILB10_2:25;
A21:  len x = n & len y = nA by CARD_1:def 7; then
A22:  len (x/^nk) = k by A1,A9,AFINSQ_2:def 2;
      x/^nk is k-element by A21,A1,A9,AFINSQ_2:def 2;
      then reconsider S = x/^nk as k-element XFinSequence of NAT;
A23:  len (x|nk) = nk by CARD_1:def 7,A1;
      reconsider XnkY=(x|nk)^y as (nk+nA)-element XFinSequence of NAT by A1;
A26:  len (S^ XnkY) = n+nA by A1,CARD_1:def 7;
A27:  dom (@(x^y)*J) = n+nA by FUNCT_2:def 1;
      (x|nk)^(x/^nk)=x; then
A28:  x^y = (x|nk)^(S^y) by AFINSQ_1:27;
      for i be object st i in dom (S^ XnkY) holds (@(x^y)*J).i = (S^ XnkY).i
      proof
        let j be object;
        assume
A29:    j in dom (S^ XnkY);
        then reconsider j as Nat;
A30:    j in dom (J) & (@(x^y)*J).j = (@(x^y)).(J.j)
          by A29,A26,A27,FUNCT_1:11,12;
        per cases by A30,AFINSQ_1:20;
        suppose
A31:        j in dom (I2^I1);
          then
A32:        J.j = (I2^I1).j by AFINSQ_1:def 3;
          per cases by A31,AFINSQ_1:20;
          suppose
A33:          j in dom I2;
            then
A34:          (I2^I1).j = I2.j &
            I2.j = (I|n).(nk+j) & j < k
              by A9,A1,AFINSQ_2:def 2,AFINSQ_1:66,def 3;
A35:        nk+j in n by A1,A33,A9,AFINSQ_1:66,HILB10_3:3;
            then
A36:          (I|n).(nk+j) = I.(nk+j) by FUNCT_1:49;
A37:        dom S c= dom (S^y) by AFINSQ_1:21;
A38:        len S = k =len I2 by CARD_1:def 7,A1,A9;
            Segm n =n;
            then nk+j < n+nA by NAT_1:44,A35,A7,XXREAL_0:2;
            then nk+j in Segm (n+nA) by NAT_1:44;
            then
            (@(x^y)*J).j = (@(x^y)).(nk+j) by FUNCT_1:17,A32,A30,A36,A34
              .=(x^y).(nk+j) by HILB10_2:def 1
              .= (S^y).j by A23,A37,A22,A33,A1,A9,A28,AFINSQ_1:def 3
              .= S.j by A22,A33,A1,A9,AFINSQ_1:def 3
              .= (S^ XnkY).j by A33,A38,AFINSQ_1:def 3;
            hence thesis;
          end;
          suppose ex k st k in dom I1 & j=len I2 + k;
            then consider w such that
A39:          w in dom I1 & j=len I2 + w;
A40:        (I2^I1).j = I1.w & I1.w = I.w & w < nk
              by A39,A9,AFINSQ_1:66,def 3,FUNCT_1:49;
A41:        dom (x|nk) c= dom ((x|nk)^y) by AFINSQ_1:21;
            nk <= nk+ (k + nA) by NAT_1:11;
            then w < n+nA by A1,A39,A9,AFINSQ_1:66,XXREAL_0:2;
            then
A42:          w in Segm (n+nA) by NAT_1:44;
            J.j = w by A42,A40,A32,FUNCT_1:17;
            then (@(x^y)*J).j =((x|nk)^(S^y)).w by A30,A28,HILB10_2:def 1
              .= (x|nk).w by AFINSQ_1:def 3,A39,A23,A9
              .= ((x|nk)^y).w by A39,A23,A9,AFINSQ_1:def 3
              .= (S^ XnkY).j by A22,A39,A1,A9,A41,A23,AFINSQ_1:def 3;
            hence thesis;
          end;
        end;
        suppose ex n st n in dom I3 & j=len (I2^I1) + n;
          then consider w such that
A43:        w in dom I3 & j=len (I2^I1) + w;
A44:      len (S^(x|nk))= n by CARD_1:def 7,A1;
          J.j = I3.w by A43,AFINSQ_1:def 3
            .= I.j by A9,A10,A43,AFINSQ_2:def 2
            .= j by A29,A26,FUNCT_1:17;
          then (@(x^y)*J).j =(x^y).j by A30,HILB10_2:def 1
            .= y.w by A9,A10,A43,A8,A21,AFINSQ_1:def 3
            .= ((S^(x|nk))^y).j by A44,A9,A10,A43,A8,A21,AFINSQ_1:def 3
            .= (S^ XnkY).j by AFINSQ_1:27;
          hence thesis;
        end;
      end;
      then @(x^y)*J = (S^ XnkY) by CARD_1:def 7,A1,A27,FUNCT_1:2;
      then @(x^y)*J = @(S^ XnkY) by HILB10_2:def 1;
      hence thesis by A19,A18,A20,A16;
    end;
    given S be k-element XFinSequence of NAT,
          XnkY be (nk+nA)-element XFinSequence of NAT such that
A45:  s=S & eval(H,@(S^XnkY)) = 0;
    set Xnk=XnkY|nk;
    set y=XnkY /^ nk;
    set X = Xnk ^ S;
A46:  len S = k & len XnkY = (nk+nA) & nk+nA >= nk by NAT_1:11,CARD_1:def 7;
    then
A47: len Xnk = nk & len y = nk+nA-'nk = nk+nA-nk
      by AFINSQ_1:54,AFINSQ_2:def 2;
    reconsider y as nA -element XFinSequence of NAT by A47,CARD_1:def 7;
    reconsider X as n-element XFinSequence of NAT by A1;
A48:  X|nk = Xnk by A47,AFINSQ_1:57;
    Xnk ^ S = (X|nk) ^ (X/^nk);
    then
A49:  X/^nk = S by A48,AFINSQ_1:28;
A50:  XnkY = Xnk ^ y;
A51:  len X = n & len y = nA by CARD_1:def 7;
A52: len (X|nk) = nk by A47,AFINSQ_1:57;
A53: len (S^ XnkY) = n+nA by CARD_1:def 7,A1;
A54: dom (@(X^y)*J) = n+nA by FUNCT_2:def 1;
A55: X^y = (X|nk)^(S^y) by A48,AFINSQ_1:27;
    for i be object st i in dom (S^ XnkY) holds (@(X^y)*J).i = (S^ XnkY).i
    proof
      let j be object;
      assume
A56:    j in dom (S^ XnkY);
      then reconsider j as Nat;
A57:  j in dom J & (@(X^y)*J).j = (@(X^y)).(J.j)
        by A56,A53,A54,FUNCT_1:11,12;
      per cases by A57,AFINSQ_1:20;
      suppose
A58:      j in dom (I2^I1);
        then
A59:      J.j = (I2^I1).j by AFINSQ_1:def 3;
        per cases by A58,AFINSQ_1:20;
        suppose
A60:        j in dom I2;
          then
A61:       (I2^I1).j = I2.j & I2.j = (I|n).(nk+j) & j < k
            by A9,A1,AFINSQ_2:def 2,AFINSQ_1:66,def 3; then
A63:      (I|n).(nk+j) = I.(nk+j) by A1,HILB10_3:3,FUNCT_1:49;
A62:      nk+j in n by A60,A1,HILB10_3:3,A9,AFINSQ_1:66;
A64:      dom S c= dom (S^y) by AFINSQ_1:21;
A65:      len S = k =len I2 by CARD_1:def 7,A1,A9;
          Segm n =n;
          then nk+j < n+nA by NAT_1:44,A62,A7,XXREAL_0:2;
          then nk+j in Segm (n+nA) by NAT_1:44;
          then I.(nk+j) = nk+j by FUNCT_1:17;
          then (@(X^y)*J).j
             =((X|nk)^(S^y)).(nk+j) by A55,HILB10_2:def 1,A59,A57,A63,A61
            .= (S^y).j by A52,A64,A60,A1,A46,A9,AFINSQ_1:def 3
            .= S.j by A60,A1,A46,A9,AFINSQ_1:def 3
            .= (S^ XnkY).j by A60,A65,AFINSQ_1:def 3;
          hence thesis;
        end;
        suppose ex k st k in dom I1 & j=len I2 + k;
          then consider w such that
A66:         w in dom I1 & j=len I2 + w;
A67:      (I2^I1).j = I1.w & I1.w = I.w & w < nk
            by A66,A9,AFINSQ_1:66,def 3,FUNCT_1:49;
A68:      dom (X|nk) c= dom ((X|nk)^y) by AFINSQ_1:21;
          nk <= nk+ (k + nA) by NAT_1:11;
          then w < n+nA by A1,A66,A9,AFINSQ_1:66,XXREAL_0:2;
          then
A69:        w in Segm (n+nA) by NAT_1:44;
          J.j = w by A59,A69,FUNCT_1:17,A67;
          then (@(X^y)*J).j =(X^y).w by HILB10_2:def 1,A57
            .=(X|nk).w by AFINSQ_1:def 3,A66,A52,A9,A55
            .= ((X|nk)^y).w by A66,A52,A9,AFINSQ_1:def 3
            .= (S^ XnkY).j by A48,A46,A1,A9,A68,A47,A66,AFINSQ_1:def 3;
          hence thesis;
        end;
      end;
      suppose ex n st n in dom I3 & j=len (I2^I1) + n;
        then consider w such that
A70:      w in dom I3 & j=len (I2^I1) + w;
A71:    len (S^(X|nk)) = n by A1,CARD_1:def 7;
        J.j = I3.w by A70,AFINSQ_1:def 3
          .= I.j by A9,A10,A70,AFINSQ_2:def 2
          .= j by A56,A53,FUNCT_1:17;
        then (@(X^y)*J).j =(X^y).j by HILB10_2:def 1,A57
          .= y.w by A9,A10,A70,A8,A51,AFINSQ_1:def 3
          .= ((S^(X|nk))^y).j by A71,A9,A10,A70,A8,A51,AFINSQ_1:def 3
          .= (S^ XnkY).j by AFINSQ_1:27,A48,A50;
        hence thesis;
      end;
    end;
    then @(X^y)*J = (S^XnkY) by CARD_1:def 7,A1,A54,FUNCT_1:2;
    then @(X^y)*J = @(S^XnkY) by HILB10_2:def 1;
    then eval(H,@(S^XnkY)) = eval(pA,@(X^y)) by A16,HILB10_2:25;
    then X in A by A2,A45;
    hence s in Y by A49,A45;
  end;
  hence thesis by HILB10_2:def 6;
end;
