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 deg<= (i+1) = T deg<= 0 \/ {o-term p:
    ex f being FinSequence of NAT st i >= Sum f & dom f = dom the_arity_of o &
    for i,t st i in dom the_arity_of o & t = p.i holds f.i = deg t}
    /\ Union the Sorts of T
    proof
      set I = {o-term p: ex f being FinSequence of NAT st i >= Sum f &
      dom f = dom the_arity_of o &
      for i,t st i in dom the_arity_of o & t = p.i holds f.i = deg t};
      thus T deg<= (i+1) c= T deg<= 0 \/ I /\ Union the Sorts of T
      proof
        let a be object; assume a in T deg<= (i+1);
        then consider r such that
A2:     a = r & deg r <= i+1;
        reconsider t = r as Element of Free(S,X) by MSAFREE4:39;
        per cases by Th16;
        suppose ex s,x st t = x-term;
          then t in the set of all x-term;
          then t in T deg<= 0 by Th11;
          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;
          deffunc F(object) = deg (p/.$1);
          consider f being Function such that
A4:       dom f = dom p & for a being object st a in dom p holds f.a = F(a)
          from FUNCT_1:sch 3;
          dom f = Seg len p by A4,FINSEQ_1:def 3;
          then reconsider f as FinSequence by FINSEQ_1:def 2;
          rng f c= NAT
          proof
            let y be object;
            assume y in rng f;
            then consider x being object such that
A5:         x in dom f & y = f.x by FUNCT_1:def 3;
            y = F(x) by A4,A5;
            hence thesis;
          end;
          then reconsider f as FinSequence of NAT by FINSEQ_1:def 4;
A6:       dom f = dom the_arity_of o by A4,MSUALG_3:6;
A8:       now let i,t; assume
A7:         i in dom the_arity_of o & t = p.i;
            then t = p/.i by A4,A6,PARTFUN1:def 6;
            hence f.i = deg t by A4,A6,A7;
          end;
          then deg t = Sum f + 1 by A3,A4,Th29,MSUALG_3:6;
          then Sum f <= i by A2,XREAL_1:6;
          then t in I & t in Union the Sorts of T by A3,A6,A8;
          then t in I /\ Union the Sorts of T by XBOOLE_0:def 4;
          hence thesis by A2,XBOOLE_0:def 3;
        end;
      end;
A10:  T deg<= 0 c= T deg<= (i+1) by Th10b;
      I /\ Union the Sorts of T c= T deg<= (i+1)
      proof
        let a be object;
        assume
A14:    a in I /\ Union the Sorts of T;
        then
A11:    a in I & a in Union the Sorts of T by XBOOLE_0:def 4;
        reconsider r = a as Element of T by A14,XBOOLE_0:def 4;
        consider o,p such that
A12:    a = o-term p & ex f being FinSequence of NAT st i >= Sum f &
        dom f = dom the_arity_of o &
        for i,t st i in dom the_arity_of o & t = p.i holds f.i = deg t by A11;
        consider f being FinSequence of NAT such that
A13:    i >= Sum f & dom f = dom the_arity_of o &
        for i,t st i in dom the_arity_of o & t = p.i holds f.i = deg t by A12;
        i+1 >= Sum f + 1 = deg (o-term p) & a in T & deg r = deg (o-term p)
        by A14,A12,A13,Th29,XREAL_1:6,XBOOLE_0:def 4;
        hence a in T deg<= (i+1);
      end;
      hence thesis by A10,XBOOLE_1:8;
    end;
