reserve X,Y for set,
  x,x1,x2,y,y1,y2,z for set,
  f,g,h for Function;
reserve M for non empty set;
reserve D for non empty set;
reserve P for Relation;
reserve O for Order of X;
reserve R,P for Relation,
  X,X1,X2,Y,Z,x,y,z,u for set,
  g,h for Function,
  O for Order of X,
  D for non empty set,
  d,d1,d2 for Element of D,
  A1,A2,B for Ordinal,
  L,L1,L2 for Sequence;
reserve A,C for Ordinal;

theorem
  Z is finite & Z c= rng f implies ex Y st Y c= dom f & Y is finite & f .:Y = Z
proof
  assume that
A1: Z is finite and
A2: Z c= rng f;
  per cases;
  suppose
A3: Z = {};
    take Y = {};
    thus Y c= dom f & Y is finite;
    thus thesis by A3;
  end;
  suppose
A4: Z <> {};
    deffunc F(object) = f"{$1};
    consider g being Function such that
A5: dom g = Z and
A6: for x being object st x in Z holds g.x = F(x) from FUNCT_1:sch 3;
    reconsider AA = rng g as non empty set by A4,A5,RELAT_1:42;
    set ff = the Choice_Function of AA;
    take Y = ff.:AA;
A7: for X being set st X in AA holds X <> {}
    proof
      let X be set;
      assume X in AA;
      then consider x being object such that
A8:   x in dom g and
A9:   g.x=X by FUNCT_1:def 3;
      g.x = f"{x} by A5,A6,A8;
      hence thesis by A2,A5,A8,A9,FUNCT_1:72;
    end;
    then
A10: not {} in AA;
    thus
A11: Y c= dom f
    proof
      let x be object;
      assume x in Y;
      then consider y being object such that
      y in dom ff and
A12:  y in AA and
A13:  ff.y=x by FUNCT_1:def 6;
      y in g.:Z by A5,A12,RELAT_1:113;
      then consider z being object such that
      z in dom g and
A14:  z in Z and
A15:  g.z=y by FUNCT_1:def 6;
A16:  g.z = f"{z} by A6,A14;
      x in g.z by A10,A12,A13,A15,Lm2;
     hence thesis by A16,FUNCT_1:def 7;
    end;
    AA = g.:Z by A5,RELAT_1:113;
    hence Y is finite by A1;
    set z = the Element of AA;
    set y = the Element of z;
    z <> {} by A7;
    then y in z;
    then reconsider AA9=union AA as non empty set by TARSKI:def 4;
    reconsider f9= ff as Function of AA,AA9 by A10,Lm3;
A17: dom f9 = AA by FUNCT_2:def 1;
    for x being object holds x in f.:Y iff x in Z
    proof let x be object;
      thus x in f.:Y implies x in Z
      proof
        assume x in f.:(Y);
        then consider y being object such that
        y in dom f and
A18:    y in Y and
A19:    f.y = x by FUNCT_1:def 6;
        consider z being object such that
A20:    z in dom ff and
        z in AA and
A21:    ff.z=y by A18,FUNCT_1:def 6;
        consider a being object such that
A22:    a in dom g and
A23:    g.a=z by A20,FUNCT_1:def 3;
        g.a = f"{a} by A5,A6,A22;
        then y in f"{a} by A10,A20,A21,A23,Lm2;
        then f.y in {a} by FUNCT_1:def 7;
        hence thesis by A5,A19,A22,TARSKI:def 1;
      end;
      set y=ff.(g.x);
      assume
A24:  x in Z;
      then
A25:  g.x in AA by A5,FUNCT_1:def 3;
      g.x = f"{x} by A6,A24;
      then y in f"{x} by A10,A25,Lm2;
      then f.y in {x} by FUNCT_1:def 7;
      then
A26:  f.y = x by TARSKI:def 1;
      ff.(g.x) in rng ff by A17,A25,FUNCT_1:def 3;
      then y in Y by A17,RELAT_1:113;
      hence thesis by A11,A26,FUNCT_1:def 6;
    end;
    hence thesis by TARSKI:2;
  end;
end;
