Function malachite_q::exhaustive::exhaustive_rationals
source · pub fn exhaustive_rationals(
) -> Chain<Once<Rational>, ExhaustiveNonzeroRationals>
Expand description
Generates all Rational
s.
The sequence begins with zero and is followed by the sequence of positive Rational
s,
interleaved with its negative. See exhaustive_positive_rationals
for details.
The output length is infinite. The absolute values of the numerators and denominators of the $n$th element are $O(n^\frac{\log \phi}{\log 2})$.
§Worst-case complexity per iteration
$T(n) = O(\log n \log\log n \log\log\log n)$
$M(i) = O(\log n \log\log n)$
where $T$ is time, $M$ is additional memory, and $n$ is the iteration number.
§Examples
use malachite_base::iterators::prefix_to_string;
use malachite_q::exhaustive::exhaustive_rationals;
assert_eq!(
prefix_to_string(exhaustive_rationals(), 20),
"[0, 1, -1, 1/2, -1/2, 2, -2, 1/3, -1/3, 3/2, -3/2, 2/3, -2/3, 3, -3, 1/4, -1/4, 4/3, \
-4/3, 3/5, ...]"
)