cova_algebra/lib.rs
1//! A Rust library for abstract algebra.
2//!
3//! This crate provides implementations of various algebraic structures and operations,
4//! with a focus on modular arithmetic and abstract algebra concepts.
5//!
6//! # Features
7//!
8//! - **Modular Arithmetic**: Create custom modular number types with the `modular!` macro
9//! - **Abstract Algebra**: Implementations of fundamental algebraic structures:
10//! - Groups (both Abelian and Non-Abelian)
11//! - Rings
12//! - Fields
13//! - Modules
14//! - Vector Spaces
15//!
16//! # Examples
17//!
18//! ## Modular Arithmetic
19//!
20//! ```
21//! use cova_algebra::{algebras::boolean::Boolean, modular, rings::Field};
22//!
23//! // Create a type for numbers modulo 7
24//! modular!(Mod7, u32, 7);
25//!
26//! let a = Mod7::new(3);
27//! let b = Mod7::new(5);
28//! let sum = a + b; // 8 ≡ 1 (mod 7)
29//! ```
30//!
31//! ## Vector Spaces
32//!
33//! ```
34//! use cova_algebra::{algebras::boolean::Boolean, rings::Field, tensors::fixed::FixedVector};
35//!
36//! let v1 = FixedVector::<3, f64>([1.0, 2.0, 3.0]);
37//! let v2 = FixedVector::<3, f64>([4.0, 5.0, 6.0]);
38//! let sum = v1 + v2;
39//! ```
40
41#![warn(missing_docs)]
42#![allow(incomplete_features)]
43#![feature(generic_const_exprs)]
44
45pub mod algebras;
46pub mod arithmetic;
47pub mod category;
48pub mod groups;
49pub mod modules;
50pub mod rings;
51pub mod tensors;
52
53pub use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
54
55pub use num_traits::{One, Zero};
56
57pub use crate::arithmetic::{Additive, Multiplicative};
58
59pub mod prelude {
60 //! # Prelude Module
61 //!
62 //! This module re-exports the most commonly used types, traits, and operations from the
63 //! algebra crate for convenient importing.
64 //!
65 //! ## Purpose
66 //!
67 //! The prelude pattern allows users to import multiple commonly used items with a single
68 //! import statement, reducing boilerplate and improving code readability.
69 //!
70 //! ## Contents
71 //!
72 //! The prelude includes:
73 //!
74 //! - Core algebraic structures: [`Algebra`], [`Group`], [`Ring`], [`Field`], [`VectorSpace`]
75 //! - Behavioral traits: [`Additive`], [`Multiplicative`]
76 //! - Group variants: [`AbelianGroup`], [`NonAbelianGroup`]
77 //! - Module types: [`LeftModule`], [`RightModule`], [`TwoSidedModule`]
78 //! - Semimodule types: [`LeftSemimodule`], [`RightSemimodule`], [`TwoSidedSemimodule`]
79 //! - Fundamental operators: [`Add`], [`Mul`], [`Sub`], [`Div`] and their assignment variants
80 //! - Identity concepts: [`Zero`], [`One`], [`Neg`]
81 //!
82 //! ## Usage
83 //!
84 //! ```
85 //! // Import everything from the prelude
86 //! use cova_algebra::prelude::*;
87 //! ```
88
89 pub use crate::{
90 algebras::Algebra,
91 arithmetic::{Additive, Multiplicative},
92 category::Category,
93 groups::{AbelianGroup, Group, NonAbelianGroup},
94 modules::{
95 LeftModule, LeftSemimodule, RightModule, RightSemimodule, TwoSidedModule, TwoSidedSemimodule,
96 VectorSpace,
97 },
98 rings::{Field, Ring},
99 Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, One, Sub, SubAssign, Zero,
100 };
101}
102
103#[cfg(test)]
104mod fixtures {
105 use crate::{modular, prime_field};
106
107 modular!(Mod7, u32, 7);
108 prime_field!(Mod7);
109}