iota-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Algorithm.Search.SternBrocot

Synopsis

Documentation

binarySearchRational :: Integer -> (Rational -> Ordering) -> (Rational, Rational) Source #

>>> binarySearchRational 100 (\x -> compare (x * x) 2)
(140 % 99,99 % 70)
>>> map (fromRational @Double) [140 % 99,  99 % 70]
[1.4141414141414141,1.4142857142857144]
>>> binarySearchRational (10^10) (`compare`(1 % (10^10)))
(1 % 10000000000,1 % 9999999999)
>>> binarySearchRational (10^10) (`compare`((10^10-1) % (10^10)))
(9999999999 % 10000000000,1 % 1)

binarySearchMinRational :: Integer -> (Rational -> Bool) -> Rational Source #

>>> binarySearchMinRational 100 (1 <)
101 % 100
>>> binarySearchMinRational 100 (1 <=)
1 % 1

binarySearchMaxRational :: Integer -> (Rational -> Bool) -> Rational Source #

>>> binarySearchMaxRational 100 (< 1)
99 % 100
>>> binarySearchMaxRational 100 (<= 1)
1 % 1