Expand description
Prime utilities, factorization, and channel (base) selection.
All functions here are pure and have no dependency on the rest of the crate.
§The “natural base” concept
The natural base of a computation is the LCM of the radicals of all
denominators involved. This is the minimal base in which every fraction in
the computation terminates exactly. For example,
natural_base(&[6, 10, 15]) == 30, because radical(6)=6, radical(10)=10,
radical(15)=15 and lcm(6,10,15)=30.
Functions§
- distinct_
primes - The distinct prime factors of
n, ascending. - extended_
gcd - Extended Euclidean algorithm.
- factorize
- Factorize
ninto(prime, exponent)pairs in ascending prime order.factorize(0)andfactorize(1)return an empty vector. - first_
n_ primes - The first
nprimes. - gcd
- Euclidean greatest common divisor.
- lcm
- Least common multiple.
lcm(0, x) == 0. - mod_
inverse - Modular inverse of
amodulom, orNonewhengcd(a, m) != 1. - natural_
base - Minimal exact base for a set of denominators: the LCM of their radicals.
- primes_
up_ to - Sieve of Eratosthenes: all primes
<= n. - radical
- Product of the distinct prime factors of
n(the squarefree kernel).radical(12) == 6,radical(1) == 1,radical(0) == 0. - termination_
period - Determine how
1/nbehaves when written in the givenbase.