reserve S for non void non empty ManySortedSign,
  U0 for MSAlgebra over S;
reserve S for non void non empty ManySortedSign,
  X for ManySortedSet of the carrier of S,
  o for OperSymbol of S,
  b for Element of ([:the carrier' of S,{the
  carrier of S}:] \/ Union (coprod X))*;
reserve x for set;

theorem Th10:
  for S be non void non empty ManySortedSign, X be non-empty
ManySortedSet of the carrier of S, o be OperSymbol of S, p be FinSequence of TS
  (DTConMSA(X)) holds Sym(o,X) ==> roots p iff p in ((FreeSort X)# * (the Arity
  of S)).o
proof
  let S be non void non empty ManySortedSign, X be non-empty ManySortedSet of
  the carrier of S, o be OperSymbol of S, p be FinSequence of TS(DTConMSA(X));
  set D = DTConMSA(X), ar = the_arity_of o;
  set r = roots p, OU = [:the carrier' of S,{the carrier of S}:] \/ Union (
  coprod X);
A1: dom p = dom r by TREES_3:def 18;
  thus Sym(o,X) ==> roots p implies p in ((FreeSort X)# * (the Arity of S)).o
  proof
    assume Sym(o,X) ==> roots p;
    then
A2: [[o,the carrier of S],roots p] in REL(X) by LANG1:def 1;
    then reconsider
    r = roots p as Element of ([:the carrier' of S,{the carrier of
    S}:] \/ Union (coprod X))* by ZFMISC_1:87;
A3: dom p = dom r by TREES_3:def 18;
A4: dom r = Seg len r & Seg len ar = dom ar by FINSEQ_1:def 3;
A5: len r = len ar by A2,Th5;
    for n be Nat st n in dom p holds p.n in FreeSort(X,ar/.n)
    proof
      let n be Nat;
      set s = ar/.n;
      assume
A6:   n in dom p;
      then consider T be DecoratedTree such that
A7:   T = p.n and
A8:   r.n = T.{} by TREES_3:def 18;
      rng p c= TS D & p.n in rng p by A6,FINSEQ_1:def 4,FUNCT_1:def 3;
      then reconsider T as Element of TS(D) by A7;
A9:   rng r c= [:the carrier' of S,{the carrier of S}:] \/ Union (coprod
      X) & r.n in rng r by A3,A6,FINSEQ_1:def 4,FUNCT_1:def 3;
      per cases by A9,XBOOLE_0:def 3;
      suppose
A10:    r.n in [:the carrier' of S,{the carrier of S}:];
        then consider
        o1 being OperSymbol of S, x2 being Element of {the carrier of
        S} such that
A11:    r.n = [o1,x2] by DOMAIN_1:1;
A12:    x2 = the carrier of S by TARSKI:def 1;
        then the_result_sort_of o1 = ar.n by A2,A3,A6,A10,A11,Th5
          .= ar/.n by A5,A3,A4,A6,PARTFUN1:def 6;
        then (ex x be set st x in X.s & T = root-tree [x,s]) or ex o be
OperSymbol of S st [o,the carrier of S] = T.{} & the_result_sort_of o = s by A8
,A11,A12;
        hence thesis by A7;
      end;
      suppose
A13:    r.n in Union (coprod X);
        then r.n in coprod(ar.n,X) by A2,A3,A6,Th5;
        then r.n in coprod(s,X) by A5,A3,A4,A6,PARTFUN1:def 6;
        then
A14:    ex a be set st a in X.s & r.n = [a,s] by Def2;
        reconsider t = r.n as Terminal of D by A13,Th6;
        T = root-tree t by A8,DTCONSTR:9;
        hence thesis by A7,A14;
      end;
    end;
    hence thesis by A5,A3,A4,Th9;
  end;
A15: dom r = Seg len r by FINSEQ_1:def 3;
  reconsider r as FinSequence of OU;
  reconsider r as Element of OU* by FINSEQ_1:def 11;
  assume
A16: p in ((FreeSort X)# * (the Arity of S)).o;
  then
A17: dom p = dom ar by Th9;
A18: Union (coprod X) misses [:the carrier' of S,{the carrier of S}:] by Th4;
A19: for x be set st x in dom r holds (r.x in [:the carrier' of S,{the
carrier of S}:] implies for o1 be OperSymbol of S st [o1,the carrier of S] = r.
x holds the_result_sort_of o1 = ar.x) & (r.x in Union (coprod X) implies r.x in
  coprod(ar.x,X))
  proof
    let x be set;
    assume
A20: x in dom r;
    then reconsider n = x as Nat;
A21: ex T be DecoratedTree st T = p.n & r.n = T.{} by A1,A20,TREES_3:def 18;
    set s = ar/.n;
    p.n in FreeSort(X,s) by A16,A1,A20,Th9;
    then consider a be Element of TS D such that
A22: a = p.n and
A23: (ex x be set st x in X.s & a = root-tree [x,s]) or ex o be
    OperSymbol of S st [o,the carrier of S] = a.{} & the_result_sort_of o = s;
A24: s = ar.n by A17,A1,A20,PARTFUN1:def 6;
    thus r.x in [:the carrier' of S,{the carrier of S}:] implies for o1 be
OperSymbol of S st [o1,the carrier of S] = r.x holds the_result_sort_of o1 = ar
    .x
    proof
      assume
A25:  r.x in [:the carrier' of S,{the carrier of S}:];
A26:  now
        dom coprod(X) = the carrier of S by PARTFUN1:def 2;
        then (coprod(X)).s in rng coprod(X) by FUNCT_1:def 3;
        then
A27:    coprod(s,X) in rng coprod(X) by Def3;
        given y be set such that
A28:    y in X.s & a = root-tree [y,s];
        r.x = [y,s] & [y,s] in coprod(s,X) by A22,A21,A28,Def2,TREES_4:3;
        then r.x in union rng coprod(X) by A27,TARSKI:def 4;
        then r.x in Union (coprod X) by CARD_3:def 4;
        hence contradiction by A18,A25,XBOOLE_0:3;
      end;
      let o1 be OperSymbol of S;
      assume [o1,the carrier of S] = r.x;
      hence thesis by A22,A23,A21,A24,A26,XTUPLE_0:1;
    end;
    assume
A29: r.x in Union (coprod X);
    now
      given o1 be OperSymbol of S such that
A30:  [o1,the carrier of S] = a.{} and
      the_result_sort_of o1 = s;
      the carrier of S in {the carrier of S} by TARSKI:def 1;
      then [o1,the carrier of S] in [:the carrier' of S,{the carrier of S}:]
      by ZFMISC_1:87;
      hence contradiction by A18,A22,A21,A29,A30,XBOOLE_0:3;
    end;
    then consider y be set such that
A31: y in X.s and
A32: a = root-tree [y,s] by A23;
    r.x = [y,s] by A22,A21,A32,TREES_4:3;
    hence thesis by A24,A31,Def2;
  end;
  len r = len ar by A17,A1,A15,FINSEQ_1:def 3;
  then [[o,the carrier of S],r] in REL X by A19,Th5;
  hence thesis by LANG1:def 1;
end;
