reserve S for non empty non void ManySortedSign;
reserve X for non-empty ManySortedSet of S;
reserve x,y,z for set, i,j for Nat;
reserve
  A0 for (X,S)-terms non-empty MSAlgebra over S,
  A1 for all_vars_including (X,S)-terms MSAlgebra over S,
  A2 for all_vars_including inheriting_operations (X,S)-terms MSAlgebra over S,
  A for all_vars_including inheriting_operations free_in_itself
  (X,S)-terms MSAlgebra over S;
reserve X0 for non-empty countable ManySortedSet of S;
reserve A0 for all_vars_including inheriting_operations free_in_itself
  (X0,S)-terms MSAlgebra over S;

theorem Th65:
  for h being ManySortedFunction of Free(S,X), A st
  h is_homomorphism Free(S,X), A
  ex g being ManySortedFunction of A,A st
  g is_homomorphism A,A & h = g**canonical_homomorphism A
  proof set X0 = X;
    let h be ManySortedFunction of Free(S,X0), A such that
A1: h is_homomorphism Free(S,X0), A;
    set ww = canonical_homomorphism A;
    reconsider H = FreeGen X0 as GeneratorSet of Free(S,X0) by Th45;
    reconsider G = FreeGen X0 as GeneratorSet of A by Th45;
A2: now
      let s be SortSymbol of S, i be Element of X0.s;
      root-tree [i,s] in FreeGen(s,X0) by MSAFREE:def 15;
      then A3: root-tree [i,s] in H.s by MSAFREE:def 16;
      G c= the Sorts of A by PBOOLE:def 18;
      then H.s c= (the Sorts of A).s;
      hence ww.s.root-tree [i,s] = root-tree [i, s] by A3,Th47;
    end; then
A4: ww is_homomorphism Free(S,X0), A &
    for s being SortSymbol of S, i being Element of X0.s holds
    ww.s.root-tree [i,s] = root-tree [i, s] by Def10;
    reconsider hG = h||H as ManySortedFunction of
    G qua ManySortedSet of S, the Sorts of A;
    consider g being ManySortedFunction of A,A such that
A5: g is_homomorphism A,A & g||G = hG by Def9;
    take g;
    thus g is_homomorphism A,A by A5;
A6: g**ww is_homomorphism Free(S,X0),A by A4,A5,MSUALG_3:10;
    now
      let x be object; assume x in the carrier of S;
      then reconsider s = x as SortSymbol of S;
A7:   dom ((h||H).s) = H.s & dom (((g**ww)||H).s) = H.s by FUNCT_2:def 1;
      now let y be object; assume
A8:     y in H.s; then y in FreeGen(s,X0) by MSAFREE:def 16;
        then consider z such that
A9:     z in X0.s & y = root-tree [z,s] by MSAFREE:def 15;
A10:     ww.s.y = root-tree[z,s] by A2,A9;
        then ww.s.y in FreeGen(s,X0) by A9,MSAFREE:def 15;
        then
A11:     ww.s.y in G.s by MSAFREE:def 16;
A12:     H.s c= (the Sorts of Free(S,X0)).s by PBOOLE:def 2,def 18;
A13:     dom (g**ww) = (the carrier of S)/\the carrier of S
        by PARTFUN1:def 2;
        thus (h||H).x .y
        = ((g.s)|(G.s)).(ww.s.y) by A9,A10,A5,MSAFREE:def 1
        .= g.s.(ww.s.y) by A11,FUNCT_1:49
        .= ((g.s)*(ww.s)).y by A8,A12,FUNCT_2:15
        .= ((g**ww).s).y by A13,PBOOLE:def 19
        .= (((g**ww).s)|(H.s)).y by A8,FUNCT_1:49
        .= ((g**ww)||H).x .y by MSAFREE:def 1;
      end;
      hence (h||H).x = ((g**ww)||H).x by A7;
    end;
    hence h = g**ww by A1,A6,EXTENS_1:19,PBOOLE:3;
  end;
