reserve S for non void non empty ManySortedSign,
  U1, U2, U3 for non-empty MSAlgebra over S,
  I for set,
  A for ManySortedSet of I,
  B, C for non-empty ManySortedSet of I;

theorem
  for F be ManySortedFunction of U2, U3 st F is_homomorphism U2, U3
holds F is_monomorphism U2, U3 iff for U1 be non-empty MSAlgebra over S for h1,
  h2 be ManySortedFunction of U1, U2 st h1 is_homomorphism U1, U2 & h2
  is_homomorphism U1, U2 holds (F**h1 = F**h2 implies h1 = h2)
proof
  let F be ManySortedFunction of U2, U3 such that
A1: F is_homomorphism U2, U3;
  set C = the Sorts of U3;
  set B = the Sorts of U2;
  thus F is_monomorphism U2, U3 implies for U1 be non-empty MSAlgebra over S
  for h1, h2 be ManySortedFunction of U1, U2 st h1 is_homomorphism U1, U2 & h2
  is_homomorphism U1, U2 holds (F**h1 = F**h2 implies h1 = h2)
  by Th13;
  set I = the carrier of S;
  assume that
A2: for U1 be non-empty MSAlgebra over S for h1, h2 be
ManySortedFunction of U1, U2 st h1 is_homomorphism U1, U2 & h2 is_homomorphism
  U1, U2 holds F**h1 = F**h2 implies h1 = h2 and
A3: not F is_monomorphism U2, U3;
  not F is "1-1" by A1,A3;
  then consider j be set such that
A4: j in I and
A5: not F.j is one-to-one by MSUALG_3:1;
  set f = F.j;
  F.j is Function of B.j, C.j by A4,PBOOLE:def 15;
  then consider x1, x2 be object such that
A6: x1 in B.j and
A7: x2 in B.j and
A8: f.x1 = f.x2 and
A9: x1 <> x2 by A4,A5,FUNCT_2:19;
  ex U1 be non-empty MSAlgebra over S st ex h1, h2 be ManySortedFunction
  of the Sorts of U1, the Sorts of U2 st h1 is_homomorphism U1, U2 & h2
  is_homomorphism U1, U2 & F**h1 = F**h2 & h1 <> h2
  proof
    take U1 = FreeMSA the Sorts of U2;
    reconsider FG = FreeGen(B) as GeneratorSet of U1;
    FG is non-empty by MSAFREE:14;
    then reconsider FGj = FG.j, Bj = B.j as non empty set by A4;
    reconsider h = FGj --> x2 as Function of FGj, Bj by A7,FUNCOP_1:45;
    reconsider g = FGj --> x1 as Function of FGj, Bj by A6,FUNCOP_1:45;
    set r = Reverse(B);
    deffunc F(object) = IFEQ($1, j, g, r.$1);
    consider G be ManySortedSet of I such that
A10: for i be object st i in I holds G.i = F(i) from PBOOLE:sch 4;
    deffunc F(object) = IFEQ($1, j, h, r.$1);
    consider H be ManySortedSet of I such that
A11: for i be object st i in I holds H.i = F(i) from PBOOLE:sch 4;
    now
      let G be ManySortedSet of I;
      let g, h be Function of FGj, Bj such that
A12:  for i be object st i in I holds G.i = IFEQ(i, j, g, r.i);
      thus G is Function-yielding
      proof
        let i be object;
        assume i in dom G;
        then
A13:    i in I;
        now
          per cases;
          case
            i = j;
            then IFEQ(i, j, g, r.i) = g by FUNCOP_1:def 8;
            hence thesis by A12,A13;
          end;
          case
            i <> j;
            then IFEQ(i, j, g, r.i) = r.i by FUNCOP_1:def 8;
            hence thesis by A12,A13;
          end;
        end;
        hence thesis;
      end;
    end;
    then reconsider G, H as ManySortedFunction of I by A10,A11;
    now
      let G be ManySortedFunction of I;
      let g, h be Function of FGj, Bj such that
A14:  for i be object st i in I holds G.i = IFEQ(i, j, g, r.i);
      thus G is ManySortedFunction of FG, B
      proof
        let i be object such that
A15:    i in I;
        now
          per cases;
          case
