reserve i for Nat,
  j for Element of NAT,
  X,Y,x,y,z for set;
reserve C for initialized ConstructorSignature,
  s for SortSymbol of C,
  o for OperSymbol of C,
  c for constructor OperSymbol of C;
reserve a,b for expression of C, an_Adj C;
reserve t, t1,t2 for expression of C, a_Type C;
reserve p for FinSequence of QuasiTerms C;
reserve e for expression of C;
reserve a,a9 for expression of C, an_Adj C;
reserve q for pure expression of C, a_Type C,
  A for finite Subset of QuasiAdjs C;
reserve T for quasi-type of C;

theorem Th128:
  for S being non void Signature
  for X being with_missing_variables ManySortedSet of the carrier of S holds
  Union the Sorts of Free(S, X) = TS DTConMSA X
proof
  let S be non void Signature;
  let X be with_missing_variables ManySortedSet of the carrier of S;
  set V = X (\/) ((the carrier of S)-->{0});
  set A = Free(S, X);
  set U = the Sorts of A;
  set G = DTConMSA X;
A1: U = S-Terms(X, V) by MSAFREE3:24;
A2: dom U = the carrier of S by PARTFUN1:def 2;
  defpred P[set] means $1 in Union U implies $1 in TS G;
A3: for s being SortSymbol of S, v being Element of V.s
  holds P[root-tree [v,s]]
  proof
    let s be SortSymbol of S;
    let v be Element of V.s;
    assume root-tree [v,s] in Union U;
    then consider s1 being object such that
A4: s1 in dom U and
A5: root-tree [v,s] in U.s1 by CARD_5:2;
    reconsider s1 as SortSymbol of S by A4;
    U.s1={t where t is Term of S,V: the_sort_of t = s1 & variables_in t c= X}
    by A1,MSAFREE3:def 5;
    then consider t being Term of S,V such that
A6: root-tree [v,s] = t and the_sort_of t = s1 and
A7: variables_in t c= X by A5;
    (variables_in t).s = {v} by A6,MSAFREE3:10;
    then {v} c= X.s by A7;
    then v in X.s by ZFMISC_1:31;
    then [v,s] in Terminals G by MSAFREE:7;
    hence thesis by DTCONSTR:def 1;
  end;
A8: for o being OperSymbol of S, p being ArgumentSeq of Sym(o,V) st
  for t being Term of S,V st t in rng p holds P[t]
  holds P[[o,the carrier of S]-tree p]
  proof
    let o be OperSymbol of S;
    let p be ArgumentSeq of Sym(o,V) such that
A9: for t being Term of S,V st t in rng p holds P[t] and
A10: [o,the carrier of S]-tree p in Union U;
    consider s being object such that
A11: s in dom U and
A12: [o,the carrier of S]-tree p in U.s by A10,CARD_5:2;
    reconsider s as SortSymbol of S by A11;
    U.s={t where t is Term of S,V: the_sort_of t = s & variables_in t c= X}
    by A1,MSAFREE3:def 5;
    then consider t being Term of S,V such that
A13: [o,the carrier of S]-tree p = t and
A14: the_sort_of t = s and variables_in t c= X by A12;
    t.{} = [o,the carrier of S] by A13,TREES_4:def 4;
    then the_result_sort_of o = s by A14,MSATERM:17;
    then
A15: rng p c= Union U by A1,A12,MSAFREE3:19;
    rng p c= TS G
    proof
      let x be object;
      assume
A16:  x in rng p;
      then x is Term of S,V by A15,Th124;
      hence thesis by A9,A15,A16;
    end;
    then reconsider q = p as FinSequence of TS G by FINSEQ_1:def 4;
    NonTerminals G = [:the carrier' of S,{the carrier of S}:] by Th120;
    then [o,the carrier of S] in NonTerminals G by ZFMISC_1:106;
    then reconsider oo = [o,the carrier of S] as Symbol of G;
    Sym(o,V) ==> roots p by MSATERM:21;
    then oo ==> roots q by Th127;
    hence thesis by DTCONSTR:def 1;
  end;
A17: for t being Term of S,V holds P[t] from MSATERM:sch 1(A3,A8);
A18: NonTerminals DTConMSA X = [:the carrier' of S,{the carrier of S}:] by
Th120;
A19: Terminals DTConMSA X = Union coprod X by Th120;
  defpred Q[set] means $1 in Union U;
A20: for s being Symbol of G st s in Terminals G holds Q[root-tree s]
  proof
    let s be Symbol of G;
    assume
A21: s in Terminals G;
    then
A22: s`2 in dom X by A19,CARD_3:22;
A23: s`1 in X.s`2 by A19,A21,CARD_3:22;
A24: s = [s`1,s`2] by A19,A21,CARD_3:22;
A25: dom U = the carrier of S by PARTFUN1:def 2;
    root-tree s in (the Sorts of Free(S,X)).s`2 by A22,A23,A24,MSAFREE3:4;
    hence thesis by A22,A25,CARD_5:2;
  end;
  A26: for
 nt being Symbol of G, ts being FinSequence of TS G st nt ==> roots ts &
  for t being DecoratedTree of the carrier of G st t in rng ts holds Q[t]
  holds Q[nt-tree ts]
  proof
    let nt be Symbol of G;
    let ts be FinSequence of TS G such that
A27: nt ==> roots ts and
    A28: for
 t being DecoratedTree of the carrier of G st t in rng ts holds Q[t];
    nt in NonTerminals G by A27;
    then consider o,z being object such that
A29: o in the carrier' of S and
A30: z in {the carrier of S} and
A31: nt = [o,z] by A18,ZFMISC_1:def 2;
    reconsider o as OperSymbol of S by A29;
A32: rng ts c= Union U
    by A28;
    rng ts c= TS DTConMSA V
    proof
      let a be object;
      assume a in rng ts;
      then
A33:  a is Element of S-TermsV by A32,Th124;
      S-TermsV = TS DTConMSA V by MSATERM:def 1;
      hence thesis by A33;
    end;
    then reconsider p = ts as FinSequence of TS DTConMSA V by FINSEQ_1:def 4;
    reconsider q = p as FinSequence of S-TermsV by MSATERM:def 1;
A34: z = the carrier of S by A30,TARSKI:def 1;
    then Sym(o, V) ==> roots p by A27,A31,Th127;
    then reconsider q as ArgumentSeq of Sym(o, V) by MSATERM:21;
    set t = Sym(o, V)-tree q;
    t in U.the_result_sort_of o by A1,A32,MSAFREE3:19;
    hence thesis by A2,A31,A34,CARD_5:2;
  end;
A35: for t being DecoratedTree of the carrier of G
  st t in TS G holds Q[t] from DTCONSTR:sch 7(A20,A26);
  thus Union U c= TS DTConMSA X
  proof
    let x be object;
    assume
A36: x in Union U;
    then consider s being object such that
A37: s in dom U and
A38: x in U.s by CARD_5:2;
    reconsider s as SortSymbol of S by A37;
    x in U.s by A38;
    then x is Term of S,V by A1,MSAFREE3:16;
    hence thesis by A17,A36;
  end;
  let x be object;
  assume
A39: x in TS G;
  then reconsider TG = TS G as non empty Subset of FinTrees(the carrier of G);
  x is Element of TG by A39;
  hence thesis by A35;
end;
