File size: 878 Bytes
c62beea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use vstd::prelude::*;
fn main() {}
verus!{



spec fn f1_count_boolean(seq: Seq<bool>) -> int
    decreases seq.len(),
{
    if seq.len() == 0 {
        0
    } else {
        f1_count_boolean(seq.drop_last()) + if (seq.last()) {
            1 as int
        } else {
            0 as int
        }
    }
}

fn f1_count_true(arr: &Vec<bool>) -> (count: u64)
{
    let mut index = 0;
    let mut counter = 0;

    while index < arr.len()
    {
        if (arr[index]) {
            counter += 1;
        }
        index += 1;

    }
    counter
}



spec fn step1(__hp0: Seq<bool>, outp: u64) -> bool {
    (0 <= outp <= __hp0.len())
    && (f1_count_boolean(__hp0) == outp)
}

fn chain_driver(arr: &Vec<bool>) -> (r_final: u64)
    ensures
        step1(arr@, r_final),
{
    let x1 = f1_count_true(arr);
    proof {
        assert(step1(arr@, x1));
    }
    x1
}

} // verus!