reserve X,Y,Z for set,
        x,y,z for object,
        A,B,C for Ordinal;
reserve U for Grothendieck;

theorem Th16:  :: Main Lemma 1
  for X st X c= U & not X in U
  ex f be Function st f is one-to-one & dom f = On U & rng f = X
proof
   let X such that
A1:X c= U & not X in U;
   for x be set st x in On U holds x is Ordinal & x c= On U
   proof
     let x be set;
     assume
A2:  x in On U;
     then x in U & x is Ordinal by ORDINAL1:def 9;
     then x c= U by ORDINAL1:def 2;
     hence thesis by A2,ORDINAL1:def 9;
   end;
   then On U is epsilon-transitive epsilon-connected by ORDINAL1:19;
   then reconsider Lambda=On U as Ordinal;
   ex THE be Function st for x be set st {} <> x c= X holds THE.x in x
   proof
     consider V be Relation such that
A3:    V well_orders X by WELLORD2:17;
     defpred The[object,object] means for A be set st A = $1 holds
     $2 in A & for b be object st b in A holds [$2,b] in V;
A4:    for x st x in (bool X)\{{}} ex u be object st The[x,u]
     proof
       let x such that
A5:    x in (bool X)\{{}};
       reconsider y=x as set by TARSKI:1;
       consider a be object such that
A6:    a in y and
A7:    for b be object st b in y holds [a,b] in V
         by A3,WELLORD1:5,A5,ZFMISC_1:56;
       take a;
       thus thesis by A6,A7;
     end;
     consider THE be Function such that
     dom THE = (bool X)\{{}} and
A8:  for e be object st e in (bool X)\{{}} holds The[e,THE.e]
         from CLASSES1:sch 1(A4);
     take THE;
     let x be set;
     assume {}<>x c= X;
     then x in (bool X)\{{}} by ZFMISC_1:56;
     hence thesis by A8;
   end;
   then consider THE be Function such that
A9:  for x be set st {} <> x c= X holds THE.x in x;
   deffunc ranks(set) = {the_rank_of x where x is Element of $1:x in $1};
A10: for A be set, x be object holds
   x in ranks(A) iff ex a be set st a in A & x = the_rank_of a
   proof
     let A be set, x be object;
     thus x in ranks(A) implies ex a be set st a in A & x = the_rank_of a
     proof
       assume x in ranks(A);
       then consider a be Element of A such that
A11:   x = the_rank_of a & a in A;
       take a;
       thus thesis by A11;
     end;
     assume ex a be set st a in A & x = the_rank_of a;
     hence thesis;
   end;
   defpred Q[set,object] means
      $2 in X \ $1 &
      for B be Ordinal st B in ranks(X\$1) holds the_rank_of $2 c= B;
   deffunc F(Sequence) = THE. {x where x is Element of X: Q[rng $1,x]};
   consider f be Sequence such that
A12: dom f = Lambda and
A13: for A be Ordinal,L be Sequence st
   A in Lambda & L = f|A holds f.A = F(L) from ORDINAL1:sch 4;
A14: for A be Ordinal st A in Lambda holds Q[rng (f|A), f.A]
   proof
     let A be Ordinal such that
A15: A in Lambda;
A16: A in U by A15,ORDINAL1:def 9;
A17: dom (f|A) = A by A12,RELAT_1:62,A15,ORDINAL1:def 2;
A18: f.A = F(f|A) by A15,A13;
     set II= {x where x is Element of X: Q[rng (f|A),x]};
     II c= X
     proof
       let i be object;
       assume i in II;
       then ex x be Element of X st i=x & Q[rng (f|A),x];
       hence thesis;
     end;
     then reconsider II as Subset of X;
     defpred P[Ordinal] means ex a be set st a in X\rng (f|A) &
       $1 = the_rank_of a;
A19: ex O be Ordinal st P[O]
     proof
       assume
A20:   for O be Ordinal holds not P[O];
A21:   X\rng (f|A)={}
       proof
         assume X\rng (f|A)<>{};
         then consider a be object such that
A22:     a in X\rng (f|A) by XBOOLE_0:def 1;
         P[the_rank_of a] by A22;
         hence contradiction by A20;
       end;
