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

theorem
  for U1 be non-empty OSAlgebra of S, R be OSCongruence of U1 holds
  OSNat_Hom(U1,R) is_epimorphism U1, QuotOSAlg (U1,R) & OSNat_Hom(U1,R) is
  order-sorted
proof
  let U1 be non-empty OSAlgebra of S, R be OSCongruence of U1;
  set F = OSNat_Hom(U1,R), QA = QuotOSAlg (U1,R), S1 = the Sorts of U1;
  for o be Element of the carrier' of S st Args (o,U1) <> {} for x be
Element of Args(o,U1) holds (F.(the_result_sort_of o)).(Den(o,U1).x) = Den(o,QA
  ).(F#x)
  proof
    let o be Element of the carrier' of S such that
    Args (o,U1) <> {};
    let x be Element of Args(o,U1);
    set ro = the_result_sort_of o, ar = the_arity_of o;
    (the Arity of S).o = ar by MSUALG_1:def 1;
    then
A1: ((OSClass R)# * the Arity of S).o = product ((OSClass R) * ar) by MSAFREE:1
;
A2: dom x = dom ar by MSUALG_3:6;
A3: for a be object st a in dom ar holds (F#x).a = (R #_os x).a
    proof
      let a be object;
      assume
A4:   a in dom ar;
      then reconsider n = a as Nat;
      set Fo = OSNat_Hom(U1,R,((ar)/.n)), s = ((ar)/.n);
A5:   ex z being Element of S1.s st z = x.n & (R #_os x).n = OSClass(R,z)
      by A4,Def13;
A6:   n in dom ((the Sorts of U1) * ar) by A4,PARTFUN1:def 2;
      then ((the Sorts of U1) * ar).n = (the Sorts of U1).(ar.n) by FUNCT_1:12
        .= S1.s by A4,PARTFUN1:def 6;
      then reconsider xn = x.n as Element of S1.s by A6,MSUALG_3:6;
      thus (F#x).a = (F.((ar)/.n)).(x.n) by A2,A4,MSUALG_3:def 6
        .= Fo.xn by Def22
        .= (R #_os x).a by A5,Def21;
    end;
    dom (the Sorts of U1) = the carrier of S by PARTFUN1:def 2;
    then rng (the ResultSort of S) c= dom (the Sorts of U1);
    then
    dom (the ResultSort of S) = the carrier' of S & dom ((the Sorts of U1
    ) * the ResultSort of S) = dom (the ResultSort of S) by FUNCT_2:def 1
,RELAT_1:27;
    then
A7: ((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 reconsider dx = (Den(o,U1)).x as Element of S1.ro by MSUALG_1:def 5;
    rng Den(o,U1) c= Result(o,U1) & Result(o,U1) = S1.ro by A7,MSUALG_1:def 5;
    then rng Den(o,U1) c= dom OSQuotRes(R,o) by A7,FUNCT_2:def 1;
    then
A8: dom Den(o,U1) = Args(o,U1) & dom ((OSQuotRes(R,o)) * Den(o,U1)) = dom
    Den(o, U1) by FUNCT_2:def 1,RELAT_1:27;
    dom (OSClass R) = the carrier of S by PARTFUN1:def 2;
    then
    dom (R #_os x) = dom ((OSClass R) * (the_arity_of o)) & rng ar c= dom
    ( OSClass R) by CARD_3:9;
    then dom (F#x) = dom ar & dom (R #_os x) = dom ar by MSUALG_3:6,RELAT_1:27;
    then
A9: F # x = R #_os x by A3,FUNCT_1:2;
    Den(o,QA) = (OSQuotCharact R).o by MSUALG_1:def 6
      .= OSQuotCharact(R,o) by Def19;
    then Den(o,QA).(F#x) = ((OSQuotRes(R,o)) * (Den(o,U1))).x by A1,A9,Def18
      .= (OSQuotRes(R,o)) . dx by A8,FUNCT_1:12
      .= OSClass (R, dx) by Def14
      .= (OSNat_Hom(U1,R,ro)).dx by Def21
      .= (F.ro).((Den(o,U1)).x) by Def22;
    hence thesis;
  end;
  hence F is_homomorphism U1,QA;
  for i be set st i in the carrier of S holds rng (F.i) = (the Sorts of QA).i
  proof
    let i be set;
    assume i in the carrier of S;
    then reconsider s = i as Element of S;
    reconsider f = F.i as Function of S1.s, (the Sorts of QA).s by
PBOOLE:def 15;
A10: dom f = S1.s by FUNCT_2:def 1;
A11: (the Sorts of QA).s = OSClass (R,s) by Def11;
    for x be object st x in (the Sorts of QA).i holds x in rng f
    proof
      let x be object;
A12:  f = OSNat_Hom(U1,R,s) by Def22;
      assume x in (the Sorts of QA).i;
      then consider a1 being set such that
A13:  a1 in S1.s and
A14:  x = Class(CompClass(R,CComp(s)),a1) by A11,Def10;
      reconsider a2 = a1 as Element of S1.s by A13;
      OSClass(R,a2) = x & f.a1 in rng f by A10,A13,A14,FUNCT_1:def 3;
      hence thesis by A12,Def21;
    end;
    then (the Sorts of QA).i c= rng f;
    hence thesis;
  end;
  hence F is "onto";
  thus F is order-sorted
  proof
    reconsider S2 = S1 as OrderSortedSet of S by OSALG_1:17;
    let s1,s2 be Element of S such that
A15: s1 <= s2;
A16: S2.s1 c= S2.s2 by A15,OSALG_1:def 16;
    let a1 be set such that
A17: a1 in dom (F.s1);
A18: a1 in S1.s1 by A17;
    then reconsider b2 = a1 as Element of S1.s2 by A16;
    dom (F.s2) = S1.s2 by FUNCT_2:def 1;
    hence a1 in dom (F.s2) by A16,A18;
    reconsider b1 = a1 as Element of S1.s1 by A17;
    thus (F.s1).a1 = OSNat_Hom(U1,R,s1).b1 by Def22
      .= OSClass(R,b1) by Def21
      .= OSClass(R,b2) by A15,Th4
      .= OSNat_Hom(U1,R,s2).b2 by Def21
      .= (F.s2).a1 by Def22;
  end;
end;
