| Crates.io | harness-algebra |
| lib.rs | harness-algebra |
| version | 0.6.0 |
| created_at | 2025-04-29 13:05:20.601361+00 |
| updated_at | 2025-05-23 19:54:58.092518+00 |
| description | The library for algebraic structures |
| homepage | |
| repository | https://github.com/harness-labs/space |
| max_upload_size | |
| id | 1653512 |
| size | 225,205 |
A Rust library providing algebraic structures and operations, with a focus on modular arithmetic and abstract algebra concepts.
modular! macroAdd this to your Cargo.toml:
[dependencies]
harness-algebra = "*"
Create a new modular number type using the modular! macro:
use harness_algebra::{group::Group, modular, ring::Ring};
// Create a type for numbers modulo 7
modular!(Mod7, u32, 7);
let a = Mod7::new(3);
let b = Mod7::new(5);
// Addition: 3 + 5 = 8 ≡ 1 (mod 7)
let sum = a + b;
assert_eq!(sum.value(), 1);
// Multiplication: 3 * 5 = 15 ≡ 1 (mod 7)
let product = a * b;
assert_eq!(product.value(), 1);
Create and manipulate vectors over any field, such as the finite field of integers modulo 7:
use harness_algebra::{vector::{Vector, VectorSpace}, ring::Field, modular};
modular!(Mod7, u32, 7);
prime_field!(Mod7);
impl Field for Mod7 {
fn multiplicative_inverse(&self) -> Self {
todo!("Implement multiplicative inverse for Mod7")
}
}
let v1 = Vector::<3, Mod7>([Mod7::new(1), Mod7::new(2), Mod7::new(3)]);
let v2 = Vector::<3, Mod7>([Mod7::new(4), Mod7::new(5), Mod7::new(6)]);
let sum = v1 + v2;
The complete API documentation is available on docs.rs.
arithmetic: Basic arithmetic traits and operationsgroup: Group theory abstractions and implementationsring: Ring theory abstractions and implementationsmodule: Module theory abstractions and implementationsvector: Vector space abstractions and implementationsmodular: Modular arithmetic abstractions and implementationsContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.
use algebra::{Group, Ring};
modular!(Mod7, u32, 7);
// Group operations
let a = Mod7::new(3);
let inverse = a.inverse(); // 4 (mod 7)
let identity = Mod7::identity(); // 0 (mod 7)
// Ring operations
let one = Mod7::one(); // 1 (mod 7)
let zero = Mod7::zero(); // 0 (mod 7)