reserve X,Z for set;
reserve x,y,z for object;
reserve A,B,C for Subset of X;

theorem Th86:
  for A being transitive RelStr, B, C being Subset of A,
      s1 being FinSequence of A, x being Element of A
  st s1 is C-asc_ordering & not x in C & B = C \/ {x} &
    for y being Element of A st y in C holds y <= x
  holds ex s2 being FinSequence of A st
    s2 = s1 ^ <*x*> & s2 is B-asc_ordering
proof
  let A be transitive RelStr;
  let B,C be Subset of A;
  let s1 be FinSequence of A;
  let x be Element of A;
  assume that
    A1: s1 is C-asc_ordering and
    A2: not x in C and
    A3: B = C \/ {x} and
    A4: for y being Element of A st y in C holds y <= x;
  A5: s1 is weakly-ascending by A1;
  set sx = <*x*>;
  B is non empty by A3;
  then reconsider sx as FinSequence of the carrier of A by FINSEQ_1:74;
  reconsider sx as FinSequence of A;
  set s2 = s1 ^ sx;
  take s2;
  A6: rng s2 = rng sx \/ rng s1 by FINSEQ_1:31
    .= B by A3, A1, FINSEQ_1:38;
  {x} misses C by A2, ZFMISC_1:50;
  then rng sx misses rng s1 by A1, FINSEQ_1:38;
  then A7: s2 is one-to-one by A1, FINSEQ_3:91;
  for n, m being Nat st n in dom s2 & m in dom s2 & n < m holds
    s2/.n <= s2/.m
  proof
    let n, m being Nat such that
      A8: n in dom s2 and
      A9: m in dom s2 and
      A10: n < m;
    per cases by A9, FINSEQ_1:25;
    suppose A11: m in dom s1;
      then s2.m = s1.m by FINSEQ_1:def 7;
      then s2/.m = s1.m by A9, PARTFUN1:def 6;
      then A12: s2/.m = s1/.m by A11, PARTFUN1:def 6;
      per cases by A8, FINSEQ_1:25;
      suppose A13: n in dom s1;
        then s2.n = s1.n by FINSEQ_1:def 7;
        then s2/.n = s1.n by A8, PARTFUN1:def 6;
        then A14: s2/.n = s1/.n by A13, PARTFUN1:def 6;
        s1/.n <= s1/.m by A5, A11, A13, A10;
        hence s2/.n <= s2/.m by A12, A14;
      end;
      suppose ex l being Nat st l in dom sx & n=len s1 + l;
        then consider l being Nat such that A15: l in dom sx & n=len s1 + l;
        m in Seg len s1 by A11, FINSEQ_1:def 3;
        then A16: m <= len s1 by FINSEQ_1:1;
        l in Seg 1 by A15, FINSEQ_1:def 8;
        then l = 1 by FINSEQ_1:2, TARSKI:def 1;
        then m < n by A15, A16, NAT_1:13;
        hence thesis by A10;
      end;
    end;
    suppose ex k being Nat st k in dom sx & m=len s1 + k;
      then consider k being Nat such that A17: k in dom sx & m=len s1 + k;
      k in Seg len sx by A17, FINSEQ_1:def 3;
      then k in Seg 1 by FINSEQ_1:40;
      then A18: k = 1 by FINSEQ_1:2, TARSKI:def 1;
      then s2.m = x by A17, FINSEQ_1:42;
      then A19: s2/.m = x by A9, PARTFUN1:def 6;
      s2/.n in C
      proof
        per cases by A8, FINSEQ_1:25;
        suppose A20: n in dom s1;
          then A21: s2.n = s1.n by FINSEQ_1:def 7;
          s1.n in rng s1 by A20, FUNCT_1:3;
          hence s2/.n in C by A21, A1, A8, PARTFUN1:def 6;
        end;
        suppose ex l being Nat st l in dom sx & n=len s1 + l;
          then consider l being Nat such that A22: l in dom sx & n=len s1 + l;
          l in Seg len sx by A22, FINSEQ_1:def 3;
          then l in Seg 1 by FINSEQ_1:40;
          then m = n by A17, A22, A18, FINSEQ_1:2, TARSKI:def 1;
          hence thesis by A10;
        end;
      end;
      hence s2/.n <= s2/.m by A19, A4;
    end;
  end;
  then s2 is weakly-ascending;
  hence thesis by A6, A7;
end;
