Datasets:
Download level_3/4.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_3/4.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_3/4.rs
-
curl -L -o 4.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_3/4.rs
2.04 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_replace_last_element(first: &Vec<i32>, second: &Vec<i32>) -> (replaced_list: Vec<i32>) | |
| requires | |
| first.len() > 0, | |
| { | |
| let mut replaced_list = Vec::new(); | |
| let first_end = first.len() - 1; | |
| let mut index = 0; | |
| while index < first_end | |
| { | |
| replaced_list.push(first[index]); | |
| index += 1; | |
| } | |
| index = 0; | |
| while index < second.len() | |
| { | |
| replaced_list.push(second[index]); | |
| index += 1; | |
| } | |
| replaced_list | |
| } | |
| 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 | |
| } | |
| fn f3_contains_k(arr: &Vec<i32>, k: i32) -> (result: bool) | |
| { | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| if (arr[index] == k) { | |
| return true; | |
| } | |
| index += 1; | |
| } | |
| false | |
| } | |
| spec fn step1(__hp0: Seq<i32>, __hp1: Seq<i32>, outp: Seq<i32>) -> bool { | |
| (outp == __hp0.subrange(0, __hp0.len() - 1).add(__hp1)) | |
| } | |
| spec fn step2(inp: Seq<i32>, outp: Seq<i32>) -> bool { | |
| (outp == inp.filter(|x: i32| x < 0)) | |
| } | |
| spec fn step3(inp: Seq<i32>, p3_k: i32, outp: bool) -> bool { | |
| (outp == (exists|i: int| 0 <= i < inp.len() && (inp[i] == p3_k))) | |
| } | |
| fn chain_driver(first: &Vec<i32>, second: &Vec<i32>, p3_k: i32) -> (r_final: bool) | |
| requires | |
| first.len() > 0, | |
| ensures | |
| exists|v1: Seq<i32>, v2: Seq<i32>| step1(first@, second@, v1) && step2(v1, v2) && step3(v2, p3_k, r_final), | |
| { | |
| let x1 = f1_replace_last_element(first, second); | |
| let x2 = f2_find_negative_numbers(&x1); | |
| let x3 = f3_contains_k(&x2, p3_k); | |
| proof { | |
| assert(step1(first@, second@, x1@)); | |
| assert(step2(x1@, x2@)); | |
| assert(step3(x2@, p3_k, x3)); | |
| } | |
| x3 | |
| } | |
| } // verus! | |