reserve x,y,z for set;

theorem Th23:
  for S being non void Signature for X being ManySortedSet of the
carrier of S for t being Term of S, X (\/) ((the carrier of S)-->{0})
 for s being SortSymbol of S st
  t in S-Terms(X, X (\/) ((the carrier of S)-->{0})).s holds t
  in (the Sorts of Free(S, X)).s
proof
  let S be non void non empty ManySortedSign;
  let X be ManySortedSet of the carrier of S;
  set Y = X (\/) ((the carrier of S)-->{0});
  set T = the Sorts of Free(S, X);
  defpred P[set] means for s being SortSymbol of S st $1 in S-Terms(X, Y).s
  holds $1 in T.s;
A1: ex A being MSSubset of FreeMSA Y st Free(S, X) = GenMSAlg A & A = (
  Reverse Y)""X by Def1;
  then reconsider TT = T as MSSubset of FreeMSA Y by MSUALG_2:def 9;
A2: now
    let o be OperSymbol of S, p be ArgumentSeq of Sym(o,Y) such that
A3: for t being Term of S,Y st t in rng p holds P[t];
    thus P[[o,the carrier of S]-tree p]
    proof
      let s be SortSymbol of S;
      assume
A4:   [o, the carrier of S]-tree p in S-Terms(X, Y).s;
A5:   Sym(o,Y) = [o, the carrier of S] by MSAFREE:def 9;
      the_sort_of (Sym(o,Y)-tree p) = the_result_sort_of o by MSATERM:20;
      then
A6:   s = the_result_sort_of o by A4,A5,Th17;
      then
A7:   rng p c= Union (S-Terms(X,Y)) by A4,A5,Th19;
A8:   rng p c= Union TT
      proof
        let x be object;
        assume
A9:     x in rng p;
        then consider y being object such that
A10:    y in dom (S-Terms(X,Y)) and
A11:    x in (S-Terms(X,Y)).y by A7,CARD_5:2;
        reconsider y as SortSymbol of S by A10;
        S-Terms(X, Y).y = S-Terms(X, Y).y;
        then reconsider x as Term of S,Y by A11,Th16;
        dom T = the carrier of S & x in T.y by A3,A9,A11,PARTFUN1:def 2;
        hence thesis by CARD_5:2;
      end;
      TT is opers_closed by A1,MSUALG_2:def 9;
      hence thesis by A5,A6,A8,Th20;
    end;
  end;
A12: S-Terms(X, Y) c= the Sorts of FreeMSA Y by PBOOLE:def 18;
A13: now
    let s1 be SortSymbol of S, v be Element of Y.s1;
    thus P[root-tree [v,s1]]
    proof
      reconsider t = root-tree [v,s1] as Term of S,Y by MSATERM:4;
      let s be SortSymbol of S;
      assume
A14:  root-tree [v,s1] in S-Terms(X, Y).s;
      S-Terms(X, Y).s c= (the Sorts of FreeMSA Y).s by A12;
      then
A15:  the_sort_of t = s by A14,Th7;
A16:  the_sort_of t = s1 by MSATERM:14;
      then v in X.s by A14,A15,Th18;
      hence thesis by A15,A16,Th4;
    end;
  end;
  thus for t being Term of S,Y holds P[t] from MSATERM:sch 1(A13,A2);
end;
