Datasets:
Download level_1/53.rs from CodeWalk/verus-proof-completion: direct link, hf CLI and curl.
- Browser
- Download file 982 Bytes
-
https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/53.rs
- Command line
-
hf download hf://datasets/CodeWalk/verus-proof-completion/level_1/53.rs
-
curl -L -o 53.rs https://huggingface.co/datasets/CodeWalk/verus-proof-completion/resolve/main/level_1/53.rs
982 Bytes
| use vstd::prelude::*; | |
| fn main() {} | |
| verus!{ | |
| fn f1_linear_search(nums: Vec<i32>, target: i32) -> (ret: i32) | |
| requires | |
| nums@.len() < 0x8000_0000, | |
| { | |
| let mut i = 0; | |
| while i < nums.len() | |
| { | |
| if nums[i] == target { | |
| break; | |
| } | |
| i = i + 1; | |
| } | |
| if i == nums.len() { | |
| -1 | |
| } else { | |
| i as i32 | |
| } | |
| } | |
| spec fn step1(__hp0: Seq<i32>, __hp1: i32, outp: i32) -> bool { | |
| (outp < __hp0.len()) | |
| && (outp >=0 ==> __hp0[outp as int] == __hp1) | |
| && (outp >=0 ==> forall |i: int| 0 <= i < outp as int ==> __hp0[i]!= __hp1) | |
| && (outp < 0 ==> forall |i: int| 0 <= i < __hp0.len() as int ==> __hp0[i] != __hp1) | |
| } | |
| fn chain_driver(nums: Vec<i32>, target: i32) -> (r_final: i32) | |
| requires | |
| nums@.len() < 0x8000_0000, | |
| ensures | |
| step1(nums@, target, r_final), | |
| { | |
| let x1 = f1_linear_search(nums, target); | |
| proof { | |
| assert(step1(nums@, target, x1)); | |
| } | |
| x1 | |
| } | |
| } // verus! | |