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 Th12:
  T height<= 0 = (the set of all x-term) \/
  {o-term p: o-term p in T & the_arity_of o = {}}
  proof set I = the set of all x-term;
    set J = {o-term p: o-term p in T & the_arity_of o = {}};
    thus T height<= 0 c= I \/ J
    proof let a;
      assume a in T height<= 0;
      then consider t such that
A1:   a = t & t in T & height t <= 0;
      per cases by Th16;
      suppose ex s,x st t = x-term;
        then t in I;
        hence thesis by A1,XBOOLE_0:def 3;
      end;
      suppose ex o,p st t = o-term p;
        then consider o,p such that
A2:     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 J by A1,A2;
          hence thesis by A1,XBOOLE_0:def 3;
        end;
        suppose the_arity_of o <> {};
          then height t = n+1 by A2,Th26;
          hence thesis by A1;
        end;
      end;
    end;
    let a; assume a in I \/ J;
    then per cases by XBOOLE_0:def 3;
    suppose a in I;
      then consider s,x such that
A3:   a = x-term;
      height (x-term) = 0 & x-term in T by Th24,TREES_1:42;
      hence thesis by A3;
    end;
    suppose a in J;
      then consider o,p such that
A4:   a = o-term p & o-term p in T & the_arity_of o = {};
      height (o-term p) = 0 by A4,Th20;
      hence thesis by A4;
    end;
  end;
