Function malachite_base::num::iterators::bit_distributor_sequence

source ·
pub fn bit_distributor_sequence(
    x_output_type: BitDistributorOutputType,
    y_output_type: BitDistributorOutputType
) -> BitDistributorSequence 
Expand description

Returns a sequence based on a BitDistributor.

The sequence is obtained by taking the second output of a two-output BitDistributor. If both output types are normal with weight 1, the sequence is https://oeis.org/A059905.

The smaller the first output type is relative to the second (where tiny outputs are smaller than normal outputs), the slower the sequence will grow.

  • If the first output type is normal and the second is tiny, the sequence grows as $O(n)$.
  • If the first output type is tiny and the second is normal, the sequence grows as $O(\log n)$.
  • If both output types are normal with weights $p$ and $q$, the sequence grows as $O(n^\frac{p}{p+q})$.
  • The output types cannot both be tiny.

Every number occurs infinitely many times, and any number’s first occurrence is after all smaller numbers have occured. The sequence increases by no more than 1 at each step, but may decrease by an arbitrarily large amount.

The output length is infinite.

§Complexity per iteration

Constant time and additional memory.

§Panics

Panics if both output types are tiny.

§Examples

use malachite_base::iterators::bit_distributor::BitDistributorOutputType;
use malachite_base::iterators::prefix_to_string;
use malachite_base::num::iterators::bit_distributor_sequence;

assert_eq!(
    prefix_to_string(
        bit_distributor_sequence(
            BitDistributorOutputType::normal(1),
            BitDistributorOutputType::normal(2)
        ),
        50
    ),
    "[0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, \
    3, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 2, 3, 0, 1, ...]"
);
assert_eq!(
    prefix_to_string(
        bit_distributor_sequence(
            BitDistributorOutputType::normal(2),
            BitDistributorOutputType::normal(1)
        ),
        50
    ),
    "[0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 8, 9, 10, 11, 8, 9, 10, 11, 12, 13, 14, \
    15, 12, 13, 14, 15, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 8, 9, ...]"
);