Function malachite_q::exhaustive::exhaustive_rational_range
source · pub fn exhaustive_rational_range(
a: Rational,
b: Rational,
) -> ExhaustiveRationalRange ⓘ
Expand description
Generates all Rational
s in the half-open interval $[a, b)$.
a
must be less than or equal to b
. If a
and b
are equal, the range is empty. To generate
all Rational
s in an infinite interval, use exhaustive_rational_range_to_infinity
or
exhaustive_rational_range_to_negative_infinity
.
The output length is infinite if $a<b$ and 0 if $a=b$.
§Worst-case complexity per iteration
$T(i) = O(\log i (\log \log i)^2 \log\log\log i)$
$M(i) = O(\log i \log \log i)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration number.
§Panics
Panics if $a>b$.
§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::conversion::traits::ExactFrom;
use malachite_q::exhaustive::exhaustive_rational_range;
use malachite_q::Rational;
assert_eq!(
prefix_to_string(
exhaustive_rational_range(
Rational::exact_from(std::f64::consts::E),
Rational::exact_from(std::f64::consts::PI)
),
20
),
"[3, 11/4, 14/5, 20/7, 17/6, 23/8, 25/8, 30/11, 25/9, 29/10, 26/9, 31/11, 28/9, 31/10, \
32/11, 41/15, 34/11, 35/12, 37/12, 39/14, ...]"
)