Datasets:
Download level_1/30.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/30.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/30.rs
-
curl -L -o 30.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/30.rs
1.34 kB
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_sub_array_at_index(main: &Vec<i32>, sub: &Vec<i32>, idx: usize) -> (result: bool) | |
| requires | |
| sub.len() <= main.len(), | |
| 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 | |
| } | |
| fn f1_is_sub_array(main: &Vec<i32>, sub: &Vec<i32>) -> (result: bool) | |
| requires | |
| sub.len() <= main.len(), | |
| { | |
| 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>, outp: bool) -> bool { | |
| (outp == (exists|k: int, l: int| | |
| 0 <= k <= (__hp0.len() - __hp1.len()) && l == k + __hp1.len() && ( (__hp0.subrange( | |
| k, | |
| l, | |
| ))) =~= __hp1)) | |
| } | |
| fn chain_driver(main: &Vec<i32>, sub: &Vec<i32>) -> (r_final: bool) | |
| requires | |
| sub.len() <= main.len(), | |
| ensures | |
| step1(main@, sub@, r_final), | |
| { | |
| let x1 = f1_is_sub_array(main, sub); | |
| proof { | |
| assert(step1(main@, sub@, x1)); | |
| } | |
| x1 | |
| } | |
| } // verus! | |