Polynomial Module Overview
Comprehensive symbolic polynomial manipulation capabilities in MathHook. Implements a trait-based architecture for automatic classification, property computation, arithmetic operations, and GCD algorithms.
📐
Mathematical Definition
A polynomial in variable over a ring is an expression of the form:
where are coefficients and is the degree.
For multivariate polynomials in variables :
Code Examples
Basic Polynomial Usage
Create polynomials and compute properties using trait-based API
use mathhook_core::core::polynomial::{
PolynomialClassification,
PolynomialProperties,
PolynomialGcdOps
};
use mathhook_core::{expr, symbol};
let x = symbol!(x);
// Create polynomials using expr! macro
let f = expr!((x ^ 2) + (2 * x) + 1); // x^2 + 2x + 1
let g = expr!((x ^ 2) - 1); // x^2 - 1
// Properties
assert_eq!(f.degree(&x), Some(2));
assert!(f.is_polynomial_in(&[x.clone()]));
// GCD computation
let gcd = f.polynomial_gcd(&g).unwrap();
// gcd = x + 1 (since f = (x+1)^2 and g = (x+1)(x-1))
Polynomial Classification
Automatic detection of polynomial structure and variable extraction
use mathhook_core::core::polynomial::PolynomialClassification;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let y = symbol!(y);
// Automatic detection
let poly = expr!((x ^ 2) + (y * x) + 1);
assert!(poly.is_polynomial());
assert!(poly.is_polynomial_in(&[x.clone(), y.clone()]));
// Variable extraction
let vars = poly.polynomial_variables();
// vars contains x and y
Content and Primitive Part
Extract GCD of coefficients and primitive polynomial
use mathhook_core::core::polynomial::PolynomialProperties;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let poly = expr!((6 * (x ^ 2)) + (9 * x) + 3); // 6x^2 + 9x + 3
let content = poly.content(); // 3
let primitive = poly.primitive_part(); // 2x^2 + 3x + 1