reserve x for Int_position,
  n,p0 for Nat;
reserve P,Q,V for Instruction-Sequence of SCMPDS;

theorem Th8:
  for f being FinSequence of INT,m,k1,k,n be Nat st k1=k
  -1 & f is_non_decreasing_on m,k1 & f is_non_decreasing_on k+1,n & (for i be
  Nat st m <= i & i < k holds f.i <= f.k) & (for i be Nat
  st k < i & i <= n holds f.k <= f.i) holds f is_non_decreasing_on m,n
proof
  let f be FinSequence of INT,m,k1,k,n be Nat;
  assume that
A1: k1=k-1;
  assume
A2: f is_non_decreasing_on m,k1;
  assume
A3: f is_non_decreasing_on k+1,n;
  assume
A4: for i be Nat st m <= i & i < k holds f.i <= f.k;
  assume
A5: for i be Nat st k < i & i <= n holds f.k <= f.i;
  now
    let i,j be Nat;
    assume that
A6: m <= i and
A7: i <= j and
A8: j <= n;
    per cases by XXREAL_0:1;
    suppose
      j < k;
      then j+1 <= k by INT_1:7;
      then j <= k1 by A1,XREAL_1:19;
      hence f.i <= f.j by A2,A6,A7,FINSEQ_6:def 9;
    end;
    suppose
A9:   j = k;
        per cases;
        suppose
          i=j;
          hence f.i <= f.j;
        end;
        suppose
          i<>j;
          then i<j by A7,XXREAL_0:1;
          hence f.i <= f.j by A4,A6,A9;
        end;
    end;
    suppose
A10:  j > k;
        per cases by XXREAL_0:1;
        suppose
          i < k;
          then
A11:      f.k >= f.i by A4,A6;
          f.j >= f.k by A5,A8,A10;
          hence f.i <= f.j by A11,XXREAL_0:2;
        end;
        suppose
A12:      i = k;
            per cases;
            suppose
              i=j;
              hence f.i <= f.j;
            end;
            suppose
              i<>j;
              then i<j by A7,XXREAL_0:1;
              hence f.i <= f.j by A5,A8,A12;
          end;
        end;
        suppose
          i > k;
          then i >= k+1 by INT_1:7;
          hence f.i <= f.j by A3,A7,A8,FINSEQ_6:def 9;
        end;
    end;
  end;
  hence thesis by FINSEQ_6:def 9;
end;
