Datasets:
Download level_1/44.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/44.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/44.rs
-
curl -L -o 44.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/44.rs
1.31 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_sub_array_at_index(main: &Vec<i32>, sub: &Vec<i32>, idx: usize) -> (result: bool) | |
| requires | |
| 0 <= idx <= (main.len() - sub.len()), | |
| { | |
| let mut i = 0; | |
| while i < sub.len() | |
| { | |
| if (main[idx + i] != sub[i]) { | |
| return false; | |
| } | |
| i += 1; | |
| } | |
| true | |
| } | |
| spec fn f1_is_subrange_at(main: Seq<i32>, sub: Seq<i32>, i: int) -> bool { | |
| sub =~= main.subrange(i, i + sub.len()) | |
| } | |
| fn f1_is_sub_array(main: &Vec<i32>, sub: &Vec<i32>) -> (result: bool) | |
| { | |
| if sub.len() > main.len() { | |
| return false; | |
| } | |
| let mut index = 0; | |
| while index <= (main.len() - sub.len()) | |
| { | |
| if (f1_sub_array_at_index(&main, &sub, index)) { | |
| return true; | |
| } | |
| index += 1; | |
| } | |
| false | |
| } | |
| spec fn step1(__hp0: Seq<i32>, __hp1: Seq<i32>, __hp2: usize, outp: bool) -> bool { | |
| (outp == (__hp0.subrange(__hp2 as int, (__hp2 + __hp1.len())) =~= __hp1)) | |
| } | |
| fn chain_driver(main: &Vec<i32>, sub: &Vec<i32>, idx: usize) -> (r_final: bool) | |
| requires | |
| 0 <= idx <= (main.len() - sub.len()), | |
| ensures | |
| step1(main@, sub@, idx, r_final), | |
| { | |
| let x1 = f1_sub_array_at_index(main, sub, idx); | |
| proof { | |
| assert(step1(main@, sub@, idx, x1)); | |
| } | |
| x1 | |
| } | |
| } // verus! | |