reserve S for locally_directed OrderSortedSign;
reserve o for Element of the carrier' of S;

theorem Th17:
  for U1,U2 be non-empty OSAlgebra of S, F be ManySortedFunction
  of U1,U2 st F is_homomorphism U1,U2 & F is order-sorted holds OSHomQuot(F)
  is_monomorphism QuotOSAlg (U1,OSCng F),U2 & OSHomQuot(F) is order-sorted
proof
  let U1,U2 be non-empty OSAlgebra of S, F be ManySortedFunction of U1,U2;
  set mc = OSCng(F), qa = QuotOSAlg (U1,mc), qh = OSHomQuot(F), S1 = the Sorts
  of U1;
  assume that
A1: F is_homomorphism U1,U2 and
A2: F is order-sorted;
  for o be Element of the carrier' of S st Args (o,qa) <> {} for x be
Element of Args(o,qa) holds (qh.(the_result_sort_of o)).(Den(o,qa).x) = Den(o,
  U2).(qh#x)
  proof
    let o be Element of the carrier' of S such that
    Args (o,qa) <> {};
    let x be Element of Args(o,qa);
    reconsider o1 = o as OperSymbol of S;
    set ro = the_result_sort_of o, ar = the_arity_of o;
A3: dom x = dom ar by MSUALG_3:6;
    Args(o,qa) = ((OSClass mc)# * (the Arity of S)).o by MSUALG_1:def 4;
    then consider a be Element of Args(o,U1) such that
A4: x = mc #_os a by Th14;
A5: dom a = dom ar by MSUALG_3:6;
A6: now
      let y be object;
      assume
A7:   y in dom ar;
      then reconsider n = y as Nat;
      ar.n in rng ar by A7,FUNCT_1:def 3;
      then reconsider s = ar.n as SortSymbol of S;
A8:   ar/.n = ar.n by A7,PARTFUN1:def 6;
      then consider an being Element of S1.s such that
A9:   an = a.n and
A10:  x.n = OSClass(mc,an) by A4,A7,Def13;
      (qh # x).n = (qh.s).(x.n) by A3,A7,A8,MSUALG_3:def 6
        .= OSHomQuot(F,s).OSClass(mc,an) by A10,Def25
        .= (F.s).an by A1,A2,Def24
        .= (F # a).n by A5,A7,A8,A9,MSUALG_3:def 6;
      hence (qh # x).y = (F # a).y;
    end;
    o in the carrier' of S;
    then o in dom (S1 * the ResultSort of S) by PARTFUN1:def 2;
    then
A11: ((the Sorts of U1) * the ResultSort of S).o = (the Sorts of U1).((the
    ResultSort of S).o) by FUNCT_1:12
      .= (the Sorts of U1).ro by MSUALG_1:def 2;
    then rng Den(o,U1) c= Result(o,U1) & Result(o,U1) = S1.ro by MSUALG_1:def 5
;
    then rng Den(o,U1) c= dom OSQuotRes(mc,o) by A11,FUNCT_2:def 1;
    then
A12: dom Den(o,U1) = Args(o,U1) & dom ((OSQuotRes(mc,o)) * Den(o,U1)) =
    dom Den(o,U1) by FUNCT_2:def 1,RELAT_1:27;
    ar = (the Arity of S).o by MSUALG_1:def 1;
    then
A13: product((OSClass mc) * ar) = ((OSClass mc)# * the Arity of S).o by
MSAFREE:1;
    reconsider da = (Den(o,U1)).a as Element of S1.ro by A11,MSUALG_1:def 5;
A14: qh.ro = OSHomQuot(F,ro) by Def25;
    Den(o,qa) = (OSQuotCharact mc).o by MSUALG_1:def 6
      .= OSQuotCharact(mc,o1) by Def19;
    then Den(o,qa).x = (OSQuotRes(mc,o) * Den(o,U1)).a by A4,A13,Def18
      .= (OSQuotRes(mc,o)) . da by A12,FUNCT_1:12
      .= OSClass (OSCng(F),da) by Def14;
    then
A15: (qh.ro).(Den(o,qa).x) = (F.ro).((Den(o,U1)).a) by A1,A2,A14,Def24
      .= Den(o,U2).(F#a) by A1;
    dom (qh # x) = dom ar & dom (F # a) = dom ar by MSUALG_3:6;
    hence thesis by A6,A15,FUNCT_1:2;
  end;
  hence qh is_homomorphism qa,U2;
  for i be set st i in the carrier of S holds (qh.i) is one-to-one
  proof
    let i be set;
    set f = qh.i;
    assume i in the carrier of S;
    then reconsider s = i as SortSymbol of S;
A16: f = OSHomQuot(F,s) by Def25;
    for x1,x2 be object st x1 in dom f & x2 in dom f & f.x1 = f.x2
holds x1 = x2
    proof
      let x1,x2 be object;
      assume that
A17:  x1 in dom f and
A18:  x2 in dom f and
A19:  f.x1 = f.x2;
      x2 in (OSClass mc).s by A16,A18,FUNCT_2:def 1;
      then x2 in OSClass (mc,s) by Def11;
      then consider a2 being set such that
A20:  a2 in S1.s and
A21:  x2 = Class( CompClass(OSCng(F),CComp(s)), a2) by Def10;
      reconsider a2 as Element of S1.s by A20;
A22:  x2 = OSClass(OSCng(F),a2) by A21;
      x1 in (OSClass mc).s by A16,A17,FUNCT_2:def 1;
      then x1 in OSClass (mc,s) by Def11;
      then consider a1 being set such that
A23:  a1 in S1.s and
A24:  x1 = Class( CompClass(OSCng(F),CComp(s)), a1) by Def10;
      reconsider a1 as Element of S1.s by A23;
      (F.s).a1 = f.(OSClass(OSCng(F),a1)) & (F.s).a2 = f.(OSClass(OSCng(F
      ),a2)) by A1,A2,A16,Def24;
      then [a1,a2] in MSCng(F,s) by A19,A24,A21,MSUALG_4:def 17;
      then [a1,a2] in (MSCng(F)).s by A1,MSUALG_4:def 18;
      then
A25:  [a1,a2] in (OSCng(F)).s by A1,A2,Def23;
      x1 = OSClass(OSCng(F),a1) by A24;
      hence thesis by A22,A25,Th12;
    end;
    hence thesis by FUNCT_1:def 4;
  end;
  hence qh is "1-1" by MSUALG_3:1;
  thus OSHomQuot(F) is order-sorted
  proof
    reconsider S1O = S1 as OrderSortedSet of S by OSALG_1:17;
    reconsider sqa = the Sorts of qa as OrderSortedSet of S;
    let s1,s2 being Element of S such that
A26: s1 <= s2;
    let a1 be set such that
A27: a1 in dom (qh.s1);
    a1 in (OSClass OSCng(F)).s1 by A27;
    then a1 in OSClass (OSCng(F),s1) by Def11;
    then consider x being set such that
A28: x in S1.s1 and
A29: a1 = Class( CompClass(OSCng(F),CComp(s1)), x) by Def10;
    S1O.s1 c= S1O.s2 by A26,OSALG_1:def 16;
    then reconsider x2 = x as Element of S1.s2 by A28;
A30: a1 = OSClass(OSCng(F),x2) by A26,A29,Th4;
    reconsider s3 = s1, s4 = s2 as Element of S;
A31: dom (qh.s1) = (the Sorts of qa).s1 & dom (qh.s2) = (the Sorts of qa).
    s2 by FUNCT_2:def 1;
    reconsider x1 = x as Element of S1.s1 by A28;
    x1 in dom (F.s3) by A28,FUNCT_2:def 1;
    then
A32: (F.s3).x1 = (F.s4).x1 by A2,A26;
    sqa.s1 c= sqa.s2 by A26,OSALG_1:def 16;
    hence a1 in dom (qh.s2) by A27,A31;
    thus (qh.s1).a1 = OSHomQuot(F,s1).(OSClass(OSCng(F),x1)) by A29,Def25
      .= (F.s2).x1 by A1,A2,A32,Def24
      .= OSHomQuot(F,s2).(OSClass(OSCng(F),x2)) by A1,A2,Def24
      .= (qh.s2).a1 by A30,Def25;
  end;
end;
