Datasets:
Download level_2/41.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/41.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_2/41.rs
-
curl -L -o 41.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_2/41.rs
1.96 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(str: &[u8], key: u8) -> (result: bool) | |
| { | |
| let mut i = 0; | |
| while i < str.len() | |
| { | |
| if (str[i] == key) { | |
| return true; | |
| } | |
| i += 1; | |
| } | |
| false | |
| } | |
| fn f1_remove_chars(str1: &[u8], str2: &[u8]) -> (result: Vec<u8>) | |
| { | |
| let mut output_str = Vec::new(); | |
| let mut index: usize = 0; | |
| while index < str1.len() | |
| { | |
| if (!f1_contains(str2, str1[index])) { | |
| output_str.push(str1[index]); | |
| } | |
| index += 1; | |
| } | |
| output_str | |
| } | |
| fn f2_contains_z(text: &[u8]) -> (result: bool) | |
| { | |
| let mut index = 0; | |
| while index < text.len() | |
| { | |
| if text[index] == 90 || text[index] == 122 { | |
| return true; | |
| } | |
| index += 1; | |
| } | |
| false | |
| } | |
| spec fn step1(__hp0: Seq<u8>, __hp1: Seq<u8>, outp: Seq<u8>) -> bool { | |
| (forall|i: int| | |
| 0 <= i < outp.len() ==> (__hp0.contains( outp[i]) && !__hp1.contains( | |
| outp[i], | |
| ))) | |
| && (forall|i: int| | |
| 0 <= i < __hp0.len() ==> (__hp1.contains( __hp0[i]) || outp.contains( | |
| __hp0[i], | |
| ))) | |
| } | |
| spec fn step2(inp: Seq<u8>, outp: bool) -> bool { | |
| (outp == (exists|i: int| 0 <= i < inp.len() && (inp[i] == 90 || inp[i] == 122))) | |
| } | |
| fn chain_driver(str1: &[u8], str2: &[u8]) -> (r_final: bool) | |
| ensures | |
| exists|v1: Seq<u8>| step1(str1@, str2@, v1) && step2(v1, r_final), | |
| { | |
| let x1 = f1_remove_chars(str1, str2); | |
| let x2 = f2_contains_z(x1.as_slice()); | |
| proof { | |
| assert(step1(str1@, str2@, x1@)); | |
| assert(step2(x1@, x2)); | |
| } | |
| x2 | |
| } | |
| } // verus! | |