
theorem Th32:
  for S being gate`2=den finite non void non empty unsplit
  gate`1=arity ManySortedSign for A being non-empty Circuit of S st A is
  gate`2=den holds A is with_stabilization-limit
proof
  let S be gate`2=den finite non void non empty unsplit gate`1=arity
  ManySortedSign;
  defpred P[object,object] means
   $1 = $2 or $1 in the carrier' of S & $2 in proj2 $1`1;
  consider R being Relation such that
A1: for a,b being object holds [a,b] in R iff a in the carrier of S & b in
  the carrier of S & P[a,b] from RELAT_1:sch 1;
  let A be non-empty Circuit of S such that
A2: A is gate`2=den;
A3: R is co-well_founded
  proof
    defpred P[object,object] means
    ex x being set st x = $1 & $2 = the_rank_of x;
    let Y be set;
    assume that
    Y c= field R and
A4: Y <> {};
    set y = the Element of Y;
A5: for x,y,z being object st P[x,y] & P[x,z] holds y = z;
    consider B being set such that
A6: for x being object holds x in B iff ex y being object st y in Y & P[y,x]
    from TARSKI:sch 1(A5);
    the_rank_of y in B by A4,A6;
    then inf B in B by ORDINAL2:17;
    then consider y being object such that
A7: y in Y and
A8: P[y,inf B] by A6;
    reconsider y as set by TARSKI:1;
    take y;
    thus y in Y by A7;
    let b be object;
    assume that
A9: b in Y and
A10: y <> b & [y,b] in R;
    the_rank_of b in B by A6,A9;
    then
A11: inf B c= the_rank_of b by ORDINAL2:14;
    y in the carrier' of S by A1,A10;
    then y = [y`1, (the Charact of A).y] by A2;
    then
A12: the_rank_of y`1 in the_rank_of y by Th31;
    b in proj2 y`1 by A1,A10;
    then consider c being object such that
A13: [c,b] in y`1 by XTUPLE_0:def 13;
A14: the_rank_of b in the_rank_of [c,b] by Th31;
    the_rank_of [c,b] in the_rank_of y`1 by A13,CLASSES1:68;
    hence contradiction by A8,A14,A12,A11,ORDINAL1:10;
  end;
  defpred A[object,object] means
ex n being Element of NAT st $2 = n & for s being
  State of A, m being Element of NAT st m >= n holds Following(s,m).$1 =
  Following(s,n).$1;
  defpred P[object] means
   $1 in the carrier of S implies ex n being Element of
NAT st for s being State of A, m being Element of NAT st m >= n holds Following
  (s,m).$1 = Following(s,n).$1;
A15: rng R c= the carrier of S
  proof
    let o be object;
    assume o in rng R;
    then ex q being object st [q,o] in R by XTUPLE_0:def 13;
    hence thesis by A1;
  end;
A16: the carrier of S c= field R
  proof
    let o be object;
    assume o in the carrier of S;
    then [o,o] in R by A1;
    hence thesis by RELAT_1:15;
  end;
  dom R c= the carrier of S
  proof
    let o be object;
    assume o in dom R;
    then ex q being object st [o,q] in R by XTUPLE_0:def 12;
    hence thesis by A1;
  end;
  then
A17: dom R \/ rng R c= (the carrier of S) \/ the carrier of S by A15,
XBOOLE_1:13;
  then
A18: the carrier of S = field R by A16,XBOOLE_0:def 10;
A19: for a being object
   st for b being object st [a,b] in R & a <> b holds P[b]
  holds P[a]
  proof
    defpred P[object,object] means
ex n being Element of NAT st $2 = n & for s being
    State of A, m being Element of NAT st m >= n holds Following(s,m).$1 =
    Following(s,n).$1;
    let a be object;
    defpred S[object] means a <> $1 & [a,$1] in R;
    consider RS being set such that
A20: for b being object holds b in RS iff b in field R & S[b] from
    XBOOLE_0:sch 1;
