
theorem Th22:
  for o being Ordinal holds InvLexOrder o is well-ordering
proof
  defpred P[Ordinal] means InvLexOrder $1 is well-ordering;
A1: now
    let o be Ordinal such that
A2: for n being Ordinal st n in o holds P[n];
    set ilo = InvLexOrder o;
A3: ilo is_strongly_connected_in Bags o by Def5;
    then ilo is_reflexive_in Bags o;
    then
A4: field(ilo) = Bags o by PARTIT_2:9;
A5: now
      assume ilo is non well_founded;
      then
A6:   not ilo is_well_founded_in Bags o by A4,WELLORD1:3;
      set R = RelStr(# Bags o, ilo #);
      set ir = the InternalRel of R;
      R is non well_founded by A6;
      then consider f being sequence of R such that
A7:   f is descending by WELLFND1:14;
      reconsider a = f.0 as bag of o;
      set s = SgmX(RelIncl o, support a);
A8:   field(RelIncl o) = o by WELLORD2:def 1;
      RelIncl o is being_linear-order by ORDERS_1:19;
      then
A9:   RelIncl o linearly_orders support a by A8,ORDERS_1:37,38;
      then
A10:  rng s = support a by PRE_POLY:def 2;
      now
        assume rng s = {};
        then
A11:    a = EmptyBag o by A10,PRE_POLY:81;
        reconsider b = f.(0 qua Nat+1) as bag of o;
A12:    b <> a by A7;
        [b,a] in ir by A7;
        then ex i being Ordinal st ( i in o)&( b.i < a.i)&( for k being
        Ordinal st i in k & k in o holds b.k = a.k) by A12,Def6;
        hence contradiction by A11,PBOOLE:5;
      end;
      then
A13:  len s in dom s by FINSEQ_5:6,RELAT_1:38;
      then
A14:  s.len s in rng s by FUNCT_1:3;
      then reconsider j = s.len s as Ordinal by A10;
      defpred P[set,set] means ex b being bag of o st f.$1 = b & $2 = b.j;
A15:  now
        let x be Element of NAT;
        reconsider b = f.x as bag of o;
        take y = b.j;
        thus P[x,y];
      end;
      consider t being sequence of  NAT such that
A16:  for i being Element of NAT holds P[i,t.i] from FUNCT_2:sch 3(A15);
      defpred P[Nat] means for i being Ordinal, b being bag of o
      st j in i & i in o & f.$1 = b holds b.i = 0;
A17:  P[ 0 ]
      proof
        let i be Ordinal, b be bag of o such that
A18:    j in i and
A19:    i in o and
A20:    f.0 = b;
        assume b.i <> 0;
        then i in support a by A20,PRE_POLY:def 7;
        then consider k being Nat such that
A21:    k in dom s and
A22:    s.k = i by A10,FINSEQ_2:10;
A23:    k <= len s by A21,FINSEQ_3:25;
        per cases by A23,XXREAL_0:1;
        suppose k = len s;
          hence contradiction by A18,A22;
        end;
        suppose k < len s;
          then [s/.k,s/.len s] in RelIncl o by A9,A13,A21,PRE_POLY:def 2;
          then [s.k,s/.len s] in RelIncl o by A21,PARTFUN1:def 6;
          then [s.k,s.len s] in RelIncl o by A13,PARTFUN1:def 6;
          then s.k c= s.len s by A10,A14,A19,A22,WELLORD2:def 1;
          hence contradiction by A18,A22,ORDINAL1:5;
        end;
      end;
A24:  for n being Nat st P[n] holds P[n+1]
      proof
        let n be Nat;
        assume
A25:    for i being Ordinal, b being bag of o
        st j in i & i in o & f.n = b holds b.i = 0;
        let i be Ordinal, b1 be bag of o such that
A26:    j in i and
A27:    i in o and
A28:    f.(n+1) = b1;
        reconsider b = f.n as bag of o;
A29:    b.i = 0 by A25,A26,A27;
A30:    b1<>b by A7,A28;
        [b1,b] in ilo by A7,A28;
        then consider i1 being Ordinal such that
A31:    i1 in o and
A32:    b1.i1 < b.i1 and
A33:    for k being Ordinal st i1 in k & k in o holds b1.k = b.k by A30,Def6;
        per cases by ORDINAL1:14;
        suppose i1 in i;
          hence thesis by A27,A29,A33;
        end;
        suppose i1 = i;
          hence thesis by A25,A26,A27,A32;
        end;
        suppose
A34:      i in i1;
          assume b1.i <> 0;
          j in i1 by A26,A34,ORDINAL1:10;
          hence contradiction by A25,A31,A32;
        end;
      end;
A35:  for n being Nat holds P[n] from NAT_1:sch 2(A17,A24);
      reconsider t as sequence of OrderedNAT by DICKSON:def 15;
A36:  t is non-increasing
      proof
        let n be Nat;
         reconsider n0=n as Element of NAT by ORDINAL1:def 12;
        reconsider tn = t.n0, tn1 = t.(n0+1) as Nat;
        reconsider fn = f.n0, fn1 = f.(n0+1) as bag of o;
A37:    fn1 <> fn by A7;
        [fn1, fn] in ilo by A7;
        then consider i being Ordinal such that
A38:    i in o and
A39:    fn1.i < fn.i and
A40:    for k being Ordinal st i in k & k in o holds fn1.k = fn.k by A37,Def6;
A41:    ex bn being bag of o st ( fn = bn)&( tn = bn.j) by A16;
A42:    ex bn1 being bag of o st ( fn1 = bn1)&( tn1 = bn1.j) by A16;
        now
          per cases by ORDINAL1:14;
          suppose i = j;
            hence tn1 <= tn by A39,A41,A42;
          end;
          suppose j in i;
            hence tn1 <= tn by A35,A38,A39;
          end;
          suppose i in j;
            hence tn1 <= tn by A10,A14,A40,A41,A42;
          end;
        end;
        hence thesis by DICKSON:def 14,def 15;
      end;
      set n = j;
      set iln = InvLexOrder n;
      set S = RelStr(#Bags n, iln#);
      iln is_strongly_connected_in Bags n by Def5;
      then iln is_reflexive_in Bags n;
      then
A43:  field(iln) = Bags n by PARTIT_2:9;
      consider p being Nat such that
A44:  for r being Nat st p <= r holds t.p = t.r by A36,Th9;
      defpred P[Nat,set] means
      ex b being bag of o st b = f.(p+$1) & $2 = b|j;
A45:  now
        let x be Element of NAT;
        reconsider b = f.(p+x) as bag of o;
        reconsider y = b|j as bag of n by A10,A14,Th17;
        reconsider y as Element of Bags n by PRE_POLY:def 12;
        take y;
        thus P[x,y];
      end;
      consider g being sequence of  Bags n such that
A46:  for x being Element of NAT holds P[x,g.x] from FUNCT_2:sch 3(A45);
      reconsider g as sequence of S;
      now
        let k be Nat;
         reconsider k0=k as Element of NAT by ORDINAL1:def 12;
        consider b being bag of o such that
A47:    b = f.(p+k) and
A48:    g.k0 = b|j by A46;
        consider b1 being bag of o such that
A49:    b1 = f.(p+(k+1)) and
A50:    g.(k+1) = b1|j by A46;
        p+(k+1) = (p+k)+1;
        then
A51:    b <> b1 by A7,A47,A49;
A52:    ex bb being bag of o st ( f.(p+k) = bb)&( t.(p+k0) = bb.j) by A16;
A53:    ex bb1 being bag of o st ( f.(p+(k+1)) = bb1)&( t.(p+(k+1))
        = bb1.j) by A16;
A54:    t.(p+k) = t.p by A44,NAT_1:11;
        thus g.(k+1) <> g.k
        proof
          assume
A55:      not thesis;
A56:      o = dom b by PARTFUN1:def 2;
A57:      o = dom b1 by PARTFUN1:def 2;
          now
            let m be object such that
A58:        m in o;
            reconsider mm=m as set by TARSKI:1;
            per cases by A58,ORDINAL1:14;
            suppose
A59:          m in j;
              then (b|j).m = b.m by FUNCT_1:49;
              hence b.m = b1.m by A48,A50,A55,A59,FUNCT_1:49;
            end;
            suppose m = j;
              hence b.m = b1.m by A44,A47,A49,A52,A53,A54,NAT_1:11;
            end;
            suppose
A60:          j in mm;
              then b.m = 0 by A35,A47,A58;
              hence b.m = b1.m by A35,A49,A58,A60;
            end;
          end;
          hence contradiction by A51,A56,A57,FUNCT_1:2;
        end;
        [f.((p+k)+1), f.(p+k)] in ilo by A7;
        then consider i being Ordinal such that
A61:    i in o and
A62:    b1.i < b.i and
A63:    for k being Ordinal st i in k & k in o holds b.k = b1.k
        by A47,A49,A51,Def6;
A64:    now
          assume
A65:      not i in j;
          per cases by A65,ORDINAL1:14;
          suppose i = j;
            hence contradiction by A44,A47,A49,A52,A53,A54,A62,NAT_1:11;
          end;
          suppose
A66:        j in i;
            then b.i = 0 by A35,A47,A61
              .= b1.i by A35,A49,A61,A66;
            hence contradiction by A62;
          end;
        end;
        reconsider bj = b|j, b1j = b1|j as bag of n by A10,A14,Th17;
A67:    b1j.i = b1.i by A64,FUNCT_1:49;
A68:    bj.i = b.i by A64,FUNCT_1:49;
        now
          let k be Ordinal such that
A69:      i in k and
A70:      k in n;
          k in o by A10,A14,A70,ORDINAL1:10;
          then
A71:      b.k = b1.k by A63,A69;
          thus bj.k = b.k by A70,FUNCT_1:49
            .= b1j.k by A70,A71,FUNCT_1:49;
        end;
        hence [g.(k+1), g.k] in iln by A48,A50,A62,A64,A67,A68,Def6;
      end;
      then g is descending;
      then S is non well_founded by WELLFND1:14;
      then not iln is_well_founded_in the carrier of S;
      then not iln well_orders field iln by A43,WELLORD1:def 5;
      then iln is non well-ordering by WELLORD1:4;
      hence contradiction by A2,A10,A14;
    end;
A72: field ilo = Bags o by ORDERS_1:12;
    then
A73: ilo is_reflexive_in Bags o by RELAT_2:def 9;
A74: ilo is_transitive_in Bags o by A72,RELAT_2:def 16;
A75: ilo is_antisymmetric_in Bags o by A72,RELAT_2:def 12;
A76: ilo is_connected_in field ilo by A3,A4;
    ilo is_well_founded_in field ilo by A5,WELLORD1:3;
    then ilo well_orders field ilo by A4,A73,A74,A75,A76,WELLORD1:def 5;
    hence P[o] by WELLORD1:4;
  end;
  thus for o being Ordinal holds P[o] from ORDINAL1:sch 2(A1);
end;
