Datasets:
Download level_2/1.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/1.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/1.rs
-
curl -L -o 1.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/1.rs
1.72 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_interleave(s1: &Vec<i32>, s2: &Vec<i32>, s3: &Vec<i32>) -> (res: Vec<i32>) | |
| requires | |
| s1@.len() == s2@.len() && s2@.len() == s3@.len(), | |
| 0 <= (s1@.len() * 3) <= i32::MAX, | |
| { | |
| let new_seq_len = s1.len() * 3; | |
| let mut output_seq = Vec::with_capacity(new_seq_len); | |
| let mut index = 0; | |
| while index < s1.len() | |
| { | |
| output_seq.push(s1[index]); | |
| output_seq.push(s2[index]); | |
| output_seq.push(s3[index]); | |
| index += 1; | |
| } | |
| output_seq | |
| } | |
| fn f2_contains_k(arr: &Vec<i32>, k: i32) -> (result: bool) | |
| { | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| if (arr[index] == k) { | |
| return true; | |
| } | |
| index += 1; | |
| } | |
| false | |
| } | |
| spec fn step1(__hp0: Seq<i32>, __hp1: Seq<i32>, __hp2: Seq<i32>, outp: Seq<i32>) -> bool { | |
| (outp.len() == __hp0.len() * 3) | |
| && (forall|i: int| | |
| 0 <= i < __hp0.len() ==> (outp[3 * i] == __hp0[i] && outp[3 * i + 1] == __hp1[i] && outp[3 * i + 2] | |
| == __hp2[i])) | |
| } | |
| spec fn step2(inp: Seq<i32>, p2_k: i32, outp: bool) -> bool { | |
| (outp == (exists|i: int| 0 <= i < inp.len() && (inp[i] == p2_k))) | |
| } | |
| fn chain_driver(s1: &Vec<i32>, s2: &Vec<i32>, s3: &Vec<i32>, p2_k: i32) -> (r_final: bool) | |
| requires | |
| s1@.len() == s2@.len() && s2@.len() == s3@.len(), | |
| 0 <= (s1@.len() * 3) <= i32::MAX, | |
| ensures | |
| exists|v1: Seq<i32>| step1(s1@, s2@, s3@, v1) && step2(v1, p2_k, r_final), | |
| { | |
| let x1 = f1_interleave(s1, s2, s3); | |
| let x2 = f2_contains_k(&x1, p2_k); | |
| proof { | |
| assert(step1(s1@, s2@, s3@, x1@)); | |
| assert(step2(x1@, p2_k, x2)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |