let dichotomy_extended middle succ pred f inf sup =
assert (inf <= sup);
let inf = ref inf in let sup = ref sup in
while !inf < !sup do
let middle = middle !inf !sup in
match f middle with
| Pervasives.Lt -> inf := succ middle (* This is Femtolib.Pervasives.Lt *)
| Pervasives.Gt -> sup := pred middle
| Pervasives.Eq -> inf := middle; sup := middle
done;
!inf