Datasets:
Download level_2/28.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/28.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/28.rs
-
curl -L -o 28.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/28.rs
1.5 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_get_first_elements(arr: &Vec<Vec<i32>>) -> (result: Vec<i32>) | |
| requires | |
| forall|i: int| 0 <= i < arr.len() ==> arr[i].len() > 0, | |
| { | |
| let mut first_elem_arr: Vec<i32> = Vec::new(); | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| let seq = &arr[index]; | |
| first_elem_arr.push(seq[0]); | |
| index += 1; | |
| } | |
| first_elem_arr | |
| } | |
| fn f2_find_negative_numbers(arr: &Vec<i32>) -> (negative_list: Vec<i32>) | |
| { | |
| let mut negative_list: Vec<i32> = Vec::new(); | |
| let input_len = arr.len(); | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| if (arr[index] < 0) { | |
| negative_list.push(arr[index]); | |
| } | |
| index += 1; | |
| } | |
| negative_list | |
| } | |
| spec fn step1(__hp0: Seq<Vec<i32>>, outp: Seq<i32>) -> bool { | |
| (__hp0.len() == outp.len()) | |
| && (forall|i: int| 0 <= i < __hp0.len() ==> outp[i] == __hp0[i][0]) | |
| } | |
| spec fn step2(inp: Seq<i32>, outp: Seq<i32>) -> bool { | |
| (outp == inp.filter(|x: i32| x < 0)) | |
| } | |
| fn chain_driver(arr: &Vec<Vec<i32>>) -> (r_final: Vec<i32>) | |
| requires | |
| forall|i: int| 0 <= i < arr.len() ==> arr[i].len() > 0, | |
| ensures | |
| exists|v1: Seq<i32>| step1(arr@, v1) && step2(v1, r_final@), | |
| { | |
| let x1 = f1_get_first_elements(arr); | |
| let x2 = f2_find_negative_numbers(&x1); | |
| proof { | |
| assert(step1(arr@, x1@)); | |
| assert(step2(x1@, x2@)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |