File size: 1,053 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
use vstd::prelude::*;
fn main() {}
verus!{



spec fn f1_sum_to(arr: Seq<i64>) -> int
    decreases arr.len(),
{
    if arr.len() == 0 {
        0
    } else {
        f1_sum_to(arr.drop_last()) + arr.last()
    }
}

fn f1_sum_range_list(arr: &Vec<i64>, start: usize, end: usize) -> (sum: i128)
    requires
        0 <= start <= end,
        start <= end < arr.len(),
{
    let mut index = start;
    let mut sum = 0i128;
    let _end = end + 1;

    while index < _end
    {
        sum = sum + arr[index] as i128;
        index += 1;
    }
    sum
}



spec fn step1(__hp0: Seq<i64>, __hp1: usize, __hp2: usize, outp: i128) -> bool {
    (f1_sum_to(__hp0.subrange(__hp1 as int, __hp2 + 1 as int)) == outp)
}

fn chain_driver(arr: &Vec<i64>, start: usize, end: usize) -> (r_final: i128)
    requires
        0 <= start <= end,
        start <= end < arr.len(),
    ensures
        step1(arr@, start, end, r_final),
{
    let x1 = f1_sum_range_list(arr, start, end);
    proof {
        assert(step1(arr@, start, end, x1));
    }
    x1
}

} // verus!