Datasets:
Download level_2/35.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/35.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/35.rs
-
curl -L -o 35.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/35.rs
1.85 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_element_wise_divide(arr1: &Vec<u32>, arr2: &Vec<u32>) -> (result: Vec<u32>) | |
| requires | |
| arr1.len() == arr2.len(), | |
| forall|i: int| 0 <= i < arr2.len() ==> arr2[i] != 0, | |
| forall|i: int| | |
| (0 <= i < arr1.len()) ==> (i32::MIN <= (arr1[i] / arr2[i]) <= i32::MAX), | |
| { | |
| let mut output_arr = Vec::with_capacity(arr1.len()); | |
| let mut index = 0; | |
| while index < arr1.len() | |
| { | |
| output_arr.push((arr1[index] / arr2[index])); | |
| index += 1; | |
| } | |
| output_arr | |
| } | |
| 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>, __hp1: Seq<u32>, outp: Seq<u32>) -> bool { | |
| (outp.len() == __hp0.len()) | |
| && (forall|i: int| | |
| 0 <= i < outp.len() ==> outp[i] == (__hp0[i] / __hp1[i])) | |
| } | |
| spec fn step2(inp: Seq<u32>, outp: Seq<u32>) -> bool { | |
| (outp == inp.filter(|x: u32| x % 2 != 0)) | |
| } | |
| fn chain_driver(arr1: &Vec<u32>, arr2: &Vec<u32>) -> (r_final: Vec<u32>) | |
| requires | |
| arr1.len() == arr2.len(), | |
| forall|i: int| 0 <= i < arr2.len() ==> arr2[i] != 0, | |
| forall|i: int| | |
| (0 <= i < arr1.len()) ==> (i32::MIN <= (arr1[i] / arr2[i]) <= i32::MAX), | |
| ensures | |
| exists|v1: Seq<u32>| step1(arr1@, arr2@, v1) && step2(v1, r_final@), | |
| { | |
| let x1 = f1_element_wise_divide(arr1, arr2); | |
| let x2 = f2_find_odd_numbers(&x1); | |
| proof { | |
| assert(step1(arr1@, arr2@, x1@)); | |
| assert(step2(x1@, x2@)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |