reserve n,k,k1,m,m1,n1,n2,l for Nat;
reserve r,r1,r2,p,p1,g,g1,g2,s,s1,s2,t for Real;
reserve seq,seq1,seq2 for Real_Sequence;
reserve Nseq for increasing sequence of NAT;
reserve x for set;
reserve X,Y for Subset of REAL;

theorem :: Cauchy Theorem
  seq is convergent iff for s st 0<s ex n st for m st n<=m
    holds |.seq.m -seq.n.|<s
proof
 thus seq is convergent implies for s st 0<s ex n st for m st n<=m
   holds |.seq.m -seq.n.|<s
  proof
    assume seq is convergent;
    then consider g1 such that
A1: for s st 0<s ex n st for m st n<=m holds |.seq.m -g1.|<s;
    let s;
    assume 0<s;
    then consider n1 such that
A2: for m st n1<=m holds |.seq.m -g1.|<s/2 by A1;
    take n=n1;
    let m;
    assume n<=m;
    then
A3: |.seq.m-g1.|<s/2 by A2;
A4: |.seq.m -g1+(g1-seq.n).|<=|.seq.m-g1.|+|.g1-seq.n.| by COMPLEX1:56;
    |.seq.n -g1.|<s/2 by A2;
    then |.-(g1-seq.n).|<s/2;
    then |.g1-seq.n.|<s/2 by COMPLEX1:52;
    then |.seq.m-g1.|+|.g1-seq.n.|<s/2+s/2 by A3,XREAL_1:8;
    hence thesis by A4,XXREAL_0:2;
  end;
  assume
A5: for s st 0<s ex n st for m st n<=m holds |.seq.m -seq.n.|<s;
  then consider n1 such that
A6: for m st n1<=m holds |.seq.m -seq.n1.|<1;
  consider r1 such that
A7: 0<r1 and
A8: for m st m<=n1 holds |.seq.m.|<r1 by SEQ_2:4;
  now
    take r=r1+|.seq.n1.|+1;
    (0 qua Nat)+(0 qua Nat)<r1+|.seq.n1.| by A7,COMPLEX1:46,XREAL_1:8;
    hence 0<r;
    let m;
A9: now
      assume n1<=m;
      then
A10:  |.seq.m -seq.n1.|<1 by A6;
      |.seq.m.|-|.seq.n1.|<=|.seq.m -seq.n1.| by COMPLEX1:59;
      then |.seq.m.|-|.seq.n1.|<1 by A10,XXREAL_0:2;
      then |.seq.m.|-|.seq.n1.|+|.seq.n1.|<1+|.seq.n1.| by XREAL_1:6;
      then (0 qua Nat)+|.seq.m.|<r1+(|.seq.n1.|+1) by A7,XREAL_1:8;
      hence |.seq.m.|<r;
    end;
    now
      assume m<=n1;
      then |.seq.m.|<r1 by A8;
      then |.seq.m.|+(0 qua Nat)<r1+|.seq.n1.| by COMPLEX1:46,XREAL_1:8;
      hence |.seq.m.|<r by XREAL_1:8;
    end;
    hence |.seq.m.|<r by A9;
  end;
  then seq is bounded by SEQ_2:3;
  then consider seq1 such that
A11: seq1 is subsequence of seq and
A12: seq1 is convergent by Th40;
  consider g1 such that
A13: for s st 0<s ex n st for m st n<=m holds |.seq1.m-g1.|<s by A12;
  take g1;
  let s;
  assume
A14: 0<s;
  then consider n1 such that
A15: for m st n1<=m holds |.seq1.m-g1.|<s/3 by A13;
  consider n2 such that
A16: for m st n2<=m holds |.seq.m -seq.n2.|<s/3 by A5,A14;
  take n=n1+n2;
  let m such that
A17: n<=m;
  consider Nseq such that
A18: seq1=seq*Nseq by A11,VALUED_0:def 17;
 A19: m in NAT by ORDINAL1:def 12;
   n1<=n by NAT_1:12;
  then n1<=m by A17,XXREAL_0:2;
  then |.(seq*Nseq).m -g1.|<s/3 by A18,A15;
  then
A20: |.seq.(Nseq.m) -g1.|<s/3 by FUNCT_2:15,A19;
  n2<=n by NAT_1:12; then
A21: n2<=m by A17,XXREAL_0:2;
  m<=Nseq.m by SEQM_3:14;
  then n2<=Nseq.m by A21,XXREAL_0:2;
  then |.seq.(Nseq.m) -seq.n2.|<s/3 by A16;
  then |.-(seq.n2-seq.(Nseq.m)).|<s/3;
  then
A22: |.seq.n2-seq.(Nseq.m).|<s/3 by COMPLEX1:52;
  |.seq.m -seq.n2.|<s/3 by A16,A21;
  then
A23: |.seq.m -seq.n2.|+|.seq.n2-seq.(Nseq.m).|<s/3+s/3 by A22,XREAL_1:8;
  |.seq.m -seq.n2+(seq.n2-seq.(Nseq.m)).|<=
     |.seq.m -seq.n2.|+|.seq.n2-seq.(Nseq.m).| by COMPLEX1:56;
  then |.seq.m -seq.(Nseq.m).|<s/3+s/3 by A23,XXREAL_0:2;
  then
A24: |.seq.m -seq.(Nseq.m).|+|.seq.(Nseq.m) -g1.|<s/3+s/3+s/3 by A20,
XREAL_1:8;
  |.seq.m -seq.(Nseq.m)+(seq.(Nseq.m) -g1).|<= |.seq.m -seq.(Nseq.m).|+
  |.seq.(Nseq.m) -g1.| by COMPLEX1:56;
  hence thesis by A24,XXREAL_0:2;
end;
