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,c,d,e for Integer;

theorem Th22:
  for a,b,c,i1,i2,i3 holds
    {p: [a*p.i1,b*p.i2] is Pell's_solution of (((c*p.i3)^2) -' 1)}
       is diophantine Subset of n -xtuples_of NAT
proof
  let a,b,c be Integer; let i1,i2,i3;
  set n5=n+5;
  set WW = {p: [a*p.i1,b*p.i2] is Pell's_solution of (((c*p.i3)^2) -' 1)};
  WW c= n -xtuples_of NAT
  proof
    let y be object;
    assume y in WW;
    then ex p st
    y=p & [a*p.i1,b*p.i2] is Pell's_solution of (((c*p.i3)^2) -' 1);
    hence thesis by HILB10_2:def 5;
  end;
  then reconsider WW as Subset of n -xtuples_of NAT;
  per cases;
  suppose n=0;
    then WW is diophantine Subset of n -xtuples_of NAT;
    hence thesis;
  end;
  suppose A1: n<>0;
    n=n+0;then
    reconsider N=n,I1=i1,I2=i2,I3=i3,N1=n+1,N2=n+2,N3=n+3,N4=n+4
    as Element of n+5 by Th2,Th3;
    defpred P[XFinSequence of NAT] means 1* $1.N =  a^2*$1.I1*$1.I1;
    A2: {p where p is (n+5)-element XFinSequence of NAT:P[p]}
    is diophantine Subset of n5 -xtuples_of NAT by Th9;
    defpred Q[XFinSequence of NAT] means 1* $1.N1 =  c^2*$1.I3*$1.I3;
    A3: {p where p is (n+5)-element XFinSequence of NAT:Q[p]}
    is diophantine Subset of n5 -xtuples_of NAT by Th9;
    defpred R[XFinSequence of NAT] means 1* $1.N2 = 1*$1.N1 -'1;
    A4: {p where p is (n+5)-element XFinSequence of NAT:R[p]} is
    diophantine Subset of n5 -xtuples_of NAT by Th20;
    defpred S[XFinSequence of NAT] means 1* $1.N3 = b^2* $1.I2 * $1.I2;
    A5: {p where p is (n+5)-element XFinSequence of NAT:S[p]}
    is diophantine Subset of n5 -xtuples_of NAT by Th9;
    defpred T[XFinSequence of NAT] means 1* $1.N4 = 1*$1.N2 * $1.N3;
    A6: {p where p is (n+5)-element XFinSequence of NAT:T[p]}
    is diophantine Subset of n5 -xtuples_of NAT by Th9;
    defpred U[XFinSequence of NAT] means 1* $1.N = 1*$1.N4 + 1;
    A7: {p where p is (n+5)-element XFinSequence of NAT:U[p]}
    is diophantine Subset of n5 -xtuples_of NAT by Th6;
    defpred PQ[XFinSequence of NAT] means P[$1] & Q[$1];
    defpred PQR[XFinSequence of NAT] means PQ[$1] & R[$1];
    defpred PQRS[XFinSequence of NAT] means PQR[$1] & S[$1];
    defpred PQRST[XFinSequence of NAT] means PQRS[$1] & T[$1];
    defpred PQRSTU[XFinSequence of NAT] means PQRST[$1] & U[$1];
    {p where p is (n+5)-element XFinSequence of NAT : P[p] &  Q[p]}
    is diophantine Subset of n5 -xtuples_of NAT
      from IntersectionDiophantine(A2,A3);
    then A8: {p where p is (n+5)-element XFinSequence of NAT: PQ[p]}
    is diophantine Subset of n5 -xtuples_of NAT;
    {p where p is (n+5)-element XFinSequence of NAT : PQ[p] &  R[p]}
    is diophantine Subset of (n+5) -xtuples_of NAT
      from IntersectionDiophantine(A8,A4);
    then A9: {p where p is (n+5)-element XFinSequence of NAT: PQR[p]}
    is diophantine Subset of n5 -xtuples_of NAT;
    {p where p is (n+5)-element XFinSequence of NAT: PQR[p] & S[p]}
    is diophantine Subset of n5 -xtuples_of NAT
      from IntersectionDiophantine(A9,A5);
    then A10: {p where p is (n+5)-element XFinSequence of NAT: PQRS[p]}
    is diophantine Subset of n5 -xtuples_of NAT;
    {p where p is (n+5)-element XFinSequence of NAT: PQRS[p] & T[p]}
    is diophantine Subset of n5 -xtuples_of NAT
      from IntersectionDiophantine(A10,A6);
    then A11: {p where p is (n+5)-element XFinSequence of NAT : PQRST[p]}
    is diophantine Subset of n5 -xtuples_of NAT;
    A12: {p where p is (n+5)-element XFinSequence of NAT: PQRST[p] & U[p]}
    is diophantine Subset of n5 -xtuples_of NAT
      from IntersectionDiophantine(A11,A7);
    set DD = {p where p is (n+5)-element XFinSequence of NAT:PQRSTU[p]};
    set DDR = {p|n where p is (n+5)-element XFinSequence of NAT:p in DD};
    A13: DDR is diophantine Subset of n -xtuples_of NAT by NAT_1:11,Th5,A12;
    A14: DDR  c= WW
    proof
      let x be object such that A15: x in DDR;
      consider p be (n+5)-element XFinSequence of NAT such that
      A16: x=p|n & p in DD by A15;
      consider q be (n+5)-element XFinSequence of NAT such that
      A17: p=q & PQRSTU[q] by A16;
      len p = n+5 & n+5 >=n by CARD_1:def 7,NAT_1:11;
      then len (p|n)=n by AFINSQ_1:54;
      then reconsider pn = p|n as n-element XFinSequence of NAT
      by CARD_1:def 7;
      A18:b^2* p.I2 * p.I2 = b^2 * (p.I2 * p.I2) = b^2 * (p.I2)^2 = (b*p.I2)^2
      by SQUARE_1:def 1, SQUARE_1:9;
      A19:a^2* p.I1 * p.I1 = a^2 * (p.I1 * p.I1) = a^2 * (p.I1)^2 = (a*p.I1)^2
      by SQUARE_1:def 1, SQUARE_1:9;
      A20:c^2* p.I3 * p.I3 = c^2 * (p.I3 * p.I3) = c^2 * (p.I3)^2 = (c*p.I3)^2
      by SQUARE_1:def 1, SQUARE_1:9;
      A21:   (p|n).I3 = p.i3 & (p|n).I2 = p.i2 & (p|n).I1 = p.i1  by A1,Th4;
      (a*pn.i1)^2 = ((((c*pn.i3)^2) -'1) * ((b*pn.i2)^2)) + 1
      by A17,A18,A19,A20,A21;
      then
      (a*pn.i1)^2 - (((c*pn.i3)^2) -' 1) * ((b*pn.i2)^2 )= 1;
      then [a*pn.i1,b*pn.i2] is Pell's_solution of (((c*pn.i3)^2) -' 1) by Lm1;
      hence thesis by A16;
    end;
    WW c= DDR
    proof
      let x be object such that A22: x in WW;
      consider p be n-element XFinSequence of NAT such that
      A23: x=p & [a*p.i1,b*p.i2] is Pell's_solution of (((c*p.i3)^2) -' 1)
      by A22;
      A24: (a*p.i1)^2 = a^2 * (p.i1)^2 = a^2 * (p.i1*p.i1) = a^2 * p.i1*p.i1
      by SQUARE_1:def 1, SQUARE_1:9;
      A25: (b*p.i2)^2 = b^2 * (p.i2)^2 = b^2 * (p.i2*p.i2) = b^2*p.i2*p.i2
      by SQUARE_1:def 1, SQUARE_1:9;
      A26: (c*p.i3)^2 = c^2 * (p.i3)^2 = c^2 * (p.i3*p.i3) = c^2*p.i3*p.i3
      by SQUARE_1:def 1, SQUARE_1:9;
      set y1 = a^2*p.i1*p.i1;
      set y2 = (c^2)*p.i3*p.i3;
      set y3 = 1*y2-'1;
      set y4 = b^2* p.i2 * p.i2;
      set y5 = 1*y3*y4;
      reconsider y1,y2,y3,y4,y5 as Element of NAT by ORDINAL1:def 12;
      set Y=<%y1%>^<%y2%>^<%y3%>^<%y4%>^<%y5%>;
      set PY = p^Y;
      A27: len p = n & len Y = 5 by CARD_1:def 7;
      A28: PY|n =p by A27,AFINSQ_1:57;
      A29: PY.i1= p.i1 by A28,A1,Th4;
      A30: PY.i2 = (PY|n).i2 by A1,Th4
      .= p.i2 by A27,AFINSQ_1:57;
      A31: PY.i3 = (PY|n).i3 by A1,Th4
      .= p.i3 by A27,AFINSQ_1:57;
      0 in dom Y by A27,AFINSQ_1:66;
      then A32:PY.(n+0) = Y.0 by A27,AFINSQ_1:def 3
      .= y1 by AFINSQ_1:46;
      1 in dom Y by A27,AFINSQ_1:66;
      then A33:PY.(n+1) = Y.1 by A27,AFINSQ_1:def 3
      .= y2 by AFINSQ_1:46;
      2 in dom Y by A27,AFINSQ_1:66;
      then A34: PY.(n+2) = Y.2 by A27,AFINSQ_1:def 3
      .= y3 by AFINSQ_1:46;
      3 in dom Y by A27,AFINSQ_1:66;
      then A35: PY.(n+3) = Y.3 by A27,AFINSQ_1:def 3
      .= y4 by AFINSQ_1:46;
      4 in dom Y by A27,AFINSQ_1:66;
      then A36:PY.(n+4) = Y.4 by A27,AFINSQ_1:def 3
      .= y5 by AFINSQ_1:46;
      y1 - y5=1 by A23,Lm1,A24,A25,A26;
      then
      y1 = y5+1;
      then PQRSTU[PY] by A32,A31,A33,A29,A34,A35,A30,A36;
      then PY in DD;
      hence thesis by A23,A28;
    end;
    hence thesis by A13,A14,XBOOLE_0:def 10;
  end;
end;
