Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add subrange_of_matching_take lemma to seq_lib #1276

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions source/vstd/seq_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,24 @@ pub proof fn lemma_seq_take_index<A>(s: Seq<A>, n: int, j: int)
{
}

pub proof fn subrange_of_matching_take<T>(a: Seq<T>, b: Seq<T>, s: int, e: int, l: int)
requires
a.take(l) == b.take(l),
l <= a.len(),
l <= b.len(),
0 <= s <= e <= l,
ensures
a.subrange(s, e) == b.subrange(s, e),
{
assert forall|i| 0 <= i < e - s implies a.subrange(s, e)[i] == b.subrange(s, e)[i] by {
assert(a.subrange(s, e)[i] == a.take(l)[i + s]);
// assert( b.subrange(s, e)[i] == b.take(l)[i + s] ); // either trigger will do
}
// trigger extn equality (verus issue #1257)

assert(a.subrange(s, e) == b.subrange(s, e));
}

// This verified lemma used to be an axiom in the Dafny prelude
/// Skipping the first `n` elements of a sequence gives a sequence of length `n` less than
/// the original sequence's length.
Expand Down