
theorem
  for X being non empty with_non-empty_elements set for o1,o2 being
  Object of EnsCat X st <^o1,o2^> <> {} for A being Morphism of o1,o2, F being
  Function of o1,o2 st F = A holds A is epi iff F is onto
proof
  let X be non empty with_non-empty_elements set, o1,o2 be Object of EnsCat X;
  assume
A1: <^o1,o2^> <> {};
  let A be Morphism of o1,o2, F be Function of o1,o2;
  assume
A2: F = A;
  per cases;
  suppose
A3: for x be set st x in X holds x is trivial;
    thus A is epi implies F is onto
    proof
      assume A is epi;
      now
        per cases;
        suppose
A4:       o2 = {};
           then F = {};
          hence thesis by A4,FUNCT_2:def 3,RELAT_1:38;
        end;
        suppose
A5:       o2 <> {};
A6:       o1 is Element of X by ALTCAT_1:def 14;
          then o1 is trivial by A3;
          then consider z be object such that
A7:       o1 = {z} by A6,ZFMISC_1:131;
          dom F = {z} by A5,A7,FUNCT_2:def 1;
          then
A8:       rng F <> {} by RELAT_1:42;
          o2 is Element of X by ALTCAT_1:def 14;
          then o2 is trivial by A3;
          then consider y be object such that
A9:       o2 = {y} by A5,ZFMISC_1:131;
          rng F c= {y} by A9,RELAT_1:def 19;
          then rng F = {y} by A8,ZFMISC_1:33;
          hence thesis by A9,FUNCT_2:def 3;
        end;
      end;
      hence thesis;
    end;
    thus F is onto implies A is epi
    proof
      assume
A10:  F is onto;
      let o be Object of EnsCat X;
      assume
A11:  <^o2,o^> <> {};
      then
A12:  <^o1,o^> <> {} by A1,ALTCAT_1:def 2;
      let B,C be Morphism of o2,o;
A13:  <^o2,o^> = Funcs(o2,o) by ALTCAT_1:def 14;
      then consider B1 be Function such that
A14:  B1 = B and
A15:  dom B1 = o2 and
      rng B1 c= o by A11,FUNCT_2:def 2;
      consider C1 be Function such that
A16:  C1 = C and
A17:  dom C1 = o2 and
      rng C1 c= o by A11,A13,FUNCT_2:def 2;
      assume B * A = C * A;
      then
A18:  B1 * F = C * A by A1,A2,A11,A14,A12,ALTCAT_1:16
        .= C1 * F by A1,A2,A11,A16,A12,ALTCAT_1:16;
      now
        assume B1 <> C1;
        then consider z be object such that
A19:    z in o2 and
A20:    B1.z <> C1.z by A15,A17,FUNCT_1:2;
        z in rng F by A10,A19,FUNCT_2:def 3;
        then consider x be object such that
A21:    x in dom F and
A22:    F.x = z by FUNCT_1:def 3;
        B1.(F.x) = (B1*F).x by A21,FUNCT_1:13;
        hence contradiction by A18,A20,A21,A22,FUNCT_1:13;
      end;
      hence thesis by A14,A16;
    end;
  end;
  suppose
A23: ex x be set st x in X & x is non trivial;
    now
      per cases;
      suppose
A24:    o2 <> {};
        consider o be set such that
A25:    o in X and
A26:    o is non trivial by A23;
        reconsider o as Object of EnsCat X by A25,ALTCAT_1:def 14;
A27:    dom F = o1 by A24,FUNCT_2:def 1;
        thus A is epi implies F is onto
        proof
          set k = the Element of o;
A28:      rng F c= o2 by RELAT_1:def 19;
          reconsider ok = (o\{k}) as non empty set by A26,ZFMISC_1:139;
          assume that
A29:      A is epi and
A30:      not F is onto;
          rng F <> o2 by A30,FUNCT_2:def 3;
          then not o2 c= rng F by A28,XBOOLE_0:def 10;
          then consider y be object such that
A31:      y in o2 and
A32:      not y in rng F;
          set C = o2 --> k;
A33:      dom C = o2 by FUNCOP_1:13;
A34:      o <> {} by A25;
          then
A35:      k in o;
          rng C c= o
          proof
            let y be object;
            assume y in rng C;
            then ex x be object st x in dom C & C.x = y by FUNCT_1:def 3;
            hence thesis by A35,A33,FUNCOP_1:7;
          end;
          then C in Funcs(o2,o) by A33,FUNCT_2:def 2;
          then reconsider C1=C as Morphism of o2,o by ALTCAT_1:def 14;
          set l = the Element of ok;
A36:      not l in {k} by XBOOLE_0:def 5;
          reconsider l as Element of o by XBOOLE_0:def 5;
A37:      k <> l by A36,TARSKI:def 1;
          deffunc G(object) = IFEQ($1,y,l,k);
          consider B be Function such that
