reserve k, n for Nat;

theorem Th5:
  for S being non void non empty ManySortedSign, X being non-empty
finite-yielding ManySortedSet of the carrier of S st S is finitely_operated for
n being Nat, v being SortSymbol of S holds {t where t is Element of (the Sorts
  of FreeMSA X).v: depth t <= n} is finite
proof
  let S be non void non empty ManySortedSign, X be non-empty finite-yielding
  ManySortedSet of the carrier of S such that
A1: S is finitely_operated;
  set SF = the Sorts of FreeMSA X;
  defpred P[Nat] means for v being SortSymbol of S holds {t where t is Element
  of SF.v: depth t <= $1} is finite;
A2: FreeMSA X = MSAlgebra (#FreeSort(X), FreeOper(X)#) by MSAFREE:def 14;
A3: for k be Nat st P[k] holds P[k+1]
  proof
    deffunc F(set) = $1;
    let n be Nat;
    assume
A4: for v being SortSymbol of S holds {t where t is Element of SF.v:
    depth t <= n} is finite;
    let v be SortSymbol of S;
    defpred QZ[Element of SF.v] means depth $1 = n+1;
    defpred P[Element of SF.v] means depth $1 <= n+1;
    defpred Q[Element of SF.v] means depth $1 <= n or depth $1 = n+1;
    set dn1 = {F(t) where t is Element of SF.v: P[t]};
    set dn11 = {F(t) where t is Element of SF.v: Q[t]};
    set den1 = {t where t is Element of SF.v: QZ[t]};
    set ov = {o where o is OperSymbol of S: the_result_sort_of o = v};
A5: SF.v = FreeSort(X,v) by A2,MSAFREE:def 11;
    ov is finite by A1,MSSCYC_1:def 5;
    then consider ovs being FinSequence such that
A6: rng ovs = ov by FINSEQ_1:52;
    deffunc F(set) = {t where t is Element of SF.v: depth t = n+1 & t.{} = [
    ovs.$1,the carrier of S]};
    consider dvs being FinSequence such that
A7: len dvs = len ovs & for k being Nat st k in dom dvs holds dvs.k =
    F(k) from FINSEQ_1:sch 2;
A8: dom ovs = Seg len ovs & dom dvs = Seg len dvs by FINSEQ_1:def 3;
A9: FreeSort(X,v) c= S-Terms X by MSATERM:12;
A10: den1 c= Union dvs
    proof
      let x be object;
      assume x in den1;
      then consider t being Element of SF.v such that
A11:  x = t and
A12:  depth t = n+1;
      t in FreeSort(X,v) by A5;
      then reconsider t9 = t as Term of S, X by A9;
      now
A13:    ex dt being finite DecoratedTree, tt being finite Tree st dt = t &
        tt = dom dt & depth t = height tt by MSAFREE2:def 14;
        assume t9 is root;
        hence contradiction by A12,A13,TREES_1:42,TREES_9:def 1;
      end;
      then consider o being OperSymbol of S such that
A14:  t9.{} = [o,the carrier of S] by MSSCYC_1:20;
      the_result_sort_of o = the_sort_of t9 by A14,MSATERM:17
        .= v by A5,MSATERM:def 5;
      then o in rng ovs by A6;
      then consider k being object such that
A15:  k in dom ovs and
A16:  o = ovs.k by FUNCT_1:def 3;
      dvs.k = {t1 where t1 is Element of SF.v: depth t1 = n+1 & t1.{} = [
      ovs.k,the carrier of S]} by A7,A8,A15;
      then
A17:  t in dvs.k by A12,A14,A16;
      dvs.k in rng dvs by A7,A8,A15,FUNCT_1:def 3;
      then t in union rng dvs by A17,TARSKI:def 4;
      hence thesis by A11,CARD_3:def 4;
    end;
    for k being object st k in dom dvs holds dvs.k is finite
    proof
      let k be object;
      set dvsk = {t where t is Element of SF.v: depth t = n+1 & t.{} = [ovs.k,
      the carrier of S]};
      assume
A18:  k in dom dvs;
      then ovs.k in rng ovs by A7,A8,FUNCT_1:def 3;
      then consider o being OperSymbol of S such that
A19:  o = ovs.k and
      the_result_sort_of o = v by A6;
      set davsk = {[o,the carrier of S]-tree a where a is Element of (S-Terms
X)* : a is ArgumentSeq of Sym(o,X) & ex t being Element of SF.v st depth t = n+
      1 & t = [o,the carrier of S]-tree a};
A20:  dvsk c= davsk
      proof
        let x be object;
        assume x in dvsk;
        then consider t being Element of SF.v such that
A21:    x = t and
A22:    depth t = n+1 and
A23:    t.{} = [o,the carrier of S] by A19;
        t in FreeSort(X,v) by A5;
        then reconsider t9 = t as Term of S, X by A9;
        consider a being ArgumentSeq of Sym(o,X) such that
A24:    t9 = [o,the carrier of S]-tree a by A23,MSATERM:10;
        reconsider a9 = a as Element of (S-Terms X)* by FINSEQ_1:def 11;
        [o,the carrier of S]-tree a9 in davsk by A22,A24;
        hence thesis by A21,A24;
      end;
      deffunc F(Nat)= {t where t is Element of SF.((the_arity_of o)/.$1):
      depth t <=n};
      set avsk = {a where a is Element of (S-Terms X)* : a is ArgumentSeq of
Sym(o,X) & ex t being Element of SF.v st depth t = n+1 & t = [o,the carrier of
      S]-tree a};
A25:  avsk,davsk are_equipotent
      proof
        set Z = {[a,[o,the carrier of S]-tree a] where a is Element of (S
-Terms X)* : a is ArgumentSeq of Sym(o,X) & ex t being Element of SF.v st depth
        t = n+1 & t = [o,the carrier of S]-tree a};
        take Z;
        hereby
          let x be object;
          assume x in avsk;
          then consider a being Element of (S-Terms X)* such that
A26:      x = a and
A27:      a is ArgumentSeq of Sym(o,X) & ex t being Element of SF.v
          st depth t = n+1 & t = [o,the carrier of S]-tree a;
          reconsider y9 = [o,the carrier of S]-tree a as object;
          take y9;
          thus y9 in davsk by A27;
          thus [x,y9] in Z by A26,A27;
        end;
        hereby
          let y be object;
          assume y in davsk;
          then consider a being Element of (S-Terms X)* such that
A28:      y = [o,the carrier of S]-tree a and
A29:      a is ArgumentSeq of Sym(o,X) & ex t being Element of SF.v
          st depth t = n+1 & t = [o,the carrier of S]-tree a;
          reconsider a9 = a as object;
          take a9;
          thus a9 in avsk by A29;
          thus [a9,y] in Z by A28,A29;
        end;
        let x,y,z,u be object;
        assume [x,y] in Z;
        then consider xa being Element of (S-Terms X)* such that
A30:    [x,y] = [xa,[o,the carrier of S]-tree xa] and
A31:    xa is ArgumentSeq of Sym(o,X) and
        ex t being Element of SF.v st depth t = n+1 & t = [o,the carrier
        of S]-tree xa;
A32:    x = xa by A30,XTUPLE_0:1;
        assume [z,u] in Z;
        then consider za being Element of (S-Terms X)* such that
A33:    [z,u] = [za,[o,the carrier of S]-tree za] and
A34:    za is ArgumentSeq of Sym(o,X) and
        ex t being Element of SF.v st depth t = n+1 & t = [o,the carrier
        of S]-tree za;
A35:    z = za by A33,XTUPLE_0:1;
        hence x = z implies y = u by A30,A33,A32,XTUPLE_0:1;
A36:    u = [o,the carrier of S]-tree za by A33,XTUPLE_0:1;
A37:    y = [o,the carrier of S]-tree xa by A30,XTUPLE_0:1;
        assume y = u;
        hence thesis by A31,A34,A32,A37,A35,A36,TREES_4:15;
      end;
      consider nS being FinSequence such that
A38:  len nS = len the_arity_of o & for k being Nat st k in dom nS
      holds nS.k = F(k) from FINSEQ_1:sch 2;
A39:  dom nS = Seg len nS by FINSEQ_1:def 3;
A40:  dom nS = Seg len the_arity_of o by A38,FINSEQ_1:def 3;
A41:  avsk c= product nS
      proof
        let x be object;
        assume x in avsk;
        then consider a being Element of (S-Terms X)* such that
A42:    x = a and
A43:    a is ArgumentSeq of Sym(o,X) and
A44:    ex t being Element of SF.v st depth t = n+1 & t = [o,the
        carrier of S]-tree a;
        reconsider a as ArgumentSeq of Sym(o,X) by A43;
A45:    len a = len the_arity_of o & dom a = Seg len a by FINSEQ_1:def 3
,MSATERM:22;
        now
          let x be object;
          assume
A46:      x in dom a;
          then reconsider k = x as Element of NAT;
          reconsider ak = a.k as Term of S, X by A46,MSATERM:22;
A47:      the_sort_of ak = (the_arity_of o)/.k by A46,MSATERM:23;
          SF.(the_sort_of ak) = FreeSort(X,the_sort_of ak) by A2,MSAFREE:def 11
;
          then reconsider ak as Element of SF.((the_arity_of o)/.k) by A47,
MSATERM:def 5;
          depth ak < n+1 by A44,A46,MSSCYC_1:27;
          then
A48:      depth ak <= n by NAT_1:13;
          set nSk = {tk where tk is Element of SF.((the_arity_of o)/.k): depth
          tk <=n};
          nSk = nS.x by A38,A40,A45,A46;
          hence a.x in nS.x by A48;
        end;
        hence thesis by A38,A39,A42,A45,CARD_3:def 5;
      end;
      now
        let x be object;
        assume
A49:    x in dom nS;
        then reconsider k = x as Nat;
        set nSk = {t where t is Element of SF.((the_arity_of o)/.k): depth t
        <=n};
        nS.k = nSk by A38,A49;
        hence nS.x is finite by A4;
      end;
      then nS is finite-yielding by FINSET_1:def 4;
      then product nS is finite;
      then davsk is finite by A25,A41,CARD_1:38;
      hence thesis by A7,A18,A20;
    end;
    then
A50: Union dvs is finite by CARD_2:88;
    defpred Z[Element of SF.v] means depth $1 <= n;
    set dln = {t where t is Element of SF.v: Z[t]};
A51: {t where t is Element of SF.v: Z[t] or QZ[t]} = dln \/ den1 from
    TOPREAL1:sch 1;
A52: for t being Element of SF.v holds P[t] iff Q[t] by NAT_1:8,12;
A53: dn1 = dn11 from FRAENKEL:sch 3(A52);
    dln is finite by A4;
    hence thesis by A53,A51,A50,A10;
  end;
A54: P[ 0 ]
  proof
    let v be SortSymbol of S;
    set dle0 = {t where t is Element of SF.v: depth t <= 0};
    set d0 = {t where t is Element of SF.v: depth t = 0};
A55: dle0 c= d0
    proof
      let x be object;
      assume x in dle0;
      then consider t being Element of SF.v such that
A56:  x = t and
A57:  depth t <= 0;
      depth t = 0 by A57;
      hence thesis by A56;
    end;
    Constants(FreeMSA X, v) is finite & d0 = FreeGen(v, X) \/ Constants(
    FreeMSA X, v) by A1,MSSCYC_1:25,26;
    hence thesis by A55;
  end;
  thus for n being Nat holds P[n] from NAT_1:sch 2(A54, A3);
end;
