clifford_codegen/algebra/mod.rs
1//! Core blade algebra computations.
2//!
3//! This module provides the mathematical foundation for code generation:
4//!
5//! - [`Blade`]: Represents a basis blade with canonical ordering
6//! - [`Algebra`]: Encapsulates a geometric algebra with its metric signature
7//! - [`ProductTable`]: Precomputed product lookup for efficient code generation
8//!
9//! # Canonical Ordering
10//!
11//! Blades are represented as bitmasks where bit `i` indicates the presence
12//! of basis vector `eᵢ`. This representation is inherently canonical:
13//!
14//! | Blade | Binary | Index |
15//! |-------|--------|-------|
16//! | 1 | `0000` | 0 |
17//! | e₁ | `0001` | 1 |
18//! | e₂ | `0010` | 2 |
19//! | e₁₂ | `0011` | 3 |
20//! | e₃ | `0100` | 4 |
21//!
22//! # Sign Computation
23//!
24//! When computing `eₐ * eᵦ`, the sign comes from:
25//! 1. Swaps needed to reorder into canonical form
26//! 2. Metric contributions when basis vectors square
27//!
28//! # Example
29//!
30//! ```
31//! use clifford_codegen::algebra::{Algebra, Blade, ProductTable};
32//!
33//! let algebra = Algebra::euclidean(3);
34//! let table = ProductTable::new(&algebra);
35//!
36//! // e1 * e2 = e12 with sign +1
37//! let (sign, result) = table.geometric(1, 2);
38//! assert_eq!(sign, 1);
39//! assert_eq!(result, 3);
40//!
41//! // e2 * e1 = -e12 (anticommutative)
42//! let (sign, result) = table.geometric(2, 1);
43//! assert_eq!(sign, -1);
44//! assert_eq!(result, 3);
45//! ```
46
47mod blade;
48mod constraints;
49mod grade;
50#[cfg(test)]
51mod proptest;
52mod sign;
53mod signature;
54mod table;
55#[cfg(test)]
56mod verification;
57mod versor;
58
59pub use blade::Blade;
60pub use constraints::{
61 satisfies_all_constraints, satisfies_antiproduct_constraint, satisfies_geometric_constraint,
62};
63pub use grade::{
64 antireverse_sign, binomial, blades_of_grade, blades_of_grades, clifford_conjugate_sign,
65 geometric_grades, grade, grade_involution_sign, inner_grade, left_contraction_grade,
66 outer_grade, reverse_sign,
67};
68pub use sign::basis_product;
69pub use signature::Algebra;
70pub use table::{ProductContribution, ProductContributions, ProductTable};
71pub use versor::{VersorInfo, VersorParity, versor_parity};