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.
§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
| Crate | Responsibility |
|---|---|
use-modular | Modular arithmetic operations and congruence checks |
use-integer | Integer classification and integer-specific descriptive helpers |
use-number | Broader number abstractions and shared numeric vocabulary |
use-prime | Primality, sieves, prime generation, and factorization |
use-algebra | Algebraic structures and law checking over caller-supplied ops |
use-combinatorics | Counting helpers that may consume modular arithmetic |
use-cryptography | Future 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.