Datasets:
Download level_2/23.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/23.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/23.rs
-
curl -L -o 23.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/23.rs
1.26 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_filter_odd_numbers(arr: &Vec<u32>) -> (odd_list: Vec<u32>) | |
| { | |
| let mut odd_list: Vec<u32> = Vec::new(); | |
| let input_len = arr.len(); | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| if (arr[index] % 2 != 0) { | |
| odd_list.push(arr[index]); | |
| } | |
| index += 1; | |
| } | |
| odd_list | |
| } | |
| fn f2_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 step1(__hp0: Seq<u32>, outp: Seq<u32>) -> bool { | |
| (outp == __hp0.filter(|x: u32| x % 2 != 0)) | |
| } | |
| spec fn step2(inp: Seq<u32>, outp: Seq<u32>) -> bool { | |
| (outp == inp.filter(|x: u32| x % 2 != 0)) | |
| } | |
| fn chain_driver(arr: &Vec<u32>) -> (r_final: Vec<u32>) | |
| ensures | |
| exists|v1: Seq<u32>| step1(arr@, v1) && step2(v1, r_final@), | |
| { | |
| let x1 = f1_filter_odd_numbers(arr); | |
| let x2 = f2_find_odd_numbers(&x1); | |
| proof { | |
| assert(step1(arr@, x1@)); | |
| assert(step2(x1@, x2@)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |