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 xx over a ring RR is an expression of the form:

f(x)=anxn+an1xn1++a1x+a0f(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0

where aiRa_i \in R are coefficients and nNn \in \mathbb{N} is the degree.

For multivariate polynomials in variables x1,x2,,xkx_1, x_2, \ldots, x_k:

f(x1,,xk)=αNkcαx1α1xkαkf(x_1, \ldots, x_k) = \sum_{\alpha \in \mathbb{N}^k} c_\alpha x_1^{\alpha_1} \cdots x_k^{\alpha_k}

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

🔗 Related Topics