reserve x,y,z for set;

theorem Th24:
  for S being non void Signature
  for X being ManySortedSet of the carrier of S
 holds the Sorts of Free(S, X)
   = S-Terms(X, X (\/) ((the carrier of S)-->{0}))
proof
  let S be non void Signature;
  let X be ManySortedSet of the carrier of S;
  set Y = X (\/) ((the carrier of S)-->{0});
  set B = MSAlgebra(# S-Terms(X, Y), Opers(FreeMSA Y, S-Terms(X, Y)) #);
  for Z being MSSubset of FreeMSA Y st Z = the Sorts of B holds Z is
  opers_closed & the Charact of B = Opers(FreeMSA Y, Z) by Th21;
  then reconsider B as MSSubAlgebra of FreeMSA Y by MSUALG_2:def 9;
A1: FreeMSA Y = MSAlgebra(#FreeSort Y, FreeOper Y#) & dom FreeSort Y = the
  carrier of S by MSAFREE:def 14,PARTFUN1:def 2;
  (Reverse Y)""X c= S-Terms(X, Y) by Th22;
  then
A2: (Reverse Y)""X is MSSubset of B by PBOOLE:def 18;
  let s be Element of S;
  ex A being MSSubset of FreeMSA Y st Free(S, X) = GenMSAlg A & A = (
  Reverse Y)""X by Def1;
  then Free(S, X) is MSSubAlgebra of B by A2,MSUALG_2:def 17;
  then the Sorts of Free(S, X) is MSSubset of B by MSUALG_2:def 9;
  then the Sorts of Free(S, X) c= S-Terms(X, Y) by PBOOLE:def 18;
  hence (the Sorts of Free(S, X)).s c= S-Terms(X, Y).s;
  let x be object;
  assume
A3: x in S-Terms(X, Y).s;
  S-Terms(X, Y) c= the Sorts of FreeMSA Y by PBOOLE:def 18;
  then (S-Terms(X, Y)).s c= (the Sorts of FreeMSA Y).s;
  then x in Union FreeSort Y by A3,A1,CARD_5:2;
  then x is Term of S,Y by MSATERM:13;
  hence thesis by A3,Th23;
end;
