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 Th29:
  (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)
  implies deg (o-term p) = i+1
  proof
    given f being FinSequence of NAT such that
A1: 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;
    dom f = dom p by A1,MSUALG_3:6;
    then
A2: len f = len p by FINSEQ_3:29;
    set t = o-term p;
    set I = [:the carrier' of S, {the carrier of S}:];
    set A = {<*i*>^^((p.(i+1))"I) where i: i < len p};
A4: {} nin union A
    proof
      assume {} in union A;
      then consider J such that
A1:   {} in J & J in A by TARSKI:def 4;
      consider i such that
A2:   J = <*i*>^^((p.(i+1))"I) & i < len p by A1;
      consider q being Element of (p.(i+1))"I such that
A3:   {} = <*i*>^q & q in (p.(i+1))"I by A1,A2;
      thus thesis by A3;
    end;
    reconsider J = [o,the carrier of S] as set;
    J in I by ZFMISC_1:106;
    then IFIN(J,I,{{}},{}) = {{}} by MATRIX_7:def 1;
    then t"I = {{}} \/ union A by Th80;
    then
A5: card (t"I) = card {{}}+`card union{<*i*>^^((p.(i+1))"I) where i: i < len p}
    by A4,CARD_2:35,ZFMISC_1:50
    .= 1 +` card union {<*i*>^^((p.(i+1))"I) where i: i < len p} by CARD_1:30;
    deffunc J(Nat) = <*$1*>^^((p.($1+1))"I);
A6: for i,j st i < len f & j < len f & i <> j holds J(i) misses J(j)
    proof let i,j;
B1:   len <*i*> = 1 = len <*j*> & <*i*>.1 = i & <*j*>.1 = j by FINSEQ_1:40;
      thus thesis by B1,Th2;
    end;
A7: for i st i < len f holds card J(i) = f.(i+1)
    proof let i;
      assume i < len f;
      then
A9:   1 <= i+1 <= len f by NAT_1:12,13;
      reconsider t = p.(i+1) as Element of
      (the Sorts of Free(S,X)).((the_arity_of o)/.(i+1))
      by A1,A9,FINSEQ_3:25,MSUALG_6:2;
      f.(i+1) = deg t by A1,A9,FINSEQ_3:25;
      hence thesis by Th1;
    end;
    card union {J(i) where i: i < len f} = Sum f from CardUnion(A6,A7);
    then card (t"I) = 1+` Sum f by A2,A5;
    hence deg t = i+1 by A1;
  end;
