opendp
opendp copied to clipboard
Binary search in chainers
Occasionally when we write relations, we only write the relation itself-- no constant, no forward map, no backward map. This can cause chaining to fail, because a hinter does not exist. We can, however, still find d_mid via binary search. In the past we've talked about how best to find the binary search bounds: maybe the search bounds are a const associated with a trait on metrics?
However, it would be simpler and better just to use this doubling trick, as the distances are always positive:
let mut lower = 0.;
let mut upper = 1.;
while !predicate(upper) {
lower = upper;
upper = 2.0 * upper;
}
The will terminate for some interval (2^(k - 1), 2^k)
, from which we can begin binary search. The python binary search is a good code snip to adapt for this.