A21: RS c= the carrier of S
    by A18,A20;
    assume
A22: for b being object st [a,b] in R & a <> b holds P[b];
A23: for b being object st b in RS ex z being object st P[b,z]
    proof
      let b be object;
      assume
A24:  b in RS;
      then a <> b & [a,b] in R by A20;
      then ex n being Element of NAT st for s being State of A, m being
Element of NAT st m >= n holds Following(s,m).b = Following(s,n).b by A22,A21
,A24;
      hence thesis;
    end;
    consider f being Function such that
A25: dom f = RS and
A26: for x being object st x in RS holds P[x,f.x] from CLASSES1:sch 1(A23);
    assume
A27: a in the carrier of S;
    per cases;
    suppose
A28:  RS <> {};
      rng f c= NAT
      proof
        let o be object;
        assume o in rng f;
        then consider l being object such that
A29:    l in dom f and
A30:    o = f.l by FUNCT_1:def 3;
        ex n being Element of NAT st f.l = n & for s being State of A, m
being Element of NAT st m >= n holds Following(s,m).l = Following(s,n). l by
A25,A26,A29;
        hence thesis by A30;
      end;
      then reconsider
      C = rng f as finite non empty Subset of NAT by A21,A25,A28,FINSET_1:8
,RELAT_1:38,41;
      set b = the Element of RS;
      a <> b & [a,b] in R by A20,A28;
      then reconsider a1=a as Gate of S by A1;
      reconsider mC = max C as Element of NAT by ORDINAL1:def 12;
      take n = mC + 1;
      let s be State of A;
      let m be Element of NAT;
      assume m >= n;
      then consider k being Nat such that
A31:  m = n + k by NAT_1:10;
      reconsider k as Element of NAT by ORDINAL1:def 12;
A32:  for x being set st x in rng the_arity_of a1 holds Following(s,mC)
      is_stable_at x
      proof
        let x be set;
        assume
A33:    x in rng the_arity_of a1;
        a1 = [(the Arity of S).a1, a1`2] by CIRCCOMB:def 8;
        then
A34:    a1 = [the_arity_of a1, a1`2] by MSUALG_1:def 1;
        then the_rank_of x in the_rank_of a1 by A33,CLASSES1:82;
        then
A35:    x <> a;
        rng the_arity_of a1 c= the carrier of S & x in proj2 a`1 by A33,A34,
FINSEQ_1:def 4;
        then
A36:    [a1,x] in R by A1,A27,A33;
        then x in field R by RELAT_1:15;
        then
A37:    x in RS by A20,A35,A36;
        then consider l being Element of NAT such that
A38:    f.x = l and
A39:    for s being State of A, m being Element of NAT st m >= l
        holds Following(s,m).x = Following(s,l).x by A26;
        l in rng f by A25,A37,A38,FUNCT_1:3;
        then
A40:    max C >= l by XXREAL_2:def 8;
        now
          let k be Nat;
A41:       mC + k in NAT by ORDINAL1:def 12;
A42:      mC + k >= max C by NAT_1:11;
          thus (Following(Following(s,mC),k)).x
             = Following(s,mC+k).x by FACIRC_1:13
            .= Following(s,l).x by A39,A40,A42,XXREAL_0:2,A41
            .= Following(s,mC).x by A39,A40;
        end;
        hence thesis;
      end;
      the_result_sort_of a1 = (the ResultSort of S).a1 by MSUALG_1:def 2
        .= a by CIRCCOMB:44;
      then Following Following(s,mC) is_stable_at a by A32,FACIRC_1:19;
      then Following(s,n) is_stable_at a by FACIRC_1:12;
      then Following(Following(s,n),k).a = Following(s,n).a;
      hence thesis by A31,FACIRC_1:13;
    end;
    suppose
A43:  RS = {};
      take n=1;
      let s be State of A;
      let m be Element of NAT;
      assume m >= n;
      then consider k being Nat such that
A44:  m = n + k by NAT_1:10;
      reconsider k as Element of NAT by ORDINAL1:def 12;
A45:  now
        assume a in InnerVertices S;
        then a in rng id the carrier' of S by CIRCCOMB:def 7;
        then reconsider a1=a as Gate of S;
        for x being set st x in rng the_arity_of a1 holds s is_stable_at x
        proof
          let x be set;
          assume
A46:      x in rng the_arity_of a1;
          a1 = [(the Arity of S).a1, a1`2] by CIRCCOMB:def 8;
          then
