reserve X for set, R,R1,R2 for Relation;
reserve x,y,z for set;
reserve n,m,k for Nat;

theorem Th20:
  R is co-well_founded irreflexive & X is finite & R is finite
  implies ex n st iter(R,n).:X = {}
  proof
    assume that
A1: R is co-well_founded irreflexive & X is finite and
A2: R is finite and
A3: iter(R,n).:X <> {};
    defpred Q[object] means for n holds Im(iter(R,n),$1) <> {};
    consider x0 being set such that
A4: x0 in X & Q[x0] by A1,A3,Th19;
    defpred P[object,object,object] means
    (Q[$2] implies $3 in Im(R,$2) & Q[$3]);
A5: for n being Nat, x be set ex y be set st P[n,x,y]
    proof
      let n be Nat, x be set;
      per cases;
      suppose
A6:     not Q[x];
        take 0; thus thesis by A6;
      end;
      suppose
A7:     Q[x];
A8:     Im(R,x) c= rng R by RELAT_1:111;
        now let n;
          iter(R,n).:Im(R,x) = (R*iter(R,n)).:{x} by RELAT_1:126
          .= Im(iter(R,n+1),x) by FUNCT_7:69;
          hence iter(R,n).:Im(R,x) <> {} by A7;
        end; then
        consider y such that
A9:     y in Im(R,x) & Q[y] by A2,A8,Th19;
        take y; thus thesis by A9;
      end;
    end;
    consider f being Function such that
A10: dom f = NAT & f.0 = x0 & for n being Nat holds P[n,f.n,f.(n+1)]
    from RECDEF_1:sch 1(A5);
    defpred R[Nat] means Q[f.$1];
A11: R[0] by A4,A10;
A12: R[k] implies R[k+1] by A10;
A13: R[k] from NAT_1:sch 2(A11,A12);
A14: rng f c= field R
    proof
      let z be object; assume z in rng f; then
      consider y be object such that
A15:   y in NAT & z = f.y by A10,FUNCT_1:def 3;
      reconsider y as Element of NAT by A15;
      P[y,z,f.(y+1)] & R[y] by A10,A13,A15; then
      [z,f.(y+1)] in R by A15,RELAT_1:169;
      hence thesis by RELAT_1:15;
    end; then
    consider z be object such that
A16: z in rng f & for x be object st x in rng f & z <> x holds [z,x] nin R
    by A1,A10,RELAT_1:42;
    consider y be object such that
A17: y in NAT & z = f.y by A10,A16,FUNCT_1:def 3;
    reconsider y as Element of NAT by A17;
    P[y,z,f.(y+1)] & R[y] & y+1 in NAT by A10,A13,A17,ORDINAL1:def 12; then
A18: [z,f.(y+1)] in R & f.(y+1) in rng f
    by A10,A17,RELAT_1:169,FUNCT_1:def 3; then
    z = f.(y+1) & R is_irreflexive_in field R by A1,A16;
    hence contradiction by A14,A18;
  end;
