Skip to main content

Crate use_modular

Crate use_modular 

Source
Expand description

§use-modular

Small modular arithmetic primitives for RustUse.
Normalized modular residues, congruence checks, inverses, and exponentiation without number-taxonomy or cryptographic protocol concerns.

Rust 1.95.0+ Edition 2024 Modular arithmetic License MIT or Apache-2.0

§Install

[dependencies]
use-modular = "0.0.5"

§What belongs here

use-modular owns small modular arithmetic operations over primitive signed integers. It keeps normalization, addition, subtraction, multiplication, exponentiation, inverses, and congruence checks explicit while always returning residues normalized to 0..modulus.

Invalid moduli are handled conservatively: functions return None when modulus <= 0, and congruence checks return false.

§Neighboring crates

CrateResponsibility
use-modularModular arithmetic operations and congruence checks
use-integerInteger classification and integer-specific descriptive helpers
use-numberBroader number abstractions and shared numeric vocabulary
use-primePrimality, sieves, prime generation, and factorization
use-algebraAlgebraic structures and law checking over caller-supplied ops
use-combinatoricsCounting helpers that may consume modular arithmetic
use-cryptographyFuture protocol and cryptographic constructions built on modularity

use-modular intentionally does not define primality testing, factorization, ring traits, cryptographic protocols, or large arbitrary- precision integer types.

§Examples

§Normalize and combine residues

use use_modular::{mod_add, mod_mul, mod_sub};

assert_eq!(mod_add(4, 3, 5), Some(2));
assert_eq!(mod_sub(2, 4, 5), Some(3));
assert_eq!(mod_mul(4, 4, 5), Some(1));

§Exponentiation and inverse

use use_modular::{mod_inverse, mod_pow};

assert_eq!(mod_pow(2, 10, 1_000), Some(24));
assert_eq!(mod_inverse(3, 11), Some(4));

§Congruence

use use_modular::is_congruent;

assert!(is_congruent(17, 5, 12));
assert!(!is_congruent(17, 6, 12));

§Status

use-modular is a concrete pre-1.0 crate in the RustUse math workspace. The API stays explicit and dependency-free so adjacent integer, number, algebra, combinatorics, and future cryptography crates can share one small modular arithmetic vocabulary. Small modular arithmetic primitives for RustUse.

Re-exports§

pub use arithmetic::mod_add;
pub use arithmetic::mod_mul;
pub use arithmetic::mod_normalize;
pub use arithmetic::mod_sub;
pub use congruence::is_congruent;
pub use inverse::mod_inverse;
pub use power::mod_pow;

Modules§

arithmetic
Basic modular arithmetic helpers.
congruence
Modular congruence helpers.
inverse
Modular inverse helpers.
power
Modular exponentiation helpers.

Structs§

Modular
A normalized modular residue paired with its positive modulus.