A38:      dom B = o2 and
A39:      for x be object st x in o2 holds B.x = G(x) from FUNCT_1:sch 3;
A40:      dom (B*F) = o1 by A27,A28,A38,RELAT_1:27;
A41:      rng B c= o
          proof
            let y1 be object;
            assume y1 in rng B;
            then consider x be object such that
A42:        x in dom B & B.x = y1 by FUNCT_1:def 3;
            per cases;
            suppose
A43:          x = y;
              y1 = IFEQ(x,y,l,k) by A38,A39,A42
                .= l by A43,FUNCOP_1:def 8;
             hence thesis by A34;
            end;
            suppose
A44:          x <> y;
              y1 = IFEQ(x,y,l,k) by A38,A39,A42
                .= k by A44,FUNCOP_1:def 8;
              hence thesis by A34;
            end;
          end;
          then
A45:      B in Funcs(o2,o) by A38,FUNCT_2:def 2;
          then
A46:      B in <^o2,o^> by ALTCAT_1:def 14;
          reconsider B1=B as Morphism of o2,o by A45,ALTCAT_1:def 14;
          for z be object holds z in rng(B*F) implies z in rng B
by FUNCT_1:14;
          then rng (B*F) c= rng B;
          then rng (B*F) c= o by A41;
          then (B*F) in Funcs(o1,o) by A40,FUNCT_2:def 2;
          then
A47:      (B*F) in <^o1,o^> by ALTCAT_1:def 14;
          B.y = IFEQ(y,y,l,k) by A31,A39
            .= l by FUNCOP_1:def 8;
          then
A48:      not B = C by A31,A37,FUNCOP_1:7;
A49:      dom (C*F) = o1 by A27,A28,A33,RELAT_1:27;
          now
            let z be object;
            assume
A50:        z in o1;
            then
A51:        F.z in rng F by A27,FUNCT_1:def 3;
            then
A52:        B.(F.z) = IFEQ((F.z),y,l,k) by A28,A39
              .= k by A32,A51,FUNCOP_1:def 8;
            thus (B * F).z = B.(F.z) by A40,A50,FUNCT_1:12
              .= C.(F.z) by A28,A51,A52,FUNCOP_1:7
              .= (C * F).z by A49,A50,FUNCT_1:12;
          end;
          then B * F = C * F by A40,A49,FUNCT_1:2;
          then B1 * A = C * F by A1,A2,A46,A47,ALTCAT_1:16
            .= C1 * A by A1,A2,A46,A47,ALTCAT_1:16;
          hence contradiction by A29,A48,A46;
        end;
        thus F is onto implies A is epi
        proof
          assume
A53:      F is onto;
          let o be Object of EnsCat X;
          assume
A54:      <^o2,o^> <> {};
          then
A55:      <^o1,o^> <> {} by A1,ALTCAT_1:def 2;
          let B,C be Morphism of o2,o;
A56:      <^o2,o^> = Funcs(o2,o) by ALTCAT_1:def 14;
          then consider B1 be Function such that
A57:      B1 = B and
A58:      dom B1 = o2 and
          rng B1 c= o by A54,FUNCT_2:def 2;
          consider C1 be Function such that
A59:      C1 = C and
A60:      dom C1 = o2 and
          rng C1 c= o by A54,A56,FUNCT_2:def 2;
          assume B * A = C * A;
          then
A61:      B1 * F = C * A by A1,A2,A54,A57,A55,ALTCAT_1:16
            .= C1 * F by A1,A2,A54,A59,A55,ALTCAT_1:16;
          now
            assume B1 <> C1;
            then consider z be object such that
A62:        z in o2 and
A63:        B1.z <> C1.z by A58,A60,FUNCT_1:2;
            z in rng F by A53,A62,FUNCT_2:def 3;
            then consider x be object such that
A64:        x in dom F and
A65:        F.x = z by FUNCT_1:def 3;
            B1.(F.x) = (B1*F).x by A64,FUNCT_1:13;
            hence contradiction by A61,A63,A64,A65,FUNCT_1:13;
          end;
          hence thesis by A57,A59;
        end;
      end;
      suppose
A66:    o2 = {};
         then F = {};
        hence A is epi implies F is onto by A66,FUNCT_2:def 3,RELAT_1:38;
        thus F is onto implies A is epi
        proof
          assume F is onto;
          let o be Object of EnsCat X;
          assume
A67:      <^o2,o^> <> {};
          let B,C be Morphism of o2,o;
A68:      <^o2,o^> = Funcs(o2,o) by ALTCAT_1:def 14;
          then consider B1 be Function such that
A69:      B1 = B and
A70:      dom B1 = o2 and
          rng B1 c= o by A67,FUNCT_2:def 2;
A71:      ex C1 be Function st C1 = C & dom C1 = o2 & rng C1 c= o by A67,A68,
FUNCT_2:def 2;
          assume B * A = C * A;
          B1 = {} by A66,A70,RELAT_1:41;
          hence thesis by A66,A69,A71,RELAT_1:41;
        end;
      end;
    end;
    hence thesis;
  end;
end;
