Datasets:
Download level_2/46.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/46.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/46.rs
-
curl -L -o 46.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/46.rs
1.88 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_cube_element(nums: &Vec<i32>) -> (cubed: Vec<i32>) | |
| requires | |
| forall|k: int| | |
| 0 <= k < nums.len() ==> (i32::MIN <= nums[k] * nums[k] | |
| <= i32::MAX), | |
| forall|k: int| | |
| 0 <= k < nums.len() ==> (i32::MIN <= nums[k] * nums[k] | |
| * nums[k] <= i32::MAX), | |
| { | |
| let mut cubed_array: Vec<i32> = Vec::new(); | |
| let mut i = 0; | |
| while i < nums.len() | |
| { | |
| cubed_array.push(nums[i] * nums[i] * nums[i]); | |
| i += 1; | |
| } | |
| cubed_array | |
| } | |
| fn f2_is_greater(arr: &Vec<i32>, number: i32) -> (result: bool) | |
| { | |
| let mut i = 0; | |
| while i < arr.len() | |
| { | |
| if number <= arr[i] { | |
| return false; | |
| } | |
| i += 1; | |
| } | |
| true | |
| } | |
| spec fn step1(__hp0: Seq<i32>, outp: Seq<i32>) -> bool { | |
| (forall|i: int| | |
| 0 <= i < __hp0.len() ==> outp[i] == __hp0[i] * __hp0[i] | |
| * __hp0[i]) | |
| } | |
| spec fn step2(inp: Seq<i32>, p2_number: i32, outp: bool) -> bool { | |
| (outp == (forall|i: int| 0 <= i < inp.len() ==> p2_number > inp[i])) | |
| } | |
| fn chain_driver(nums: &Vec<i32>, p2_number: i32) -> (r_final: bool) | |
| requires | |
| forall|k: int| | |
| 0 <= k < nums.len() ==> (i32::MIN <= nums[k] * nums[k] | |
| <= i32::MAX), | |
| forall|k: int| | |
| 0 <= k < nums.len() ==> (i32::MIN <= nums[k] * nums[k] | |
| * nums[k] <= i32::MAX), | |
| ensures | |
| exists|v1: Seq<i32>| step1(nums@, v1) && step2(v1, p2_number, r_final), | |
| { | |
| let x1 = f1_cube_element(nums); | |
| let x2 = f2_is_greater(&x1, p2_number); | |
| proof { | |
| assert(step1(nums@, x1@)); | |
| assert(step2(x1@, p2_number, x2)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |