reserve A for non trivial Nat,
        B,C,n,m,k for Nat,
        e for Nat;
reserve a for non trivial Nat;

theorem Th17:
  for A be non trivial Nat for C,B be Nat, e st 0 < B holds
    C = Py(A,B) implies
  ex i,j be Nat, D,E,F,G,H,I be Nat st
    D*F*I is square &
    F divides (H - C) &
    B <= C &

  D = (A^2-1)*C^2+1 & E = 2*(i+1)*D*(e+1)*C^2 & F= (A^2 -1) *E^2+1 &
  G = A+F*(F-A) & H = B+2*j*C & I = (G^2-1)*H^2+1
proof
  let A be non trivial Nat;
  let C,B be Nat,e such that
A1: B>0 and
A2: C= Py(A,B);
  set x = Px(A,B),D=x^2;
  Px(A,0) = 1 & Py(A,0) = 0 by HILB10_1:3;
  then
A3: Px(A,0+1) = 1*A + 0*(A^2-'1) & Py(A,0+1) = 1 + 0*A by HILB10_1:6;
A4: x*x <>0;
A5: D>0 by A4,SQUARE_1:def 1;
  ex q,i be Nat st 2*D*(e+1)*C^2 *(i+1) = Py(A,q)
  proof
    set t = e+1;
A6: 2^2=2*2 & D^2=D*D & t^2=t*t&C^2^2=C^2*C^2&C^2=C*C by SQUARE_1:def 1;
    then reconsider dd=(A^2-'1) * (2^2)*(D^2) *(t^2) *(C^2^2)
      as non square Nat by A5,A1,A2;
    consider x,y be Nat such that
A7: x^2 -dd *y^2 =1 & y <>0 by PELLS_EQ:14;
    reconsider i=y-1 as Nat by A7;
A8: (2^2)*(D^2)*(t^2)*(C^2^2) *(y^2) = (2*2)*(D*D)*(t*t)*(C^2*C^2)*(y*y)
      by A6,SQUARE_1:def 1
    .= (2*D*t*C^2*y)*(2*D*t*C^2*y)
    .= (2*D*t*C^2*y)^2 by SQUARE_1:def 1;
    x^2 - (A^2-'1) * (2*D * t *C^2 *y)^2 = 1 by A7,A8;
    then [x,2*D * t *C^2 *y] is Pell's_solution of A^2-'1 by Lm1;
    then consider n such that
A9:   x= Px(A,n) & 2*D * t *C^2 *y = Py(A,n) by HILB10_1:4;
    take n,i;
    thus thesis by A9;
  end;
  then consider q,i be Nat such that
A10:  2*D*(e+1)*C^2*(i+1) = Py(A,q);
  set E=Py(A,q), F = Px(A,q)^2;
  x^2 - (A^2-'1) *C^2 = 1 by A2,HILB10_1:7;
  then
A11:D= (A^2-'1)*C^2+1;
A12: F - (A^2-'1) *(E^2) = 1 by HILB10_1:7;
  then
A13: F = (A^2-'1)*E^2+1;
A14: C^2=C*C by SQUARE_1:def 1;
  q<>0 by A5,A1,A2,A14,HILB10_1:3,A10;
  then q>=1+0 by NAT_1:13;
  then
A15:  A <= Px(A,q) by A3,HILB10_1:10;
  then Px(A,q) > 1 by NEWTON03:def 1,XXREAL_0:2;
  then
A16:  A*1 < Px(A,q)*Px(A,q) = F by A15,XREAL_1:97,SQUARE_1:def 1;
  then
  F-A > 0 by XREAL_1:50;
  then reconsider G=A +F*(F-A) as non trivial Nat by A16;
  set H=Py(G,B), I=Px(G,B)^2;
A17: I - (G^2-'1) *(H^2) = 1 by HILB10_1:7;
  H,B are_congruent_mod (2*C)
  proof
A18: E^2 = E*E by SQUARE_1:def 1;
A19: (A^2 -'1) *E, (A^2 -'1) *E are_congruent_mod 2*C by INT_1:11;
A20: 1,1 are_congruent_mod 2*C by INT_1:11;
A21: A,A are_congruent_mod 2*C by INT_1:11;
    C^2 = C*C by SQUARE_1:def 1;
    then ((i+1)*D*(e+1)*C)*(2*C) = E-0 by A10;
    then E,0 are_congruent_mod 2*C by INT_1:def 5;
    then (A^2 -'1) *E*E,(A^2 -'1) *E*0 are_congruent_mod 2*C by A19,INT_1:18;
    then
A22: (A^2 -'1)*E^2+1,0+1 are_congruent_mod 2*C by A18,A20,INT_1:16;
    then F-A, 1-A are_congruent_mod 2*C by A12,A21,INT_1:17;
    then F*(F-A), 1*(1-A) are_congruent_mod 2*C by A22,A12,INT_1:18;
    then A+ F*(F-A), A+ 1*(1-A) are_congruent_mod 2*C by A21,INT_1:16;
    then ex i4 be Integer st 2*C*i4 = G-1 by INT_1:def 5;
    hence thesis by HILB10_1:24,INT_1:20;
  end;
  then consider j be Integer such that
A23:  H-B = (2*C)*j by INT_1:def 5;
  j*(2*C) >=B-B by A23,HILB10_1:13,XREAL_1:9;
  then j >= 0 by A1,A2;
  then reconsider j as Element of NAT by INT_1:3;
  A*A=A^2 by SQUARE_1:def 1;
  then
A24: A^2>=1+0 by NAT_1:13;
  G*G=G^2 by SQUARE_1:def 1;
  then
A25: G^2>=1+0 by NAT_1:13;
  A +F*(F-A) - A = F*(F-A);
  then
A26: H,C are_congruent_mod F by A2,HILB10_1:26,INT_1:def 5;
  take i,j, D,E,F,G,H,I;
  thus D*F*I is square & F divides (H - C) & B <= C
    by A2,HILB10_1:13,A26,INT_1:def 4;
  I - (G^2-1) *(H^2) = 1 by A17,A25,XREAL_1:233;
  hence thesis by A11,A24,A10,A13,A23,XREAL_1:233;
end;