A23:   dom ( X |` (f|A)) in U by A17,A16,CLASSES1:def 1,FUNCT_1:56;
       rng ( X |` (f|A)) = X by A21,XBOOLE_1:37,RELAT_1:89;
       hence contradiction by A1,Th2,A23;
     end;
     consider Min be Ordinal such that
A24:   P[Min] & for O be Ordinal st P[O] holds Min c= O
       from ORDINAL1:sch 1(A19);
     consider t be set such that
A25:   t in X\rng (f|A) & Min = the_rank_of t by A24;
     for B be Ordinal st B in ranks(X\rng (f|A)) holds the_rank_of t c= B
     proof
       let B be Ordinal such that
A26:   B in ranks(X\rng (f|A));
       ex a be set st a in X\rng (f|A) & B=the_rank_of a by A10,A26;
       hence thesis by A24,A25;
     end;
     then t in II by A25;
     then THE.II in II by A9;
     then ex x be Element of X st x = THE.II & Q[rng (f|A),x];
     hence Q[rng (f|A),f.A] by A18;
   end;
A27: f is one-to-one
   proof
     let x1,x2 be object such that
A28: x1 in dom f & x2 in dom f & f.x1 = f.x2;
     assume
A29: x1<>x2;
     reconsider x1,x2 as Ordinal by A28;
A30: f.x1 in X\rng (f|x1) & f.x2 in X\rng (f|x2) by A14,A28,A12;
     per cases by A28,ORDINAL1:def 3,A29;
     suppose x1 in x2;
       then x1 in dom (f|x2) & f.x1 = (f|x2).x1 by A28,RELAT_1:57,FUNCT_1:49;
       then f.x1 in rng (f|x2) by FUNCT_1:def 3;
       hence contradiction by A30,XBOOLE_0:def 5,A28;
     end;
     suppose x2 in x1;
       then x2 in dom (f|x1) & f.x2 = (f|x1).x2 by A28,RELAT_1:57,FUNCT_1:49;
       then f.x2 in rng (f|x1) by FUNCT_1:def 3;
       hence contradiction by A30,XBOOLE_0:def 5,A28;
     end;
   end;
A31: rng f c= X
   proof
     let y such that
A32: y in rng f;
     consider A be object such that
A33: A in dom f & f.A =y by A32,FUNCT_1:def 3;
     reconsider A as Ordinal by A33;
     Q[rng (f|A), f.A] by A12,A14,A33;
     hence thesis by A33;
   end;
A34: X c= rng f
   proof
     let x such that
A35: x in X;
     assume
A36: not x in rng f;
     Rrank x in U by A1,A35,Th14;
     then
A37: bool Rrank x in U by Def1;
     rng f c= bool Rrank x
     proof
       let y be object such that
A38:   y in rng f;
       consider A be object such that
A39:   A in dom f & f.A = y by A38,FUNCT_1:def 3;
       reconsider A as Ordinal by A39;
       rng (f|A) c= rng f by RELAT_1:70;
       then not x in rng (f|A) by A36;
       then x in X\rng(f|A) by A35,XBOOLE_0:def 5;
       then the_rank_of x in ranks(X\rng (f|A));
       then the_rank_of (f.A) in  succ the_rank_of x
         by A39,A12,A14,ORDINAL1:22;
       then
A40:   Rank succ the_rank_of (f.A) c= Rank succ the_rank_of x
         by CLASSES1:37,ORDINAL1:21;
       f.A in Rank succ the_rank_of (f.A) by CLASSES1:def 8;
       then f.A in Rank succ the_rank_of x by A40;
       hence thesis by A39, CLASSES1:30;
     end;
     then
A41: rng f in U by A37,CLASSES1:def 1;
A42: rng (f") = dom f & dom (f") = rng f by A27,FUNCT_1:33;
     dom f in U by A42,A41,A12,ORDINAL2:7,Th2;
     then dom f in Lambda by ORDINAL1:def 9;
     hence thesis by A12;
   end;
   take f;
   thus thesis by A34,A31,A27,A12;
 end;
