Datasets:
Download level_2/18.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/18.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/18.rs
-
curl -L -o 18.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/18.rs
1.24 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_find_odd_numbers(arr: &Vec<u32>) -> (odd_numbers: Vec<u32>) | |
| { | |
| let mut odd_numbers: Vec<u32> = Vec::new(); | |
| let input_len = arr.len(); | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| if (arr[index] % 2 != 0) { | |
| odd_numbers.push(arr[index]); | |
| } | |
| index += 1; | |
| } | |
| odd_numbers | |
| } | |
| spec fn f2_is_even(n: u32) -> bool { | |
| (n % 2) == 0 | |
| } | |
| fn f2_is_product_even(arr: &Vec<u32>) -> (result: bool) | |
| { | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| if (arr[index] % 2 == 0) { | |
| return true; | |
| } | |
| index += 1; | |
| } | |
| false | |
| } | |
| spec fn step1(__hp0: Seq<u32>, outp: Seq<u32>) -> bool { | |
| (outp == __hp0.filter(|x: u32| x % 2 != 0)) | |
| } | |
| spec fn step2(inp: Seq<u32>, outp: bool) -> bool { | |
| (outp <==> (exists|k: int| 0 <= k < inp.len() && f2_is_even( inp[k]))) | |
| } | |
| fn chain_driver(arr: &Vec<u32>) -> (r_final: bool) | |
| ensures | |
| exists|v1: Seq<u32>| step1(arr@, v1) && step2(v1, r_final), | |
| { | |
| let x1 = f1_find_odd_numbers(arr); | |
| let x2 = f2_is_product_even(&x1); | |
| proof { | |
| assert(step1(arr@, x1@)); | |
| assert(step2(x1@, x2)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |