reserve S for OrderSortedSign;
reserve S for OrderSortedSign,
  X for ManySortedSet 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 Th38:
  for S be locally_directed OrderSortedSign, X be non-empty
  ManySortedSet of S holds OSFreeGen(X) is osfree
proof
  let S be locally_directed OrderSortedSign, X be non-empty ManySortedSet of S;
  set FA = FreeOSA(X), PTA = ParsedTermsOSA(X), SPTA = the Sorts of PTA, FG =
  OSFreeGen(X);
  let U1 be non-empty monotone OSAlgebra of S, F be ManySortedFunction of FG,
  the Sorts of U1;
  set SA =the Sorts of FA, S1 = the Sorts of U1, R = LCongruence(X), NH =
  OSNat_Hom(PTA,R);
  reconsider NH1= NH as ManySortedFunction of PTA, FA;
  set NHP = (NH1 || PTVars(X));
A1: now
    let s be Element of S;
A2: NHP.s = (NH1.s) | ((PTVars(X)).s) by MSAFREE:def 1;
    hence NHP.s = (NH1.s) | (PTVars(s,X)) by Def24;
    thus PTVars(s,X) c= SPTA.s;
    thus dom (NH1.s) = SPTA.s & rng (NH1.s) c= SA.s by FUNCT_2:def 1
,RELAT_1:def 19;
A3: (PTVars(X)).s = PTVars(s,X) by Def24;
    hence
A4: dom (NHP.s) = PTVars(s,X) by FUNCT_2:def 1;
    for y being object holds
     y in FG.s iff (ex x being object st x in dom (NHP.
    s) & y = (NHP.s).x)
    proof
      let y be object;
      thus y in FG.s implies
ex x being object st x in dom (NHP.s) & y = (NHP.s).
      x
      proof
        assume y in FG.s;
        then y in OSFreeGen(s,X) by Def26;
        then consider a be object such that
A5:     a in X.s and
A6:     y = (NH.s).(root-tree [a,s]) by Def25;
        take x = root-tree [a,s];
        root-tree [a,s] in dom (NHP.s) by A4,A5,Def23;
        hence thesis by A2,A6,FUNCT_1:47;
      end;
      given x being object such that
A7:   x in dom (NHP.s) and
A8:   y = (NHP.s).x;
      consider a be object such that
A9:   a in X.s and
A10:  x = root-tree [a,s] by A3,A7,Def23;
      y = (NH.s).(root-tree [a,s]) by A2,A7,A8,A10,FUNCT_1:47;
      then y in OSFreeGen(s,X) by A9,Def25;
      hence thesis by Def26;
    end;
    hence
A11: rng (NHP.s) = FG.s by FUNCT_1:def 3;
    hence NHP.s is Function of PTVars(s,X),FG.s by A4,FUNCT_2:1;
    thus NHP.s is Function of (PTVars(X)).s,FG.s by A3,A4,A11,FUNCT_2:1;
  end;
  then for i being object st i in the carrier of S
    holds NHP.i is Function of (PTVars X).i, FG.i;
  then reconsider
  NHP = (NH1 || PTVars(X)) as ManySortedFunction of PTVars(X),FG by
PBOOLE:def 15;
  consider h being ManySortedFunction of PTA,U1 such that
A12: h is_homomorphism PTA,U1 and
A13: h is order-sorted and
A14: h || PTVars(X) = F ** NHP by Th37;
  reconsider hCng = OSCng(h) as monotone OSCongruence of PTA by A12,A13,
OSALG_4:24;
  reconsider H = OSHomQuot(h,R) as ManySortedFunction of FA,U1;
  take H;
A15: R c= hCng by Def17;
  hence H is_homomorphism FA,U1 & H is order-sorted by A12,A13,OSALG_4:25;
  for s be Element of S holds F.s = (H.s) | (FG.s)
  proof
    let s be Element of S;
A16: FG.s = OSFreeGen(s,X) by Def26;
    then FG.s c= SA.s;
    then FG.s c= dom OSHomQuot(h,R,s) by FUNCT_2:def 1;
    then
A17: dom (OSHomQuot(h,R,s) | (FG.s)) = FG.s by RELAT_1:62;
    rng (OSHomQuot(h,R,s) | (FG.s)) c= S1.s by RELAT_1:def 19;
    then reconsider
    OSF = OSHomQuot(h,R,s) | (FG.s) as Function of FG.s,S1.s by A17,FUNCT_2:2;
    now
A18:  dom (NHP.s) = PTVars(s,X) by A1;
A19:  ((h.s) | ((PTVars(X)).s)) = (F ** NHP).s by A14,MSAFREE:def 1
        .= (F.s )*(NHP.s) by MSUALG_3:2;
      let x be object such that
A20:  x in FG.s;
      consider a being object such that
A21:  a in X.s and
A22:  x = (NH.s).(root-tree [a,s]) by A16,A20,Def25;
      reconsider xa = root-tree [a,s] as Element of SPTA.s by A21,Th10;
A23:  OSClass(R,xa) = (OSNat_Hom(PTA,R,s)).xa by OSALG_4:def 21
        .= x by A22,OSALG_4:def 22;
A24:  root-tree [a,s] in PTVars(s,X) by A21,Def23;
      then xa in (PTVars(X)).s by Def24;
      then
A25:  (h.s).xa = (h.s | ((PTVars(X)).s)).xa by FUNCT_1:49;
A26:  (OSHomQuot(h,R,s)).(OSClass(R,xa)) = (h.s).xa by A12,A13,A15,
OSALG_4:def 27;
      (NHP.s).xa = ((NH.s) | (PTVars(s,X))).xa by A1
        .= (NH.s).xa by A24,FUNCT_1:49;
      then (h.s).xa = (F.s).x by A22,A24,A19,A25,A18,FUNCT_1:13;
      hence (F.s).x = (OSHomQuot(h,R,s) | (FG.s)).x by A20,A23,A26,FUNCT_1:49;
    end;
    then F.s = OSF by FUNCT_2:12;
    hence thesis by OSALG_4:def 28;
  end;
  then
  for i be set st i in the carrier of S holds F.i = (H.i) | (FG.i);
  hence thesis by MSAFREE:def 1;
end;
