use vstd::prelude::*; fn main() {} verus!{ fn f1_replace_last_element(first: &Vec, second: &Vec) -> (replaced_list: Vec) requires first.len() > 0, { let mut replaced_list = Vec::new(); let first_end = first.len() - 1; let mut index = 0; while index < first_end { replaced_list.push(first[index]); index += 1; } index = 0; while index < second.len() { replaced_list.push(second[index]); index += 1; } replaced_list } fn f2_insert_before_each(arr: &Vec, elem: i32) -> (result: Vec) { let mut result: Vec = Vec::new(); let mut index = 0; while index < arr.len() { result.push(elem); result.push(arr[index]); index += 1; } result } fn f3_find_negative_numbers(arr: &Vec) -> (negative_list: Vec) { let mut negative_list: Vec = 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 } spec fn step1(__hp0: Seq, __hp1: Seq, outp: Seq) -> bool { (outp == __hp0.subrange(0, __hp0.len() - 1).add(__hp1)) } spec fn step2(inp: Seq, p2_elem: i32, outp: Seq) -> bool { (outp.len() == (2 * inp.len())) && (forall|k: int| 0 <= k < inp.len() ==> #[trigger] outp[2 * k] == p2_elem) && (forall|k: int| 0 <= k < inp.len() ==> #[trigger] outp[2 * k + 1] == inp[k]) } spec fn step3(inp: Seq, outp: Seq) -> bool { (outp == inp.filter(|x: i32| x < 0)) } fn chain_driver(first: &Vec, second: &Vec, p2_elem: i32) -> (r_final: Vec) requires first.len() > 0, ensures exists|v1: Seq, v2: Seq| #[trigger] step1(first@, second@, v1) && #[trigger] step2(v1, p2_elem, v2) && step3(v2, r_final@), { let x1 = f1_replace_last_element(first, second); let x2 = f2_insert_before_each(&x1, p2_elem); let x3 = f3_find_negative_numbers(&x2); proof { assert(step1(first@, second@, x1@)); assert(step2(x1@, p2_elem, x2@)); assert(step3(x2@, x3@)); } x3 } } // verus!