Datasets:
Download level_1/17.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/17.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/17.rs
-
curl -L -o 17.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/17.rs
1.05 kB
| 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! | |