reserve i,n,m for Nat,
  x,y,X,Y for set,
  r,s for Real;

theorem
  for M be non empty MetrSpace holds TopSpaceMetr M is compact iff M is
  totally_bounded & M is complete
proof
  let M be non empty MetrSpace;
  set T=TopSpaceMetr M;
  thus T is compact implies M is totally_bounded & M is complete by TBSP_1:8,9;
  assume that
A1: M is totally_bounded and
A2: M is complete;
  now
    reconsider NULL=0 as Real;
    deffunc F(Nat)=1/(1+$1);
    set cM=the carrier of M;
    defpred P[object,object] means
for a,b be Subset of M st $1=a & $2=b holds b c=
    a & diameter b <= (diameter a)/2;
    defpred Q[object] means
for a be Subset of M st a=$1 holds a is bounded & a
    is infinite & a is closed;
    consider seq be Real_Sequence such that
A3: for n be Nat holds seq.n=F(n) from SEQ_1:sch 1;
    set Ns=NULL(#)seq;
A4: for x being object st x in bool cM & Q[x]
   ex y being object st y in bool cM & P[x,y] & Q[y]
    proof
      let x being object such that
A5:   x in bool cM and
A6:   Q[x];
      reconsider X=x as Subset of M by A5;
      reconsider X9=X as Subset of T;
      set d=diameter X;
      per cases by A6,TBSP_1:21;
      suppose
A7:     d=0;
        take Y=X;
        thus thesis by A6,A7;
      end;
      suppose
A8:     d>0;
        then d/4>0 by XREAL_1:224;
        then consider F be Subset-Family of M such that
A9:     F is finite and
A10:    cM = union F and
A11:    for C be Subset of M st C in F ex w be Point of M st C = Ball
        (w,d/4) by A1;
        X is infinite by A6;
        then consider Y be Subset of M such that
A12:    Y in F and
A13:    Y /\ X is infinite by A9,A10,Th35;
        set YX=Y/\X;
A14:    ex w be Point of M st Y = Ball(w,d/4) by A11,A12;
        then
A15:    Y is bounded;
        then
A16:    diameter YX <=diameter Y by TBSP_1:24,XBOOLE_1:17;
        diameter Y<=2*( d /4) by A8,A14,TBSP_1:23,XREAL_1:224;
        then
A17:    diameter YX<=d/2 by A16,XXREAL_0:2;
        reconsider yx=YX as Subset of T;
        reconsider CYX=Cl yx as Subset of M;
        take CYX;
A18:    yx c= Cl yx by PRE_TOPC:18;
A19:    yx c= X9 by XBOOLE_1:17;
        X is closed by A6;
        then
A20:    X9 is closed by Th6;
        YX is bounded by A15,TBSP_1:14,XBOOLE_1:17;
        hence thesis by A13,A17,A18,A20,A19,Th6,Th8,TOPS_1:5;
      end;
    end;
    consider G be Subset-Family of M such that
A21: G is finite and
A22: the carrier of M = union G and
A23: for C be Subset of M st C in G ex w be Point of M st C = Ball(w,1/
    2) by A1;
    let A be Subset of T;
    assume A is infinite;
    then consider X be Subset of M such that
A24: X in G and
A25: X /\ A is infinite by A21,A22,Th35;
    reconsider XA=X/\A as Subset of M;
    reconsider xa=XA as Subset of T;
    reconsider CXA=Cl xa as Subset of M;
A26: XA is bounded & diameter XA <=1
    proof
A27:  ex w be Point of M st X = Ball(w,1/2) by A23,A24;
      then
A28:  diameter X<=2*(1/2) by TBSP_1:23;
A29:  X is bounded by A27;
      then diameter XA <=diameter X by TBSP_1:24,XBOOLE_1:17;
      hence thesis by A29,A28,TBSP_1:14,XBOOLE_1:17,XXREAL_0:2;
    end;
    then CXA is bounded by Th8;
    then
A30: 0<=diameter CXA by TBSP_1:21;
    xa c= Cl xa by PRE_TOPC:18;
    then
A31: CXA in bool cM & Q[CXA] by A25,A26,Th6,Th8;
    consider f be Function such that
A32: dom f = NAT & rng f c= bool cM and
A33: f.0 = CXA and
A34: for k be Nat holds P[f.k,f.(k+1)] & Q[f.k] from
    TREES_2:sch 5(A31,A4);
    reconsider f as SetSequence of M by A32,FUNCT_2:2;
A35: for n holds f.n is bounded by A34;
A36: now
      let x be object;
      assume x in dom f;
      then reconsider i=x as Element of NAT;
      f.i is infinite by A34;
      hence f.x is non empty;
    end;
    for n holds f.n is closed by A34;
    then reconsider f as non-empty pointwise_bounded closed SetSequence of M
    by A36,A35,Def1,Def8,FUNCT_1:def 9;
A37: Ns.0=NULL*seq.0 by SEQ_1:9;
    for n be Nat holds f.(n+1) c= f.n
     by A34;
    then
A38: f is non-ascending by KURATO_0:def 3;
    set df=diameter f;
    defpred N[Nat] means Ns.$1 <= df.$1 & df.$1<=seq.$1;
A39: for n be Nat st N[n] holds N[n+1]
    proof
      let n be Nat;
      assume N[n];
      then df.n<=F(n) by A3;
      then
A40:  (df.n)/2<=F(n)/2 by XREAL_1:72;
      set n1=n+1;
A41:  diameter (f.n)=df. n by Def2;
      diameter (f.n1)<=(diameter (f.n))/2 by A34;
      then df.n1<=(df.n)/2 by A41,Def2;
      then
A42:  df.n1<=F(n)/2 by A40,XXREAL_0:2;
A43:  Ns.n1=NULL*seq.n1 by SEQ_1:9;
      f.n1 is bounded by Def1;
      then
A44:  0<= diameter (f.n1) by TBSP_1:21;
      n1+1<=(n1+1)+n by NAT_1:11;
      then
A45:  F(n1)>=1/(2*n1) by XREAL_1:118;
      1/(2*n1)=F(n)/2 by XCMPLX_1:78;
      then F(n1)>=df.n1 by A42,A45,XXREAL_0:2;
      hence thesis by A3,A44,A43,Def2;
    end;
A46: seq.0=1/(1+0) by A3;
A47: for n be Nat holds seq.n=1/(n+1) by A3;
    then
A48: seq is convergent by SEQ_4:31;
    diameter CXA <= 1 by A26,Th8;
    then
A49: N[0] by A33,A30,A46,A37,Def2;
A50: for n be Nat holds N[n] from NAT_1:sch 2(A49,A39);
A51: Ns is convergent by A47,SEQ_2:7,SEQ_4:31;
A52: lim seq=0 by A47,SEQ_4:31;
    then
A53: lim Ns=NULL*0 by A47,SEQ_2:8,SEQ_4:31;
    then
A54: lim df = 0 by A48,A52,A51,A50,SEQ_2:20;
    then meet f is non empty by A2,A38,Th10;
    then consider p be object such that
A55: p in meet f by XBOOLE_0:def 1;
    reconsider p as Point of T by A55;
    reconsider p9=p as Point of M;
A56: df is convergent by A48,A52,A51,A53,A50,SEQ_2:19;
    now
      let U be open Subset of T;
      assume p in U;
      then consider r be Real such that
A57:  r>0 and
A58:  Ball(p9,r) c= U by TOPMETR:15;
      r/2 >0 by A57,XREAL_1:215;
      then consider n be Nat such that
A59:  for m be Nat st n<=m holds |.df.m-0.|<r/2 by A54,A56,
SEQ_2:def 7;
      p in f.n by A55,KURATO_0:3;
      then
A60:  {p} c= f.n by ZFMISC_1:31;
      f.n is infinite by A34;
      then {p} c<f.n by A60,XBOOLE_0:def 8;
      then f.n\{p} <>{} by XBOOLE_1:105;
      then consider q be object such that
A61:  q in f.n\{p} by XBOOLE_0:def 1;
      reconsider q as Point of T by A61;
A62:  q in f.n by A61,ZFMISC_1:56;
A63:  q in f.n by A61,ZFMISC_1:56;
      reconsider q9=q as Point of M;
      q<>p by A61,ZFMISC_1:56;
      then
A64:  dist(p9,q9)<>0 by METRIC_1:2;
      reconsider B=Ball(q9,dist(p9,q9)) as Subset of T;
A65:  dist(p9,q9)>=0 by METRIC_1:5;
      dist(q9,q9)=0 by METRIC_1:1;
      then
A66:  q in B by A64,A65,METRIC_1:11;
      Ball(q9,dist(p9,q9)) in Family_open_set M by PCOMPS_1:29;
      then
A67:  B is open by PRE_TOPC:def 2;
      f.n c= Cl xa by A33,A38,PROB_1:def 4;
      then B meets xa by A67,A66,A62,PRE_TOPC:24;
      then consider s be object such that
A68:  s in B and
A69:  s in xa by XBOOLE_0:3;
      reconsider s as Point of M by A68;
      reconsider s9=s as Point of T;
      take s9;
A70:  Ns.n=NULL*seq.n by SEQ_1:9;
A71:  |.df.n-0.|<r/2 by A59;
A72:  f.n is bounded by A34;
      df.n>=Ns.n by A50;
      then df.n<r/2 by A70,A71,ABSVALUE:def 1;
      then
A73:  diameter (f.n) < r/2 by Def2;
      p in f.n by A55,KURATO_0:3;
      then dist(p9,q9)<=diameter (f.n) by A63,A72,TBSP_1:def 8;
      then
A74:  dist(p9,q9)<r/2 by A73,XXREAL_0:2;
      dist(q9,s)<dist(p9,q9) by A68,METRIC_1:11;
      then dist(q9,s)<r/2 by A74,XXREAL_0:2;
      then
A75:  dist(p9,q9)+dist(q9,s)< r/2+r/2 by A74,XREAL_1:8;
      dist(p9,s)<=dist(p9,q9)+dist(q9,s) by METRIC_1:4;
      then dist(p9,s)<r by A75,XXREAL_0:2;
      then
A76:  s in Ball(p9,r) by METRIC_1:11;
      s in A by A69,XBOOLE_0:def 4;
      hence s9 in A/\U & s9<>p by A58,A68,A76,METRIC_1:11,XBOOLE_0:def 4;
    end;
    hence Der A is non empty by TOPGEN_1:17;
  end;
  then T is countably_compact by Th27;
  hence thesis by Th34;
end;
