Algebra Crate
A Rust library providing algebraic structures and operations, with a focus on modular arithmetic and abstract algebra concepts.
Features
- Modular Arithmetic: Create custom modular number types with the
modular!macro - Abstract Algebra: Implementations of fundamental algebraic structures:
- Groups (both Abelian and Non-Abelian)
- Rings
- Fields
Usage
Modular Arithmetic
Create a new modular number type using the modular! macro:
modular!; // Creates a type for numbers modulo 7
let a = new;
let b = new;
let sum = a + b; // 8 ≡ 1 (mod 7)
Algebraic Structures
The crate provides traits for various algebraic structures:
Group: Basic group operations with identity and inverseAbelianGroup: Commutative groups with addition operationsNonAbelianGroup: Non-commutative groups with multiplication operationsRing: Structures with both addition and multiplicationField: Rings with multiplicative inverses
Dependencies
num: For numeric traits and operations
Examples
use ;
modular!;
// Group operations
let a = new;
let inverse = a.inverse; // 4 (mod 7)
let identity = identity; // 0 (mod 7)
// Ring operations
let one = one; // 1 (mod 7)
let zero = zero; // 0 (mod 7)