reserve n for Nat,
        i,j,i1,i2,i3,i4,i5,i6 for Element of n,
        p,q,r for n-element XFinSequence of NAT;
reserve i,j,n,n1,n2,m,k,l,u,e,p,t for Nat,
        a,b for non trivial Nat,
        x,y for Integer,
        r,q for Real;

theorem Th27:
  for a be non trivial Nat for y,n be Nat st 1 <=n holds
    y = Py(a,n) implies
      ex b,c,d,r,s,t,u,v,x be Nat st
        [x,y] is Pell's_solution of a^2-'1 &
        [u,v] is Pell's_solution of a^2-'1 &
        [s,t] is Pell's_solution of b^2-'1 &
        v = 4*r*y^2 &
        b =a +u^2*(u^2-a) &
        s = x+c*u &
        t = n+4*d*y &
        n <= y
  proof
    let a be non trivial Nat;
    let y,n be Nat such that
A1:   n>=1 and
A2:   y= Py(a,n);
    set x = Px(a,n), m = 4*n*y,u = Px(a,m),v=Py(a,m);
A3:   x^2 - (a^2-'1) *y^2 = 1 by A2,HILB10_1:7;
A4:   u^2 - (a^2-'1) *(v^2) = 1 by HILB10_1:7;
A5:   Py(a,n*y), y * (x |^ (y-'1)) *y are_congruent_mod y^2 by A2,HILB10_1:35;
    y^2=y*y by SQUARE_1:def 1;
    then y * (x |^ (y-'1)) *y= y^2*(x |^ (y-'1));
    then y * (x |^ (y-'1)) *y,0 are_congruent_mod y^2 by INT_1:60;
    then y^2 divides Py(a,n*y)-0 by A5,INT_1:15,INT_1:def 4;
    then consider R be Nat such that
A6:   y^2*R = Py(a,n*y) by NAT_D:def 3;
    set r= R * Px(a,n*y) * Px(a,n*y*2);
A7:   Py(a,n*y*2) = 2*Py(a,n*y)*Px(a,n*y) by Th25;
A8: Py(a,n*y*2*2) = 2*Py(a,n*y*2)*Px(a,n*y*2) by Th25;
    Px(a,0) = 1 & Py(a,0) = 0 by HILB10_1:3;
    then
A9:   Px(a,0+1) = 1*a + 0*(a^2-'1) & Py(a,0+1) = 1 + 0*a by HILB10_1:6;
A10:  m>=1+0 by A1,A2,NAT_1:13;
    then
A11:  a <= u by A9,HILB10_1:10;
    then u > 1 by NEWTON03:def 1,XXREAL_0:2;
    then
A12:  a*1 < u*u & u^2=u*u by A11,XREAL_1:97,SQUARE_1:def 1;
    then
A13:  u^2-a > 0 by XREAL_1:50;
    then reconsider b=a +u^2*(u^2-a) as non trivial Nat by A12;
    set s = Px(b,n),t=Py(b,n);
A14: s^2 - (b^2-'1) *(t^2) = 1 by HILB10_1:7;
    b-a = u*(u*(u^2-a)) by A12;
    then s,x are_congruent_mod u by Th16,INT_1:def 5;
    then consider c be Integer such that
    A15:  u*c = s-x by INT_1:def 5;
    b > a+0 by A13,A12,XREAL_1:8;
    then c >=0 by Th15,A15,XREAL_1:48;
    then reconsider c as Element of NAT by INT_1:3;
    consider D be Integer such that
    A16:  (b-1)*D = t-n by INT_1:def 5,HILB10_1:24;
    D>=0 by A16,XREAL_1:48,HILB10_1:13;
    then reconsider D as Element of NAT by INT_1:3;
    set Z=(a^2-'1) *(v^2);
    set d = (r*y *(a^2-'1) *v)*(Z+2-a)*D;
A17: y^2=y*y by SQUARE_1:def 1;
A18: v^2=v*v by SQUARE_1:def 1;
A19: a*a=a^2 by SQUARE_1:def 1;
    then a^2>=1+0 by NAT_1:13;
    then
A20:  a^2-'1 = a^2-1 by XREAL_1:233;
    v >= m by HILB10_1:13;
    then v >=1 & v^2=v*v by A10,XXREAL_0:2,SQUARE_1:def 1;
    then
A21:  v^2 >=1*1 by XREAL_1:66;
    a*a > a*1 by XREAL_1:97,NEWTON03:def 1;
    then a^2 >= a+1 by A19,NAT_1:13;
    then a^2-'1 >= a by A20,XREAL_1:19;
    then Z >= a*1 by A21,XREAL_1:66;
    then Z-a >=0 by XREAL_1:48;
    then Z-a+2 >= 0+0;
    then reconsider d as Element of NAT by INT_1:3;
    take b,c,d,r,s,t,u,v,x;
A22: b = a+ ((a^2-'1) *(v^2)+1) * ((a^2-'1) *(v^2)+1-a) by A4
      .= Z*Z + Z*(2-a) +1;
    t = n+(b-1)*D by A16;
    hence thesis by A17,A18,A3,A4,A14,Lm1,A8,A6,A7,A15,A2,HILB10_1:13,A22;
end;
