Skip to main content

axiom_iterator_max_postcondition

Function axiom_iterator_max_postcondition 

Source
pub broadcast proof fn axiom_iterator_max_postcondition<A: Ord, I: Iterator<Item = A> + IteratorSpec>(
    iter: I,
    ret: Option<A>,
)
Expand description
requires
iter.obeys_prophetic_iter_laws(),
#[trigger] iterator_max_post(iter, ret),
ensures
iter.produces().all(|p: bool| p),
ret is None <==> iter.remaining().len() == 0,
obeys_cmp::<A>()
    ==> (ret matches Some(
        greatest,
    ) ==> {
        &&& iter.remaining().contains(greatest)
        &&& forall |k: int| {
            0 <= k < iter.remaining().len()
                ==> greatest.cmp_spec(&iter.remaining()[k]) != Ordering::Less
        }
        &&& exists |j: int| {
            0 <= j < iter.remaining().len() && iter.remaining()[j] == greatest
                && forall |k: int| {
                    j < k < iter.remaining().len()
                        ==> (#[trigger] iter.remaining()[k]).cmp_spec(&greatest)
                            == Ordering::Less
                }
        }

    }),

Connects Iterator::max to the prophetic iterator model on successful return. Like vstd’s provided-method specs in std_specs/iter.rs, this model trusts obeys_prophetic_iter_laws() to include consistency of consuming methods with next. Constraining the underlying implementations remains a vstd TODO. Membership and ordering guarantees additionally require vstd’s comparison laws.