Datasets:
Download level_2/37.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/37.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/37.rs
-
curl -L -o 37.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/37.rs
1.59 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_max_length_list(seq: &Vec<Vec<i32>>) -> (max_list: &Vec<i32>) | |
| requires | |
| seq.len() > 0, | |
| { | |
| let mut max_list = &seq[0]; | |
| let mut index = 1; | |
| while index < seq.len() | |
| { | |
| if ((seq[index]).len() > max_list.len()) { | |
| max_list = &seq[index]; | |
| } | |
| index += 1; | |
| } | |
| max_list | |
| } | |
| fn f2_insert_before_each(arr: &Vec<i32>, elem: i32) -> (result: Vec<i32>) | |
| { | |
| let mut result: Vec<i32> = Vec::new(); | |
| let mut index = 0; | |
| while index < arr.len() | |
| { | |
| result.push(elem); | |
| result.push(arr[index]); | |
| index += 1; | |
| } | |
| result | |
| } | |
| spec fn step1(__hp0: Seq<Vec<i32>>, outp: Seq<i32>) -> bool { | |
| (forall|k: int| 0 <= k < __hp0.len() ==> outp.len() >= (__hp0[k]).len()) | |
| && (exists|k: int| 0 <= k < __hp0.len() && outp =~= (__hp0[k]@)) | |
| } | |
| spec fn step2(inp: Seq<i32>, p2_elem: i32, outp: Seq<i32>) -> bool { | |
| (outp.len() == (2 * inp.len())) | |
| && (forall|k: int| 0 <= k < inp.len() ==> outp[2 * k] == p2_elem) | |
| && (forall|k: int| 0 <= k < inp.len() ==> outp[2 * k + 1] == inp[k]) | |
| } | |
| fn chain_driver(seq: &Vec<Vec<i32>>, p2_elem: i32) -> (r_final: Vec<i32>) | |
| requires | |
| seq.len() > 0, | |
| ensures | |
| exists|v1: Seq<i32>| step1(seq@, v1) && step2(v1, p2_elem, r_final@), | |
| { | |
| let x1 = f1_max_length_list(seq); | |
| let x2 = f2_insert_before_each(x1, p2_elem); | |
| proof { | |
| assert(step1(seq@, x1@)); | |
| assert(step2(x1@, p2_elem, x2@)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |