Datasets:
Download level_2/38.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/38.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/38.rs
-
curl -L -o 38.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/38.rs
1.77 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_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 f1_shared_elements(list1: &Vec<i32>, list2: &Vec<i32>) -> (shared: Vec<i32>) | |
| { | |
| let mut shared = Vec::new(); | |
| let mut index = 0; | |
| while index < list1.len() | |
| { | |
| if (f1_contains(list2, list1[index]) && !f1_contains(&shared, list1[index])) { | |
| shared.push(list1[index]); | |
| } | |
| index += 1 | |
| } | |
| shared | |
| } | |
| fn f2_all_elements_equals(arr: &Vec<i32>, element: i32) -> (result: bool) | |
| { | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| if arr[index] != element { | |
| return false; | |
| } | |
| index += 1; | |
| } | |
| true | |
| } | |
| spec fn step1(__hp0: Seq<i32>, __hp1: Seq<i32>, outp: Seq<i32>) -> bool { | |
| (forall|i: int| | |
| 0 <= i < outp.len() ==> (__hp0.contains( outp[i]) && __hp1.contains( | |
| outp[i], | |
| ))) | |
| && (forall|i: int, j: int| 0 <= i < j < outp.len() ==> outp[i] != outp[j]) | |
| } | |
| spec fn step2(inp: Seq<i32>, p2_element: i32, outp: bool) -> bool { | |
| (outp == (forall|i: int| 0 <= i < inp.len() ==> (inp[i] == p2_element))) | |
| } | |
| fn chain_driver(list1: &Vec<i32>, list2: &Vec<i32>, p2_element: i32) -> (r_final: bool) | |
| ensures | |
| exists|v1: Seq<i32>| step1(list1@, list2@, v1) && step2(v1, p2_element, r_final), | |
| { | |
| let x1 = f1_shared_elements(list1, list2); | |
| let x2 = f2_all_elements_equals(&x1, p2_element); | |
| proof { | |
| assert(step1(list1@, list2@, x1@)); | |
| assert(step2(x1@, p2_element, x2)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |