2 (* yet another binary search *)
7 use int.ComputerDivision
9 val function f int : int
11 axiom f_monotonic : forall x y : int. x <= y -> f x <= f y
13 let rec binary_search target lo hi variant { hi-lo }
14 requires { f lo < target <= f hi }
15 ensures { f result >= target /\
16 forall x : int. x < result -> f x < target }
18 let mid = div (lo + hi) 2 in
19 if f mid < target then
20 binary_search target mid hi
22 binary_search target lo mid