reserve i for Nat, x,y for set;
reserve S for non empty non void ManySortedSign;
reserve X for non-empty ManySortedSet of S;

theorem Th34:
  for S being non empty non void ManySortedSign
  for X being non-empty ManySortedSet of the carrier of S
  for A being all_vars_including inheriting_operations free_in_itself
  (X,S)-terms MSAlgebra over S
  ex VF being ManySortedMSSet of the Sorts of A,the Sorts of A,
  B being all_vars_including inheriting_operations free_in_itself (X,S)-terms
  VarMSAlgebra over S
  st B = VarMSAlgebra(#the Sorts of A, the Charact of A, VF#) &
  B is vf-free
  proof
    let S be non empty non void ManySortedSign;
    let X be non-empty ManySortedSet of the carrier of S;
    let A be all_vars_including inheriting_operations free_in_itself
    (X,S)-terms (X,S)-terms MSAlgebra over S;
    deffunc F((Element of S),(Element of S),Element of A,$1) =
    {$3|p where p is Element of dom $3: (($3|p).{})`2 = $2};
A1: for s,r being SortSymbol of S for t being Element of A,s holds
    F(s,r,t) is Subset of (the Sorts of A).r
    proof
      let s,r be SortSymbol of S;
      let t be Element of (the Sorts of A).s;
      F(s,r,t) c= (the Sorts of A).r
      proof
        let x be object; assume x in F(s,r,t); then
        consider p being Element of dom t such that
A2:     x = t|p & ((t|p).{})`2 = r;
        reconsider tp = t|p as Element of A by MSAFREE4:44;
        reconsider t1 = tp as Term of S,X by MSAFREE4:42;
        per cases by MSATERM:2;
        suppose
          ex s being SortSymbol of S, v being Element of X.s st t1.{} = [v,s];
          then consider s1 being SortSymbol of S, v being Element of X.s1
          such that
A3:       tp.{} = [v,s1];
A4:       s1 = r by A2,A3; then
          t1 = root-tree [v,r] by A3,MSATERM:5; then
          the_sort_of t1 = r by A4,MSATERM:14; then
          t1 in FreeSort(X,r) by MSATERM:def 5; then
          tp in (the Sorts of FreeMSA X).r by MSAFREE:def 11; then
          tp in (the Sorts of Free(S,X)).r by MSAFREE3:31;
          hence thesis by A2,MSAFREE4:43;
        end;
        suppose tp.{} in [:the carrier' of S,{the carrier of S}:]; then
          (tp.{})`2 in {the carrier of S} by MCART_1:10; then
          r = the carrier of S & r in the carrier of S by A2,TARSKI:def 1;
          hence thesis;
        end;
      end;
      hence F(s,r,t) is Subset of (the Sorts of A).r;
    end;
    consider v being ManySortedMSSet of the Sorts of A,the Sorts of A such that
A5: for x,z being Element of the carrier of S
    for y being Element of (the Sorts of A).x holds v.x.y.z = F(x,z,y)
    from Scheme(A1);
    set B = VarMSAlgebra(#the Sorts of A, the Charact of A, v#);
    take v;
 B is (X,S)-terms
    proof
      thus the Sorts of B is ManySortedSubset of the Sorts of Free(S,X)
      by MSAFREE4:def 6;
    end;
    then reconsider B as (X,S)-terms strict VarMSAlgebra over S;
    B is all_vars_including inheriting_operations free_in_itself
    proof
      thus FreeGen X is ManySortedSubset of the Sorts of B by MSAFREE4:def 7;
      hereby
        let o be OperSymbol of S, p be FinSequence; assume
        p in Args(o, Free(S,X)) &
        Den(o,Free(S,X)).p in (the Sorts of B).the_result_sort_of o; then
        p in Args(o,A) & Den(o,A).p = Den(o,Free(S,X)).p by MSAFREE4:def 8;
        hence p in Args(o,B) & Den(o,B).p = Den(o,Free(S,X)).p;
      end;
      let f be ManySortedFunction of FreeGen X, the Sorts of B;
      let G be ManySortedSubset of the Sorts of B such that
A7:   G = FreeGen X;
      reconsider H = G as MSSubset of A;
      consider h being ManySortedFunction of A,A such that
A8:   h is_homomorphism A,A & f = h || H by A7,MSAFREE4:def 9;
      reconsider g = h as ManySortedFunction of B,B;
      take g;
      the MSAlgebra of B = the MSAlgebra of A;
      hence g is_homomorphism B,B by A8,MSAFREE4:30;
      thus thesis by A8;
    end;
    then reconsider B as all_vars_including inheriting_operations
    free_in_itself (X,S)-terms strict VarMSAlgebra over S;
    B is vf-free
    by A5;
    hence thesis;
  end;
