Crates.io | number-theory |
lib.rs | number-theory |
version | |
source | src |
created_at | 2021-12-26 02:46:08.027051+00 |
updated_at | 2025-03-07 12:54:38.251684+00 |
description | Fast primality, factorization and elementary number theory for integer types |
homepage | |
repository | https://github.com/JASory/ENT |
max_upload_size | |
id | 503168 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Elementary Number Theory for Integers in Rust
Algebraic definitions of primality and factorization are used, permitting checks like -127.is_prime() to return true and unique factorizations to be considered unsigned.
WIP, will probably considerably improve this over (northern hemisphere) summer of 2025.
Currently implements these functions
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.
Usage is fairly simple
// include NT functions
use number_theory::NumberTheory;
// include arbitrary-precision arithmetic
use number_theory::Mpz;
// Sign, generally unnecessary for ENT
//use number_theory:Sign;
let mersenne = Mpz::from_string("-127").unwrap();
assert_eq!(mersenne.is_prime(), true);
// Or for a more complex example
// check if x mod 1 === 0, trivial closure
let modulo = |x: &u64| {if x%1==0{return true} return false};
//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 = Mpz::cip(1, 872,modulo);
// Successor function, increment by one
factorial.successor();
// 872! + 1 is in-fact a factorial prime
assert_eq!(factorial.is_prime(),true)