reserve
  a,b for object, I,J for set, f for Function, R for Relation,
  i,j,n for Nat, m for (Element of NAT),
  S for non empty non void ManySortedSign,
  s,s1,s2 for SortSymbol of S,
  o for OperSymbol of S,
  X for non-empty ManySortedSet of the carrier of S,
  x,x1,x2 for (Element of X.s), x11 for (Element of X.s1),
  T for all_vars_including inheriting_operations free_in_itself
  (X,S)-terms MSAlgebra over S,
  g for Translation of Free(S,X),s1,s2,
  h for Endomorphism of Free(S,X);
reserve
  r,r1,r2 for (Element of T),
  t,t1,t2 for (Element of Free(S,X));
reserve
  Y for infinite-yielding ManySortedSet of the carrier of S,
  y,y1 for (Element of Y.s), y11 for (Element of Y.s1),
  Q for all_vars_including inheriting_operations free_in_itself
  (Y,S)-terms MSAlgebra over S,
  q,q1 for (Element of Args(o,Free(S,Y))),
  u,u1,u2 for (Element of Q),
  v,v1,v2 for (Element of Free(S,Y)),
  Z for non-trivial ManySortedSet of the carrier of S,
  z,z1 for (Element of Z.s),
  l,l1 for (Element of Free(S,Z)),
  R for all_vars_including inheriting_operations free_in_itself
  (Z,S)-terms MSAlgebra over S,
  k,k1 for Element of Args(o,Free(S,Z));
reserve c,c1,c2 for set, d,d1 for DecoratedTree;
reserve
  w for (Element of Args(o,T)),
  p,p1 for Element of Args(o,Free(S,X));

theorem
  T height<= (i+1) = T height<= 0 \/ {o-term p:
    union {height t: t in rng p} c= i}
  /\ Union the Sorts of T
  proof
    set I = {o-term p: union {height t: t in rng p} c= i};
    thus T height<= (i+1) c= T height<= 0 \/ I /\ Union the Sorts of T
    proof
      let a be object; assume a in T height<= (i+1);
      then consider t such that
A2:   a = t & t in T & height t <= i+1;
      per cases by Th16;
      suppose ex s,x st t = x-term;
        then t in the set of all x-term;
        then t in (the set of all x-term) \/
        {o-term p: o-term p in T & the_arity_of o = {}} by XBOOLE_0:def 3;
        then t in T height<= 0 by Th12;
        hence thesis by A2,XBOOLE_0:def 3;
      end;
      suppose ex o,p st t = o-term p;
        then consider o,p such that
A3:     t = o-term p;
        reconsider n = union {height t1: t1 in rng p} as Nat by Th25;
        per cases;
        suppose the_arity_of o = {};
          then t in {o-term p where o,p: o-term p in T & the_arity_of o = {}}
          by A2,A3;
          then t in (the set of all x-term) \/
          {o-term p where o,p: o-term p in T & the_arity_of o = {}}
          by XBOOLE_0:def 3;
          then t in T height<= 0 by Th12;
          hence thesis by A2,XBOOLE_0:def 3;
        end;
        suppose the_arity_of o <> {};
          then height t = n + 1 by A3,Th26;
          then Segm n c= Segm i by A2,XREAL_1:6,NAT_1:39;
          then t in I & t in Union the Sorts of T by A2,A3;
          then t in I /\ Union the Sorts of T by XBOOLE_0:def 4;
          hence thesis by A2,XBOOLE_0:def 3;
        end;
      end;
    end;
A10: T height<= 0 c= T height<= (i+1) by Th10c;
      I /\ Union the Sorts of T c= T height<= (i+1)
      proof
        let a be object;
        assume
A15:    a in I /\ Union the Sorts of T;
        then a in I & a in Union the Sorts of T by XBOOLE_0:def 4;
        then consider o,p such that
A12:    a = o-term p & union {height t: t in rng p} c= i;
        reconsider n = union {height t: t in rng p} as Nat by Th25;
A13:    Segm n c= Segm i by A12;
A14:    a in T by A15,XBOOLE_0:def 4;
        per cases;
        suppose the_arity_of o <> {};
          then height(o-term p) = n+1 <= i+1 by A13,Th26,NAT_1:39,XREAL_1:6;
          hence a in T height<= (i+1) by A12,A14;
        end;
        suppose the_arity_of o = {};
          then height(o-term p) = 0 <= i+1 by Th20;
          hence a in T height<= (i+1) by A12,A14;
        end;
      end;
      hence thesis by A10,XBOOLE_1:8;
  end;
