Datasets:
Download level_2/43.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/43.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/43.rs
-
curl -L -o 43.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/43.rs
1.74 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_remove_kth_element(list: &Vec<i32>, k: usize) -> (new_list: Vec<i32>) | |
| requires | |
| list.len() > 0, | |
| 0 < k < list@.len(), | |
| { | |
| let mut new_list = Vec::new(); | |
| let mut index = 0; | |
| while index < (k - 1) | |
| { | |
| new_list.push(list[index]); | |
| index += 1; | |
| } | |
| let mut index = k; | |
| while index < list.len() | |
| { | |
| new_list.push(list[index]); | |
| index += 1; | |
| } | |
| new_list | |
| } | |
| fn f2_contains(arr: &Vec<i32>, key: i32) -> (result: bool) | |
| { | |
| let mut i = 0; | |
| while i < arr.len() | |
| { | |
| if (arr[i] == key) { | |
| return true; | |
| } | |
| i += 1; | |
| } | |
| false | |
| } | |
| fn f2_any_value_exists(arr1: &Vec<i32>, arr2: &Vec<i32>) -> (result: bool) | |
| { | |
| let mut index = 0; | |
| while index < arr1.len() | |
| { | |
| if (f2_contains(arr2, arr1[index])) { | |
| return true; | |
| } | |
| index += 1; | |
| } | |
| false | |
| } | |
| spec fn step1(__hp0: Seq<i32>, __hp1: usize, outp: Seq<i32>) -> bool { | |
| (outp == __hp0.subrange(0, __hp1 - 1 as int).add( | |
| __hp0.subrange(__hp1 as int, __hp0.len() as int), | |
| )) | |
| } | |
| spec fn step2(inp: Seq<i32>, p2_key: i32, outp: bool) -> bool { | |
| (outp == (exists|i: int| 0 <= i < inp.len() && (inp[i] == p2_key))) | |
| } | |
| fn chain_driver(list: &Vec<i32>, k: usize, p2_key: i32) -> (r_final: bool) | |
| requires | |
| list.len() > 0, | |
| 0 < k < list@.len(), | |
| ensures | |
| exists|v1: Seq<i32>| step1(list@, k, v1) && step2(v1, p2_key, r_final), | |
| { | |
| let x1 = f1_remove_kth_element(list, k); | |
| let x2 = f2_contains(&x1, p2_key); | |
| proof { | |
| assert(step1(list@, k, x1@)); | |
| assert(step2(x1@, p2_key, x2)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |