Datasets:
Download level_1/21.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 715 Bytes
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/21.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/21.rs
-
curl -L -o 21.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/21.rs
715 Bytes
| 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(arr: &Vec<i64>) -> (ret: i128) | |
| { | |
| let mut index = 0; | |
| let mut f1_sum = 0i128; | |
| while index < arr.len() | |
| { | |
| f1_sum = f1_sum + arr[index] as i128; | |
| index += 1; | |
| } | |
| f1_sum | |
| } | |
| spec fn step1(__hp0: Seq<i64>, outp: i128) -> bool { | |
| (f1_sum_to(__hp0) == outp) | |
| } | |
| fn chain_driver(arr: &Vec<i64>) -> (r_final: i128) | |
| ensures | |
| step1(arr@, r_final), | |
| { | |
| let x1 = f1_sum(arr); | |
| proof { | |
| assert(step1(arr@, x1)); | |
| } | |
| x1 | |
| } | |
| } // verus! | |