Something went wrong. Try again.
forked from verus-lang/verus
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364#[allow(unused_imports)]use verus_builtin::*;use verus_builtin_macros::*;#[allow(unused_imports)]use vstd::{pervasive::*, seq::*, seq_lib::*};
verus! {
spec fn max_int(x: int, y: int) -> int { if x > y { x } else { y }}
// To enable recommends checking, use: spec(checked) instead of specspec fn seq_max_int(s: Seq<int>) -> int recommends s.len() > 0, // without this, spec(checked) generates a recommends warning below
decreases s.len(),{ let m = s[s.len() - 1]; if s.len() <= 1 { m } else { max_int(m, seq_max_int(s.drop_last())) }}
proof fn test(s: Seq<int>) requires seq_max_int(s) >= 0, // without this, the assertion fails and there's a recommends note{ assert(seq_max_int(s) >= 0);}
fn main() { proof { let s = seq![10, 20, 30, 25]; reveal_with_fuel(seq_max_int, 4); assert(seq_max_int(s) == 30); }}
// Usage of `spec_affirm`spec fn some_predicate(a: nat) -> bool recommends a < 100,{ if (a >= 50) { let _ = spec_affirm(50 <= a && a < 100); a >= 75 } else { let _ = spec_affirm(a < 40); // spec(checked) would raise a recommends note here a < 25 }}
} // verus!