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

theorem Th9:
  D is non square & n > 1
    implies
  ex x,y be Integer st
     y <> 0 & |. y .| <=n & 0 < x - y * sqrt D < 1/n
  proof
    assume A1: D is non square & n>1;
    consider x be FinSequence of NAT such that
    A2:len x = n+1 and
    A3:for k st k in dom x holds x.k = [\ (k-1) * sqrt D /]+1 and
    D is non square implies x is one-to-one by Th7;
    deffunc U(Nat) = x.$1 - ($1-1)*sqrt D;
    consider u be FinSequence such that
    A4:len u = n+1 and
    A5: for k st k in dom u holds u.k = U(k) from FINSEQ_1:sch 2;
    rng u c= REAL
    proof
      let y be object;
      assume y in rng u;
      then consider x be object such that
      A6: x in dom u & u.x =y by FUNCT_1:def 3;
      reconsider x as Nat by A6;
      u.x = U(x) by A5,A6;
      hence thesis by A6,XREAL_0:def 1;
    end;
    then reconsider u as FinSequence of REAL by FINSEQ_1:def 4;
    A7:dom x= dom u by A2,A4,FINSEQ_3:29;
    for k st k in dom u holds 0 < u.k <= 1
    proof
      let k such that A8:k in dom u;
      A9: u.k = x.k - (k-1)*(sqrt D) by A8,A5;
      x.k = [\ (k-1) * sqrt D /]+1 by A8,A7,A3;
      then  u.k = [\ (k-1) * sqrt D /] - (k-1)*(sqrt D) +1 by A9;
      hence thesis by Lm1;
    end;
    then consider n1,n2 be Nat such that
    A10:  n1 in dom u & n2 in dom u & n1 <>n2 & u.n1 <= u.n2 &
    u.n2-u.n1 < (1-0)/n by A1,A4,Th8;
    A11: u.n1 = x.n1 - (n1-1)*sqrt D & u.n2 = x.n2 - (n2-1)*sqrt D by A5,A10;
    A12: u.n1 <>u.n2
    proof
      assume u.n1 =u.n2;
      then x.n1 + (1-n1)*sqrt D = x.n2 + (1-n2)*sqrt D by A11;
      then 1-n1 =1-n2 by A1,Th3;
      hence thesis by A10;
    end;
    set X=x.n2-x.n1,Y=n2-n1;
    take X,Y;
    1<= n1 <= n+1 & 1 <= n2 <= n+1 by A4,A10,FINSEQ_3:25;
    then  1-(n+1) <= Y <= n +1 -1 by XREAL_1:13;
    then A13: -n <= Y <= n;
    u.n2 > u.n1 by A12,A10,XXREAL_0:1;
    hence thesis by A13,ABSVALUE:5,A10,A11,XREAL_1:50;
  end;
