Datasets:
Download level_1/37.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 906 Bytes
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/37.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/37.rs
-
curl -L -o 37.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/37.rs
906 Bytes
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| spec fn f1_sum_negative_to(seq: Seq<i64>) -> int | |
| decreases seq.len(), | |
| { | |
| if seq.len() == 0 { | |
| 0 | |
| } else { | |
| f1_sum_negative_to(seq.drop_last()) + if (seq.last() < 0) { | |
| seq.last() as int | |
| } else { | |
| 0 as int | |
| } | |
| } | |
| } | |
| fn f1_sum_negatives(arr: &Vec<i64>) -> (sum_neg: i128) | |
| { | |
| let mut index = 0; | |
| let mut sum_neg = 0i128; | |
| while index < arr.len() | |
| { | |
| if (arr[index] < 0) { | |
| sum_neg = sum_neg + (arr[index] as i128); | |
| } | |
| index += 1; | |
| } | |
| sum_neg | |
| } | |
| spec fn step1(__hp0: Seq<i64>, outp: i128) -> bool { | |
| (f1_sum_negative_to(__hp0) == outp) | |
| } | |
| fn chain_driver(arr: &Vec<i64>) -> (r_final: i128) | |
| ensures | |
| step1(arr@, r_final), | |
| { | |
| let x1 = f1_sum_negatives(arr); | |
| proof { | |
| assert(step1(arr@, x1)); | |
| } | |
| x1 | |
| } | |
| } // verus! | |