A47:      a1 = [the_arity_of a1, a1`2] by MSUALG_1:def 1;
          then the_rank_of x in the_rank_of a1 by A46,CLASSES1:82;
          then
A48:      x <> a;
          rng the_arity_of a1 c= the carrier of S & x in proj2 a`1 by A46,A47,
FINSEQ_1:def 4;
          then
A49:      [a1,x] in R by A1,A27,A46;
          then x in field R by RELAT_1:15;
          hence thesis by A20,A43,A48,A49;
        end;
        then
A50:    Following s is_stable_at the_result_sort_of a1 by FACIRC_1:19;
        the_result_sort_of a1 = (the ResultSort of S).a1 by MSUALG_1:def 2
          .= a1 by CIRCCOMB:44;
        then Following(s,n) is_stable_at a1 by A50,FACIRC_1:14;
        then Following(Following(s,n),k).a = Following(s,n).a;
        hence thesis by A44,FACIRC_1:13;
      end;
A51:  now
        assume a in InputVertices S;
        then
A52:    s is_stable_at a by FACIRC_1:18;
        hence Following(s,m).a = s.a
          .= Following(s,n).a by A52;
      end;
      the carrier of S = InputVertices S \/ InnerVertices S by XBOOLE_1:45;
      hence thesis by A27,A51,A45,XBOOLE_0:def 3;
    end;
  end;
A53: for a being object st a in field R holds P[a]
     from REWRITE1:sch 2(A3,A19 );
A54: for a being object st a in field R ex b being object st A[a,b]
  proof
    let a be object;
    assume a in field R;
    then ex n being Element of NAT st for s being State of A, m being Element
    of NAT st m >= n holds Following(s,m).a = Following(s,n).a by A17,A53;
    hence thesis;
  end;
  consider f being Function such that
A55: dom f = field R and
A56: for x being object st x in field R holds A[x,f.x] from CLASSES1:sch 1
  (A54);
  rng f c= NAT
  proof
    let o be object;
    assume o in rng f;
    then consider l being object such that
A57: l in dom f and
A58: o = f.l by FUNCT_1:def 3;
    ex n being Element of NAT st f.l = n & for s being State of A, m
being Element of NAT st m >= n holds Following(s,m).l = Following(s,n). l by
A55,A56,A57;
    hence thesis by A58;
  end;
  then reconsider C = rng f as finite non empty Subset of NAT by A18,A55,
FINSET_1:8,RELAT_1:38,41;
  reconsider N = max C as Element of NAT by ORDINAL1:def 12;
  take N;
  let s be State of A;
A59: now
    let x be object;
    assume
A60: x in the carrier of S;
    then consider n being Element of NAT such that
A61: f.x = n and
A62: for s being State of A, m being Element of NAT st m >= n holds
    Following(s,m).x = Following(s,n).x by A16,A56;
    n in C by A16,A55,A60,A61,FUNCT_1:3;
    then
A63: N >= n by XXREAL_2:def 8;
    then
A64: N+1 >= n by NAT_1:13;
    thus Following(s,N).x = Following(s,n).x by A62,A63
      .= Following(s,N+1).x by A62,A64
      .= (Following Following(s,N)).x by FACIRC_1:12;
  end;
  dom Following(s,N) = the carrier of S & dom Following Following(s,N) =
  the carrier of S by CIRCUIT1:3;
  hence Following(s,N) = Following Following(s,N) by A59,FUNCT_1:2;
end;
