Datasets:
Download level_1/5.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/5.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/5.rs
-
curl -L -o 5.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/5.rs
1.45 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| proof fn f1_lemma_vec_push<T>(vec: Seq<T>, i: T, l: usize) | |
| requires | |
| l == vec.len(), | |
| ensures | |
| forall|k: int| 0 <= k < vec.len() ==> vec[k] == vec.push(i)[k], | |
| vec.push(i).index(l as int) == i, | |
| { | |
| } | |
| fn f1_contains(arr: &Vec<i32>, key: i32) -> (result: bool) | |
| { | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| if (arr[index] == key) { | |
| return true; | |
| } | |
| index += 1; | |
| } | |
| false | |
| } | |
| fn f1_difference(arr1: &Vec<i32>, arr2: &Vec<i32>) -> (result: Vec<i32>) | |
| { | |
| let mut result = Vec::new(); | |
| let mut index = 0; | |
| while index < arr1.len() | |
| { | |
| if (!f1_contains(arr2, arr1[index]) && !f1_contains(&result, arr1[index])) { | |
| result.push(arr1[index]); | |
| } | |
| index += 1; | |
| } | |
| index = 0; | |
| while index < arr2.len() | |
| { | |
| if (!f1_contains(arr1, arr2[index]) && !f1_contains(&result, arr2[index])) { | |
| result.push(arr2[index]); | |
| } | |
| index += 1; | |
| } | |
| result | |
| } | |
| spec fn step1(__hp0: Seq<i32>, __hp1: i32, outp: bool) -> bool { | |
| (outp == (exists|i: int| 0 <= i < __hp0.len() && (__hp0[i] == __hp1))) | |
| } | |
| fn chain_driver(arr: &Vec<i32>, key: i32) -> (r_final: bool) | |
| ensures | |
| step1(arr@, key, r_final), | |
| { | |
| let x1 = f1_contains(arr, key); | |
| proof { | |
| assert(step1(arr@, key, x1)); | |
| } | |
| x1 | |
| } | |
| } // verus! | |