A16:        i = j;
            then IFEQ(i, j, g, r.i) = g by FUNCOP_1:def 8;
            hence thesis by A14,A15,A16;
          end;
          case
            i <> j;
            then IFEQ(i, j, g, r.i) = r.i by FUNCOP_1:def 8;
            then G.i = r.i by A14,A15;
            hence thesis by A15,PBOOLE:def 15;
          end;
        end;
        hence thesis;
      end;
    end;
    then reconsider G, H as ManySortedFunction of FG, B by A10,A11;
A17: FG is free by MSAFREE:16;
    then consider h1 be ManySortedFunction of U1, U2 such that
A18: h1 is_homomorphism U1, U2 and
A19: h1 || FG = G by MSAFREE:def 5;
    consider h2 be ManySortedFunction of U1, U2 such that
A20: h2 is_homomorphism U1, U2 and
A21: h2 || FG = H by A17,MSAFREE:def 5;
    take h1, h2;
    thus h1 is_homomorphism U1, U2 & h2 is_homomorphism U1, U2 by A18,A20;
    reconsider Fh1 = F**h1, Fh2 = F**h2 as ManySortedFunction of U1, U3;
A22: Fh1 is_homomorphism U1, U3 by A1,A18,MSUALG_3:10;
    now
      let i be object;
      assume
A23:  i in I;
      now
        per cases;
        case
A24:      i = j;
          then
A25:      f is Function of B.i, C.i by A4,PBOOLE:def 15;
          then reconsider fg = f*g as Function of FGj, C.i by A24,FUNCT_2:13;
          reconsider fh = f*h as Function of FGj, C.i by A24,A25,FUNCT_2:13;
          now
            let x be object;
            assume
A26:        x in FGj;
            hence fg.x = f.(g.x) by FUNCT_2:15
              .= f.x2 by A8,A26,FUNCOP_1:7
              .= f.(h.x) by A26,FUNCOP_1:7
              .= fh.x by A26,FUNCT_2:15;
          end;
          then
A27:      f*g = f*h by FUNCT_2:12;
          IFEQ(i, j, g, r.i) = g by A24,FUNCOP_1:def 8;
          then g = (h1 || FG).i by A10,A19,A23;
          then
A28:      (F**(h1 || FG)).i = f*g by A4,A24,MSUALG_3:2;
          IFEQ(i, j, h, r.i) = h by A24,FUNCOP_1:def 8;
          then h = (h2 || FG).i by A11,A21,A23;
          hence (F**(h1 || FG)).i = (F**(h2 || FG)).i by A4,A24,A27,A28,
MSUALG_3:2;
        end;
        case
A29:      i <> j;
          reconsider f9 = F.i as Function of B.i, C.i by A23,PBOOLE:def 15;
          reconsider h29 = (h2 || FG).i as Function of FG.i, B.i by A23,
PBOOLE:def 15;
A30:      IFEQ(i, j, h, r.i) = r.i by A29,FUNCOP_1:def 8;
          IFEQ(i, j, g, r.i) = r.i by A29,FUNCOP_1:def 8;
          then (h1 || FG).i = r.i by A10,A19,A23
            .= (h2 || FG).i by A11,A21,A23,A30;
          hence (F**(h1 || FG)).i = f9*h29 by A23,MSUALG_3:2
            .= (F**(h2 || FG)).i by A23,MSUALG_3:2;
        end;
      end;
      hence (F**(h1 || FG)).i = (F**(h2 || FG)).i;
    end;
    then
A31: F**(h1 || FG) = F**(h2 || FG);
A32: Fh2 is_homomorphism U1, U3 by A1,A20,MSUALG_3:10;
    (F**h1) || FG = F**(h1 || FG) by Th4
      .= (F**h2) || FG by A31,Th4;
    hence F**h1 = F**h2 by A22,A32,Th14;
    now
      take i = j;
      thus i in I by A4;
A33:  now
        let x be Element of FGj;
        assume g = h;
        then g.x = x2 by FUNCOP_1:7;
        hence contradiction by A9;
      end;
A34:  h = IFEQ(i, j, h, r.i) by FUNCOP_1:def 8
        .= H.i by A4,A11;
      g = IFEQ(i, j, g, r.i) by FUNCOP_1:def 8
        .= G.i by A4,A10;
      hence G <> H by A34,A33;
    end;
    hence thesis by A19,A21;
  end;
  hence contradiction by A2;
end;
