Expand description
Unified Polynomial Module
This module provides comprehensive polynomial operations with automatic classification, smart dispatch, and optional educational explanations.
§Architecture
The polynomial module is designed around these principles:
-
Automatic Classification: Users don’t need to manually wrap expressions. The system automatically detects polynomial structure and routes to optimized algorithms.
-
Decomposed Traits: Instead of a monolithic trait, functionality is split into:
PolynomialClassification- Type detection and variable extractionPolynomialProperties- Degree, leading coefficient, content, primitive partPolynomialArithmetic- Division operationsPolynomialGcdOps- GCD, LCM, cofactorsPolynomialEducational- Step-by-step explanations (opt-in)
-
Side-Table Caching: Expensive computations (degree, classification) are cached using thread-local LRU cache, preserving the 32-byte Expression size constraint.
-
Smart Dispatch: GCD and other functions check cheap cases (integers, zero, one, symbols) BEFORE expensive classification.
-
Unified Dispatch: The
dispatchmodule automatically routes operations to the optimalPoly<T>implementation based on coefficient type analysis:- All integers →
IntPoly(fastest) - Any rationals →
RationalPoly(field operations) - Multivariate → symbolic fallback
- All integers →
§Example
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let p1 = expr!(x^2 - 1);
let p2 = expr!(x - 1);
// Automatic polynomial GCD - no wrapping needed!
let gcd = p1.gcd(&p2); // Returns x - 1§Submodules
algorithms- Core polynomial algorithms (division, GCD, factorization)dispatch- Unified dispatch to optimalPoly<T>implementationseducational- Step-by-step explanation generationgroebner- Groebner basis computation (migrated from algebra/groebner)sparse_polynomial- Efficient sparse polynomial representationspecial_families- Orthogonal polynomials (Legendre, Hermite, etc.)
Re-exports§
pub use educational::PolynomialEducational;pub use poly::IntPoly;pub use poly::Poly;pub use poly::RationalPoly;pub use traits::EuclideanDomain;pub use traits::Field;pub use traits::Ring;pub use crate::algebra::gcd::polynomial_gcd;pub use crate::algebra::gcd::univariate_gcd;pub use algorithms::integer_gcd;pub use algorithms::square_free_factorization_poly;pub use sparse_polynomial::expression_to_sparse_polynomial;pub use sparse_polynomial::sparse_polynomial_to_expression;pub use sparse_polynomial::Monomial;pub use sparse_polynomial::SparsePolynomial;
Modules§
- algorithms
- Polynomial Algorithm Implementations
- dispatch
- Unified polynomial dispatch layer
- educational
- Polynomial Educational Module
- finite_
field - Finite Field Arithmetic for Modular GCD Algorithms
- groebner
- Groebner Basis Computation
- poly
- Generic univariate polynomial over any ring
- sparse_
polynomial - Efficient Sparse Polynomial Representation for Gröbner Basis
- special_
families - Special Polynomial Families
- traits
- Algebraic trait hierarchy for polynomial coefficient types
Structs§
- Cache
Stats - Cache statistics for monitoring
- Polynomial
Cache - Thread-local polynomial computation cache
Enums§
- Cached
Classification - Cached classification result
- Polynomial
Error - Errors that can occur during polynomial operations
Traits§
- Polynomial
Arithmetic - Trait for polynomial arithmetic operations
- Polynomial
Classification - Trait for polynomial classification
- Polynomial
GcdOps - Trait for polynomial GCD operations
- Polynomial
Properties - Trait for polynomial properties
Functions§
- cache_
stats - Get statistics from the thread-local polynomial cache
- clear_
cache - Clear the thread-local polynomial cache
- coefficient_
at - Get the coefficient at a specific degree
- coefficients_
list - Get all coefficients as a vector ordered by degree (ascending)
- constant_
term - Extract the constant term (coefficient of degree 0)
- extract_
coefficient_ map - Extract all coefficients of a polynomial as a map from degree to coefficient
- get_
or_ compute_ intpoly - Get or compute IntPoly representation with caching
- is_
monic - Check if polynomial is monic (leading coefficient is 1)
- with_
cache - Access the thread-local polynomial cache