
theorem :: Dilworth: General case
for R being with_finite_stability# antisymmetric transitive RelStr
 ex C being Clique-partition of R st card C = stability# R
proof
 let R be with_finite_stability# antisymmetric transitive RelStr;
 per cases;
 suppose R is finite;
   hence thesis by Th51;
 end;
 suppose A1: R is infinite;
 defpred P[Nat] means
  for P being with_finite_stability# non empty antisymmetric transitive RelStr
   st stability# P = $1
    ex C being Clique-partition of P st card(C) = stability# P;
 A2: P[0];
 A3: for k be Nat st P[k] holds P[k + 1] proof
 let k be Nat;
 assume A4: P[k];
 let P be with_finite_stability# non empty antisymmetric transitive RelStr;
 assume A5: stability# P = k+1;
  consider C being non empty Subset of P such that
A6: C is strong-chain and
A7: not ex D being Subset of P st D is strong-chain & C c< D by Th52;
    set cP = the carrier of P;
   per cases;
   suppose A8: C = cP;  :: real base case
     for x being set st x in { C } holds x is Clique of P by A6,TARSKI:def 1;
     then reconsider Cp = { C } as Clique-partition of P
           by Def11,A8,EQREL_1:39;
     take Cp;
A9: cP = [#]P;
     thus card Cp = 1 by CARD_1:30
                 .= stability# P by A9,A6,A8,Th20;
   end;
   suppose C <> cP;
    then A10: C c< cP;
    set cP9 = cP \ C;
A11:  cP \ cP9 = cP /\ C by XBOOLE_1:48
            .= C by XBOOLE_1:28;
    reconsider cP9 as Subset of P;
    cP9 <> {} by A10,XBOOLE_1:105;
  then reconsider P9 = subrelstr cP9
       as with_finite_stability# non empty antisymmetric transitive RelStr;
 A12: cP9 = the carrier of P9 by YELLOW_0:def 15;
A13:  stability# P9 <= k+1 by A5,Th44;
A14:  stability# P9 <> k+1 proof
     assume A15: stability# P9 = k+1;
     consider A being finite StableSet of P9 such that
    A16: card(A) = stability# P9 by Def6;
    reconsider A9 = A as finite non empty StableSet of P by A16,Th30;
    defpred R[set, set, set] means
      for c being set st c in $2 holds not $1 /\ $3 c= c or
              ex d being set st d in $2 & d <> c & $3 /\ d <> {};
    defpred Q[finite Subset of P,set] means
     for p being Clique-partition of subrelstr $1
        st card p <= stability# P holds R[$1,p,$2];
    defpred P[object,object] means
     ex S being finite non empty Subset of P
      st $2 = S & $1 in S & Q[S, C\/{$1}];
    A17: for x being object st x in A ex y being object st P[x,y] proof
        let a be object;
        assume A18: a in A;
            A c= cP by A12,XBOOLE_1:1;
            then {a} c= cP by A18,ZFMISC_1:31;
         then reconsider Ca = C \/ {a} as Subset of P by XBOOLE_1:8;
        now
          assume A19: Ca is strong-chain;
               a in {a} by TARSKI:def 1;
           then A20: a in Ca by XBOOLE_0:def 3;
           A21: not a in C by A12,A18,XBOOLE_0:def 5;
               C c= Ca by XBOOLE_1:7;
           then C c< Ca by A20,A21;
           hence contradiction by A19,A7;
        end;
        then consider S being finite non empty Subset of P such that
     A22: Q[S,Ca];
         take S;
         take S;
         thus S = S;
          now
            assume A23: not a in S;
            A24: S /\ C c= S /\ Ca proof
                  let x be object;
                  assume x in S /\ C;
                  then x in S & x in C by XBOOLE_0:def 4;
                  then x in S & x in Ca by XBOOLE_0:def 3;
                  hence x in S /\ Ca by XBOOLE_0:def 4;
                 end;
                 S /\ Ca c= S /\ C proof
                   let x be object;
                   assume A25: x in S /\ Ca;
                   then A26: x in S by XBOOLE_0:def 4;
                     x in Ca by A25,XBOOLE_0:def 4;
                   then x in C or x in {a} by XBOOLE_0:def 3;
                   hence x in S /\ C by A26,A23,TARSKI:def 1,XBOOLE_0:def 4;
                 end;
            then A27: S /\ C = S /\ Ca by A24;
            consider p being Clique-partition of subrelstr S such that
          A28: card p <= stability# P and
          A29: not R[S,p,C] by A6;
            consider c being set such that
          A30: c in p and
          A31: S /\ C c= c and
          A32: for d being set st d in p & d <> c holds C /\ d = {} by A29;
              for d being set st d in p & d <> c holds Ca /\ d = {} proof
                let d be set such that
              A33: d in p and
              A34: d <> c;
                  now
                   assume Ca /\ d <> {};
                   then consider x being object such that
                  A35: x in Ca /\ d by XBOOLE_0:def 1;
                  A36: x in Ca by A35,XBOOLE_0:def 4;
                  A37: x in d by A35,XBOOLE_0:def 4;
                   per cases by A36,XBOOLE_0:def 3;
                   suppose x in C;
                     then x in C /\ d by A37,XBOOLE_0:def 4;
                    hence contradiction by A33,A34,A32;
                   end;
                   suppose x in {a};
                     then x = a by TARSKI:def 1;
                     then a in the carrier of subrelstr S by A37,A33;
                    hence contradiction by A23,YELLOW_0:def 15;
                  end;
                 end;
              hence Ca /\ d = {};
              end;
            hence contradiction by A30,A31,A28,A27,A22;
          end;
         hence a in S;
         thus thesis by A22;
       end;
      consider f being Function such that
    A38: dom f = A and
A39: for x being object st x in A holds P[x,f.x] from CLASSES1:sch 1(A17);
    A40:  rng f is finite by A38,FINSET_1:8;
     set SS = union rng f;
    A41:  for x being set st x in rng f holds x is finite proof
          let x be set;
          assume x in rng f;
           then consider a being object such that
          A42: a in dom f and
          A43: x = f.a by FUNCT_1:def 3;
          P[a,f.a] by A38,A42,A39;
          then consider S being finite non empty Subset of P such that
          A44: f.a = S and a in f.a & Q[S, C \/ {a}];
          thus x is finite by A44,A43;
         end;
    A45: SS c= cP proof
          let x be object;
          assume x in SS;
          then consider y being set such that
          A46: x in y and
          A47: y in rng f by TARSKI:def 4;
              consider a being object such that
          A48: a in dom f and
          A49: y = f.a by A47,FUNCT_1:def 3;
          P[a,f.a] by A38,A48,A39;
          then consider S being finite non empty Subset of P such that
          A50: f.a = S and a in f.a & Q[S, C \/ {a}];
          thus x in cP by A46,A49,A50;
         end;
    A51: A9 c= SS proof
          let x be object;
          assume A52: x in A9;
          then P[x,f.x] by A39;
          then consider S being finite non empty Subset of P such that
              f.x = S and
          A53: x in f.x  and Q[S, C \/ {x}];
          f.x in rng f by A52,A38,FUNCT_1:3;
          hence x in SS by A53,TARSKI:def 4;
         end;
     then reconsider SS as finite non empty Subset of P
                      by A41,A40,A45,FINSET_1:7;
     set SSp = subrelstr SS;
    A54: SS = the carrier of SSp by YELLOW_0:def 15;
     consider p being Clique-partition of SSp such that
    A55: card p <= stability# P and
    A56: not R[SS,p,C] by A6;
        consider c being set such that
    A57: c in p and
    A58: SS /\ C c= c and
    A59: for d being set st d in p & d <> c holds C /\ d = {} by A56;
        reconsider c as Element of p by A57;
        A9 = A9 /\ SS by A51,XBOOLE_1:28;
     then reconsider A = A9 as finite non empty StableSet of SSp by Th31;
    A60: stability# SSp >= card A by Def6;
        card p >= stability# SSp by Th46;
        then card p >= card A by A60,XXREAL_0:2;
        then consider a being Element of A such that
    A61: c /\ A = {a} by Th48,A55,A16,A15,A5,XXREAL_0:1;
        a in c /\ A by A61,TARSKI:def 1; then
    A62: a in c by XBOOLE_0:def 4;
        P[a,f.a] by A39;
        then consider S being finite non empty Subset of P such that
    A63: f.a = S and
    A64: a in f.a and
    A65: Q[S, C \/ {a}];
        deffunc F(set) = $1 /\ S;
        defpred P[set] means $1 meets S;
        set Sp = { F(e) where e is Element of p: P[e]};
    A66: S c= SS proof
          let x be object;
          assume A67: x in S;
          S in rng f by A63,A38,FUNCT_1:3;
          hence x in SS by A67,TARSKI:def 4;
        end;
        then reconsider Sp as a_partition of S by A54,PUA2MSS1:11;
        for x being set st x in Sp holds x is Clique of subrelstr S proof
          let x be set;
          assume x in Sp;
          then consider e being Element of p such that
        A68: x = e /\ S and e meets S;
            e is Clique of SSp by Def11;
            then e is Clique of P by Th28;
          hence x is Clique of subrelstr S by A68,Th29;
        end;
        then reconsider Sp as Clique-partition of subrelstr S
         by Def11,YELLOW_0:def 15;
    A69: Sp = { F(e) where e is Element of p: P[e]};
    A70: card Sp <= card p from FraenkelFinCard1(A69);
         set cc = c /\ S;
         c meets S by A62,A63,A64,XBOOLE_0:3; then
    A71: cc in Sp;
         S /\ (C \/ {a}) c= cc proof
           let x be object;
           assume A72: x in S /\ (C \/ {a});
           then A73: x in S by XBOOLE_0:def 4;
           A74: x in C \/ {a} by A72,XBOOLE_0:def 4;
            per cases by A74,XBOOLE_0:def 3;
            suppose x in C;
                then x in SS /\ C by A73,A66,XBOOLE_0:def 4;
              hence x in cc by A73,A58,XBOOLE_0:def 4;
            end;
            suppose x in {a};
              then x = a by TARSKI:def 1;
              hence x in cc by A62,A63,A64,XBOOLE_0:def 4;
            end;
         end;
         then consider d being set such that
     A75: d in Sp and
     A76: d <> cc and
     A77: (C \/ {a}) /\ d <> {} by A71,A70,A55,A65,XXREAL_0:2;
         consider dd being Element of p such that
     A78: d = dd /\ S and
         dd meets S by A75;
          C /\ dd = {} by A78,A76,A59; then
     A79: C /\ d = {} /\ S by A78,XBOOLE_1:16 .= {};
          C /\ d \/ {a} /\ d <> {} by A77,XBOOLE_1:23;
          then consider x being object such that
     A80: x in {a} /\ d by A79,XBOOLE_0:def 1;
          x in {a} & x in d by A80,XBOOLE_0:def 4;
          then a in d by TARSKI:def 1;
          then a in dd by A78,XBOOLE_0:def 4;
          then c meets dd by A62,XBOOLE_0:3;
     hence contradiction by A78,A76,EQREL_1:def 4;
    end;
    then stability# P9 < k+1 by A13,XXREAL_0:1; then
A81: stability# P9 <= k by NAT_1:13;
    consider A being finite StableSet of P such that
A82:  card A = stability# P by Def6;
A83:  stability# P9 = k proof
     per cases;
     suppose A84: A /\ C = {};
        A c= cP9 proof
          let x be object;
          assume A85: x in A;
          then not x in C by A84,XBOOLE_0:def 4;
          hence x in cP9 by A85,XBOOLE_0:def 5;
         end;
       hence thesis by A5,A14,A82,Th45;
     end;
     suppose A /\ C <> {};
       then consider x being object such that
     A86: x in A /\ C by XBOOLE_0:def 1;
     A87: x in A by A86,XBOOLE_0:def 4;
     A88: x in C by A86,XBOOLE_0:def 4;
         set A9 = A \ {x};
         {x} c= A by A87,ZFMISC_1:31;
         then A89: A = A9 \/ {x} by XBOOLE_1:45;
         x in {x} by TARSKI:def 1;
         then not x in A9 by XBOOLE_0:def 5;
         then A90: card A = card A9 + 1 by A89,CARD_2:41;
     A91: A9 c= A by XBOOLE_1:36;
         A9 c= cP9 proof
           let xx be object;
           assume A92: xx in A9;
         then A93: xx in A by XBOOLE_0:def 5;
          not xx in {x} by A92,XBOOLE_0:def 5;
             then xx <> x by TARSKI:def 1;
             then not xx in C by A87,A88,A93,A6,Th15;
           hence xx in cP9 by A92,XBOOLE_0:def 5;
         end; then
     A94: A9 c= A /\ cP9 by A91,XBOOLE_1:19;
         A /\ cP9 c= A9 proof
           let xx be object;
           assume A95: xx in A /\ cP9;
         then A96: xx in A by XBOOLE_0:def 4;
             xx in cP9 by A95,XBOOLE_0:def 4;
           then x <> xx by A88,XBOOLE_0:def 5;
           then not xx in {x} by TARSKI:def 1;
           hence xx in A9 by A96,XBOOLE_0:def 5;
         end;
         then A9 = A /\ cP9 by A94;
         then reconsider A9 as StableSet of P9 by Th31;
         stability# P9 >= card A9 by Def6;
       hence thesis by A90,A82,A5,A81,XXREAL_0:1;
     end;
    end;
    then consider Cp9 being Clique-partition of P9 such that
A97: card(Cp9) = stability# P9 by A4;
    set Cp = Cp9 \/ { cP \ cP9 };
A98: Cp9 is finite by A97;
    cP9 <> cP by A11,XBOOLE_1:37;
    then
A99: cP9 c< cP;
    then reconsider Cp as a_partition of cP by A12,Th4;
     now  :: chains in Cp;
       let x be set;
       assume A100: x in Cp;
       per cases by A100,XBOOLE_0:def 3;
       suppose x in Cp9;
         then x is Clique of P9 by Def11;
         hence x is Clique of P by Th28;
       end;
       suppose x in { cP \ cP9 };
        hence x is Clique of P by A6,A11,TARSKI:def 1;
       end;
     end;
    then reconsider Cp as Clique-partition of P by Def11;
    take Cp;
    not cP \ cP9 in Cp9 proof
      assume not thesis;
      then cP c= cP9 \/ cP9 by A12,XBOOLE_1:44;
      hence contradiction by A99,XBOOLE_1:60;
    end;
    hence card Cp = stability# P by A5,A83,A97,A98,CARD_2:41;
   end;
  end;
  for k being Nat holds P[k] from NAT_1:sch 2(A2,A3);
  hence thesis by A1;
 end;
end;
