Datasets:
File size: 1,580 Bytes
c62beea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | use vstd::prelude::*;
fn main() {}
verus!{
fn f1_find_negative_numbers(arr: &Vec<i32>) -> (negative_list: Vec<i32>)
{
let mut negative_list: Vec<i32> = Vec::new();
let input_len = arr.len();
let mut index = 0;
while index < arr.len()
{
if (arr[index] < 0) {
negative_list.push(arr[index]);
}
index += 1;
}
negative_list
}
fn f2_contains(arr: &Vec<i32>, key: i32) -> (result: bool)
{
let mut i = 0;
while i < arr.len()
{
if (arr[i] == key) {
return true;
}
i += 1;
}
false
}
fn f2_intersection(arr1: &Vec<i32>, arr2: &Vec<i32>) -> (result: Vec<i32>)
{
let mut output_arr = Vec::new();
let mut index = 0;
while index < arr1.len()
{
if (f2_contains(arr2, arr1[index]) && !f2_contains(&output_arr, arr1[index])) {
output_arr.push(arr1[index]);
}
index += 1;
}
output_arr
}
spec fn step1(__hp0: Seq<i32>, outp: Seq<i32>) -> bool {
(outp == __hp0.filter(|x: i32| x < 0))
}
spec fn step2(inp: Seq<i32>, p2_key: i32, outp: bool) -> bool {
(outp == (exists|i: int| 0 <= i < inp.len() && (inp[i] == p2_key)))
}
fn chain_driver(arr: &Vec<i32>, p2_key: i32) -> (r_final: bool)
ensures
exists|v1: Seq<i32>| #[trigger] step1(arr@, v1) && step2(v1, p2_key, r_final),
{
let x1 = f1_find_negative_numbers(arr);
let x2 = f2_contains(&x1, p2_key);
proof {
assert(step1(arr@, x1@));
assert(step2(x1@, p2_key, x2));
}
x2
}
} // verus!
|