ENT
Elementary Number Theory for Integers in Rust
The fastest provably correct library for primality checking in the interval 0;264 + 242 that is publicly available. Algebraic definitions of primality and factorization are used, permitting checks like -127.is_prime() to return true and unique factorizations to be considered unsigned.
Currently implements these functions
- Primality, prime-certificate generation
- Factorization
- GCD, Extended GCD, LCM
- Euler totient
- Jordan totient
- Dedekind psi
- Liouville function
- Prime-counting function/nth-prime, and prime lists
- Integer radical (not sqrt)
- K-free
- Quadratic and exponential residues
- Legendre symbol
- Jacobi symbol
- Smoothness checks
Additionally this library has an implementation of the previous NT functions for arbitrary-precision integers, plus some elementary arithmetic. Multiplication utilizes Karatsuba algorithm, otherwise all other arithmetic can be assumed to be naive.
- Addition/subtraction
- Multiplication
- Euclidean Division
- Conversion to and from radix-10 string
- Successor function (+1)
- SIRP-factorials {generalization of factorials}
- Conditional Interval Product (CIP factorial)
- Sqrt/nth root
- Exponentiation
- Logarithms
Usage is fairly simple
// include NT functions
use NumberTheory;
// include arbitrary-precision arithmetic
use Mpz;
// Sign, generally unnecessary for ENT
//use number_theory:Sign;
let mersenne = from_string.unwrap;
assert_eq!;
// Or for a more complex example
// check if x mod 1 === 0, trivial closure
let modulo = ;
//Generate 872 factorial, using the above trivial function
// this can be just as easily reproduced as Mpz::sirp(1,872,1,0);
let mut factorial = cip;
// Successor function, increment by one
factorial.successor;
// 872! + 1 is in-fact a factorial prime
assert_eq!