reserve x for set,
  t,t1,t2 for DecoratedTree;
reserve C for set;
reserve X,Y for non empty constituted-DTrees set;
reserve T for DecoratedTree,
  p for FinSequence of NAT;
reserve T for finite-branching DecoratedTree,
  t for Element of dom T,
  x for FinSequence,
  n, m for Nat;
reserve x, x9 for Element of dom T,
  y9 for set;
reserve n,k1,k2,l,k,m for Nat,
  x,y for set;

theorem Th47:
  for T being finite-branching Tree holds T is finite iff ex n
  being Nat st T-level n = {}
proof
  let T be finite-branching Tree;
  deffunc F(Nat) = T-level $1;
  now
    assume
A1: T is finite;
    now
      assume
A2:   not ex n being Nat st T-level n = {};
A3:   for n ex C being finite Chain of T st card C = n
      proof
        let n;
        T-level n <> {} by A2;
        then consider t being object such that
A4:     t in T-level n by XBOOLE_0:def 1;
        consider w being Element of T such that
        t = w and
A5:     len w = n by A4;
        ProperPrefixes w is finite Chain of T by Th43;
        then consider C being finite Chain of T such that
A6:     C = ProperPrefixes w;
        card C = n by A5,A6,TREES_1:35;
        hence thesis;
      end;
      for t being Element of T holds succ t is finite;
      then ex C being Chain of T st not C is finite by A3,TREES_2:29;
      hence contradiction by A1;
    end;
    hence ex n being Nat st T-level n = {};
  end;
  hence T is finite implies ex n being Nat st T-level n = {};
  given n such that
A7: T-level n = {};
  set X = { F(m) where m is Nat : m <= n };
A8: T c= union X
  proof
    let x be object;
    assume x in T;
    then reconsider t = x as Element of T;
    consider m such that
A9: m = len t;
A10: t in F(m) by A9;
    len t < n
    proof
      consider q being FinSequence such that
A11:  q = t|Seg n and
A12:  q is_a_prefix_of t by Th32;
      assume n <= len t;
      then
A13:  len q = n by A11,FINSEQ_1:17;
      reconsider q as Element of T by A12,TREES_1:20;
      q in T-level n by A13;
      hence contradiction by A7;
    end;
    then F(m) in X by A9;
    hence thesis by A10,TARSKI:def 4;
  end;
A14: X is finite
  proof
    defpred P[set,object] means ex l,m st m = l+1 & $1 = m & F(l) = $2;
A15: for k be Nat st k in Seg(n+1) ex x being object st P[k,x]
    proof
      let k be Nat;
      assume k in Seg(n+1);
      then 0 <> k by FINSEQ_1:1;
      then consider l being Nat such that
A16:  k = l+1 by NAT_1:6;
      reconsider l as Nat;
      consider x such that
A17:  x = F(l);
      take x,l,l+1;
      thus thesis by A16,A17;
    end;
    consider p being FinSequence such that
A18: dom p = Seg(n+1) & for k be Nat st k in Seg(n+1) holds P[k,p.k]
    from FINSEQ_1:sch 1(A15);
A19: for k st k+1 in Seg (n+1) holds p.(k+1) = F(k)
    proof
      let k;
      assume k+1 in Seg (n+1);
      then ex l,m st m = l+1 & k+1 = m & F(l) = p.(k+1) by A18;
      hence thesis;
    end;
    X c= rng p
    proof
      let y be object;
      assume y in X;
      then consider m such that
A20:  y = F(m) and
A21:  m <= n;
A22:  0+1 <= m+1 by XREAL_1:6;
      m+1 <= n+1 by A21,XREAL_1:6;
      then
A23:  m+1 in Seg (n+1) by A22,FINSEQ_1:1;
      then p.(m+1) = F(m) by A19;
      hence thesis by A18,A20,A23,FUNCT_1:def 3;
    end;
    hence thesis;
  end;
  for Y being set st Y in X holds Y is finite
  proof
    let Y be set;
    assume Y in X;
    then ex m st Y = F(m) & m <= n;
    hence thesis by Th46;
  end;
  then union X is finite by A14,FINSET_1:7;
  hence thesis by A8;
end;
