Something went wrong. Try again.
forked from verus-lang/verus
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990#[allow(unused_imports)]use verus_builtin::*;#[allow(unused_imports)]use verus_builtin_macros::*;#[allow(unused_imports)]use vstd::seq::*;
fn main() {}
verus! {
// ANCHOR: pow_concrete// Naive definition of exponentiationspec fn pow(base: nat, exp: nat) -> nat decreases exp,{ if exp == 0 { 1 } else { base * pow(base, (exp - 1) as nat) }}
proof fn concrete_pow() { assert(pow(2, 8) == 256) by (compute); // Assertion 1 assert(pow(2, 9) == 512); // Assertion 2 assert(pow(2, 8) == 256) by (compute_only); // Assertion 3}// ANCHOR_END: pow_concrete
/*// ANCHOR: let_failslet x = 2;assert(pow(2, x) == 4) by (compute_only);// ANCHOR_END: let_fails*/
// ANCHOR: let_passesproof fn let_passes() { assert({ let x = 2; pow(2, x) == 4 }) by (compute_only);}// ANCHOR_END: let_passes
// ANCHOR: seq_exampleproof fn seq_example(a: Seq<int>, b: Seq<int>, c: Seq<int>, d: Seq<int>) { assert(seq![a, b, c, d] =~= seq![a, b].add(seq![c, d])) by (compute_only);}// ANCHOR_END: seq_example
// ANCHOR: fibonacci_memoize#[verifier::memoize]spec fn fibonacci(n: nat) -> nat decreases n{ if n == 0 { 0 } else if n == 1 { 1 } else { fibonacci((n - 2) as nat) + fibonacci((n - 1) as nat) }}
proof fn test_fibonacci() { assert(fibonacci(63) == 6557470319842) by(compute_only);}// ANCHOR_END: fibonacci_memoize
// ANCHOR: all_specuse vstd::compute::RangeAll;
spec fn p(u: usize) -> bool { u >> 8 == 0}
proof fn range_property(u: usize) requires 25 <= u < 100, ensures p(u),{ assert((25..100int).all_spec(|x: int| p(x as usize))) by (compute_only); let prop = |x: int| p(x as usize); assert(prop(u as int));}// ANCHOR_END: all_spec
} // verus!