reserve n,n1,n2,k,D for Nat,
        r,r1,r2 for Real,
        x,y for Integer;

theorem Th12:
  D is non square implies
  {[x,y] where x, y is Integer:
      y <> 0 & |. x^2 - D * y^2.| < 2 * sqrt D + 1 &
      0 < x - y * sqrt D} is infinite
  proof
    set S = {[x,y] where x, y is Integer:
             y<>0 & |. x^2 - D*y^2.| < 2*(sqrt D)+1 &
             0 < x-y*(sqrt D)};
    assume A1:D is non square & S is finite;
    ex f be Function of S,REAL st
       for x,y be Integer st [x,y] in S holds f. [x,y] = x-y*(sqrt D)
      proof
        defpred P[object,object] means
        for x,y be Integer st [x,y]= $1 holds $2 = x-y*(sqrt D);
        A2: for xy be object st xy in S ex u be object st P[xy,u]
        proof
          let xy be object such that A3: xy in S;
          consider x,y be Integer such that
          A4: xy=[x,y] & y<>0 & |. x^2 - D*y^2.| < 2*(sqrt D)+1 &
          0 < x-y*(sqrt D) by A3;
          take u=x-y*(sqrt D);
          let x1,y1 be Integer such that A5: [x1,y1] = xy;
          x1=x & y1=y by A4,A5,XTUPLE_0:1;
          hence thesis;
        end;
        consider f be Function such that
        A6:  dom f = S & for xy be object st xy in S holds P[xy,f.xy]
        from CLASSES1:sch 1(A2);
        rng f c= REAL
        proof
          let a be object;
          assume a in rng f;
          then consider xy be object such that
          A7:xy in dom f & f.xy = a by FUNCT_1:def 3;
          consider x be Integer, y be Integer such that
          A8:  xy= [x,y] &
          y<>0 & |. x^2 - D*y^2.| < 2*(sqrt D)+1 & 0 < x-y*(sqrt D) by A6,A7;
          f.xy = x-y*(sqrt D) by A6,A7,A8;
          hence a in REAL by A7,XREAL_0:def 1;
        end;
        then reconsider f as Function of S,REAL by A6,FUNCT_2:2;
        take f;
        thus thesis by A6;
      end;
    then consider f be Function of S,REAL such that
    A9: for x,y be Integer st [x,y] in S holds f. [x,y] = x-y*(sqrt D);
    S is non empty
    proof
      consider x,y be Integer such that
      A10: y<>0 & 0 < x - y * (sqrt D) & |. x^2 - D*y^2.| < 2*(sqrt D)+1
      by A1,Th11;
      [x,y] in S by A10;
      hence thesis;
    end;
    then reconsider R=rng f as finite non empty Subset of REAL by A1;
    inf R >0
      proof
        min R in R by XXREAL_2:def 7;
        then consider xy be object such that
        A11:xy in dom f & f.xy=inf R by FUNCT_1:def 3;
        xy in S by A11;
        then ex x be Integer, y be Integer st
          xy= [x,y] & y<>0 & |. x^2 - D*y^2.| < 2*(sqrt D)+1
            & 0 < x-y*(sqrt D);
        hence thesis by A9,A11;
      end;
    then consider n be Nat such that
    A12: 1/n < inf R and A13:n > 1 by Lm3;
    consider x,y be Integer such that
    A14: y<>0 & |.y.| <= n & 0 < x - y * (sqrt D) < 1/n by A1,A13,Th9;
    A15:|. x^2 - D * y^2.| <= 2 * sqrt D + 1 / (n^2) by A1,A13,A14,Th10;
    2 * sqrt D + 1 / (n^2) < 2 * sqrt D + 1
    proof
      n * n  > 1*1 by A13,XREAL_1:96;
      then 1/(n*n) < 1 by XREAL_1:189;
      hence thesis by XREAL_1:6;
    end;
    then |. x^2 - D * y^2.| < 2 * sqrt D + 1 by A15,XXREAL_0:2;
    then [x,y] in S & S = dom f by A14,FUNCT_2:def 1;
    then f. [x,y] in R & f. [x,y] = x - y * (sqrt D) by A9,FUNCT_1:def 3;
    then x - y * (sqrt D) >= inf R by XXREAL_2:def 7;
    hence contradiction by A12,A14,XXREAL_0:2;
  end;
