Expand description
§numbers_rus
A number-theory and exact-arithmetic toolkit for Rust, organised around three pillars:
- Number theory — deterministic Miller-Rabin primality, Sieve of
Eratosthenes, wheel-factored integer factorization, GCD/LCM via the
binary Euclidean algorithm, modular exponentiation and inversion,
Euler’s totient, and the Chinese Remainder Theorem.
See
integers::primesandintegers::arith. - Exact arithmetic — generic
rational::Rationalover any signed integer type (auto-reducing), and genericcomplex::Complexwith full operator overloading. - Symbolic objects — typed
equation::Equationand single-variableequation::Polynomialwith Horner evaluation, differentiation, and arithmetic.
A lightweight stats module rounds this out with mean, median,
variance, std_dev, quartiles, and iqr over any slice of a numeric
type convertible to f64.
§Quick tour
use numbers_rus::integers::{primes, arith, sequences};
use numbers_rus::rational::Rational;
use numbers_rus::equation::{Equation, Op, Polynomial};
// Primality in microseconds, even for large u64.
assert!(primes::is_prime(1_000_003));
assert!(!primes::is_prime(1_000_004));
// Modular arithmetic for crypto-adjacent problems.
assert_eq!(arith::mod_pow(2, 10, 1000), 24);
assert_eq!(arith::mod_inverse(3, 11), Some(4));
// Exact rationals.
let r = Rational::new(2i64, 4) + Rational::new(1, 3);
assert_eq!(format!("{}", r), "5/6");
// Typed equations (no sentinel-value bugs).
let mut eq = Equation::new(0i64, 0, Op::Add);
assert_eq!(eq.solve(), 0); // zero is a valid solution, not "not computed"
// Polynomials.
let p = Polynomial::new(vec![1, 0, -1]); // 1 - x^2
assert_eq!(p.eval(3), -8);§Feature flags
std(default) — enablesstd-dependent APIs (currently everything;no_stdsupport is planned for a future release).serde— derivesSerializeandDeserializeonrational::Rational,complex::Complex,equation::Equation,equation::Op, andequation::Polynomial.
§Migrating from 0.2
The 1.0 release is a substantial reshape. See the CHANGELOG for the full rename table; the highlights:
solve::equation::Equation::get_sol()is nowequation::Equation::solve, backed byOption<T>rather than a0sentinel.integers::base::is_primeis replaced byintegers::primes::is_prime(Miller-Rabin, deterministic foru64).single::single_vector::*is replaced bystats, which takes&[T]and returns numeric results instead ofString.structures::dataframe,vector::vector, andnumbers::complexhave been removed.