Problem: longest_increasing_subsequence

You task is to implement the algorithm for longest increasing subsequence problem and verify its correctness in Dafny. For simplicity, the sequence only contains integer, and we only consider strictly increasing subsequence. The algorithm only needs to return the length of the longest increasing subsequence. In the incomplete code, it contains the definition of a valid increasing subsequence. You task is to implement the longest increasing subsequence algorithm and verify that the code indeed returns the length of the longest increasing subsequence, i.e, any increasing subsequence has length at most the return of the algorithm, and there exists an increasing subsequence that has the length equal to the returned value.


// Following is the block for necessary definitions
// <preamble>
ghost predicate is_valid_is(s: seq<int>, indices: seq<int>) {
    (forall k: int, m: int :: 
        0 <= k < m < |indices| ==> indices[k] < indices[m])
    && 
    (forall k: int :: 
        0 <= k < |indices| ==> 0 <= indices[k] < |s|)
    && 
    (forall k: int, m: int :: 
        0 <= k < m < |indices| ==> s[indices[k]] < s[indices[m]])
}
// </preamble>

// Following is the block for potential helper specifications
// <helpers>

// </helpers>

// Following is the block for proofs of lemmas
// <proofs>

// </proofs>

// Following is the block for the main specification
// <spec>
method longest_increasing_subsequence(s: seq<int>) returns (result: int)
    requires |s| <= 0x7FFFFFFFFFFFFFFF
    ensures result >= 0
    ensures
        forall sub: seq<int> :: is_valid_is(s, sub) && |sub| > 0 ==> |sub| <= result
    ensures
        exists sub: seq<int> :: is_valid_is(s, sub) && |sub| == result
// </spec>
// <code>
{
    // Implement and verify the LIS algorithm here.
}
// </code>