<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../../../xsl/unit.xsl"?>
<KIVSPEC name="VerifyThis1"><SPECBODY>enrich
   <a href="../../../specs/natlist/export/unit.xml">natlist</a>, 
   <a href="../../../../../lib/basic/specs/olist/export/unit.xml">olist</a>
with
   

   
   
   
   predicates  cutseq : natlist × list × bool;
               cutseq : natlist × list;
               in-range : natlist × nat × nat;
   procedures MAXCUT list :  : natlist  ;
   variables  m : nat;
              n : nat;
              x : list;
              cut : natlist;
              ns : natlist;
              inc : bool;
              sz : nat;
   
   

   

   axioms cutseq-empty :  ⊦ ¬ cutseq([], x);
          used for: ls;
          cutseq-one :  ⊦ cutseq(n ', x) ↔ n = 0;
          used for: ls;
          cutseq-rec
          : ⊦   cutseq(cut + n ' + n0 ', x)
              ↔   (  ordered&lt;(sublist(n, n0 - n, x)) ∧ (n0 &lt; &#35; x → ¬ x[n0 -1] &lt; x[n0])
                   ∨ ordered≤(rev(sublist(n, n0 - n, x))) ∧ (n0 &lt; &#35; x → x[n0 -1] &lt; x[n0]))
                ∧ n &lt; n0 ∧ n0 ≤ &#35; x ∧ cutseq(cut + n ', x);
          used for: ls;
          cutseq-empty-h :  ⊦ ¬ cutseq([], x, inc);
          used for: ls;
          cutseq-one-h :  ⊦ cutseq(n ', x, inc) ↔ n = 0;
          used for: ls;
          cutseq-rec-h
          : ⊦   cutseq(cut + n ' + n0 ', x, inc)
              ↔ (inc ⊃ ordered&lt;(sublist(n, n0 - n, x));ordered≤(rev(sublist(n, n0 - n, x)))) ∧ n &lt; n0 ∧ n0 ≤ &#35; x ∧ cutseq(cut + n ', x);
          used for: ls;
          in-range-base :  ⊦ in-range([], n, m);
          used for: ls, s;
          in-range-rec :  ⊦ in-range(n0 ' + ns, n, m) ↔ n ≤ n0 ∧ n0 ≤ m ∧ in-range(ns, n, m);
          used for: ls, s;

   theorems MAXCUT-thm :  ⊦ ⟨MAXCUT(x; ; cut)⟩ (cut.head = 0 ∧ cut.last = &#35; x ∧ in-range(cut, 0, &#35; x) ∧ cutseq(cut, x));
            MAXCUT-non-empty :  ⊦ ⟨/* _:use contract MAXCUT-thm and skip call;  */; MAXCUT(x; ; cut)⟩ (&#35; cut &gt; 0);
            MAXCUT-begin-to-end :  ⊦ ⟨/* _:use contract MAXCUT-thm and skip call;  */; MAXCUT(x; ; cut)⟩ (cut.head = 0 ∧ cut.last = &#35; x);
            MAXCUT-within-bounds :  ⊦ ⟨/* _:use contract MAXCUT-thm and skip call;  */; MAXCUT(x; ; cut)⟩ in-range(cut, 0, &#35; x);
            MAXCUT-monotonic-maximal :  ⊦ ⟨/* _:use contract MAXCUT-thm and skip call;  */; MAXCUT(x; ; cut)⟩ cutseq(cut, x);

   declarations MAXCUT
                : MAXCUT(x; ; cut)
                  {cut := 0 + []; 
                   let m = 0, n = 1
                   in {while n &lt; &#35; x
                       do {/* _:
                              invariant cutseq(cut, x) ∧ n = m + 1 ∧ m ≤ &#35; x ∧ cut.last = m ∧ cut.head = 0 ∧ in-range(cut, 0, &#35; x)
                              wfbound &#35; x - m; 
                           */; 
                           let inc = x[m] &lt; x[n]
                           in while n &lt; &#35; x ∧ (x[n - 1] &lt; x[n] ↔ inc)
                              do {/* _:invariant cutseq(cut + n ', x, inc) ∧ m &lt; n ∧ n ≤ &#35; x wfbound &#35; x - n;  */; n := n + 1}; 
                           cut := cut + n; m := n; n := m + 1}; 
                       if m &lt; &#35; x then cut := cut + &#35; x}
                  }
                ;
end enrich</SPECBODY></KIVSPEC>