pub trait PolynomialProperties: PolynomialClassification {
// Required methods
fn degree(&self, var: &Symbol) -> Option<i64>;
fn total_degree(&self) -> Option<i64>;
fn leading_coefficient(&self, var: &Symbol) -> Expression;
fn content(&self) -> Expression;
fn primitive_part(&self) -> Expression;
}Expand description
Trait for polynomial properties
Provides methods for computing polynomial properties such as degree, leading coefficient, content, and primitive part. Results are cached using thread-local LRU caching for performance.
§Examples
use mathhook_core::core::polynomial::{PolynomialClassification, PolynomialProperties};
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let poly = expr!(x ^ 3);
assert_eq!(poly.degree(&x), Some(3));Required Methods§
Sourcefn degree(&self, var: &Symbol) -> Option<i64>
fn degree(&self, var: &Symbol) -> Option<i64>
Compute degree with respect to a variable
Returns the highest power of the variable in the polynomial.
§Arguments
var- The variable to compute degree for
§Returns
Some(degree) if the expression is a polynomial in the variable,
None if not a polynomial.
§Examples
use mathhook_core::core::polynomial::PolynomialProperties;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
assert_eq!(expr!(x ^ 3).degree(&x), Some(3));
assert_eq!(expr!(5).degree(&x), Some(0));Sourcefn total_degree(&self) -> Option<i64>
fn total_degree(&self) -> Option<i64>
Compute total degree (sum of degrees in all variables)
For multivariate polynomials, returns the maximum sum of exponents across all terms.
§Examples
use mathhook_core::core::polynomial::PolynomialProperties;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let y = symbol!(y);
let poly = expr!(x * y); // x*y has total degree 2
assert_eq!(poly.total_degree(), Some(2));Sourcefn leading_coefficient(&self, var: &Symbol) -> Expression
fn leading_coefficient(&self, var: &Symbol) -> Expression
Get leading coefficient with respect to a variable
Returns the coefficient of the highest degree term.
§Arguments
var- The variable to find leading coefficient for
§Examples
use mathhook_core::core::polynomial::PolynomialProperties;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let poly = expr!((5 * (x ^ 2)) + (3 * x) + 1);
// Leading coefficient of 5x^2 + 3x + 1 is 5
let lc = poly.leading_coefficient(&x);Sourcefn content(&self) -> Expression
fn content(&self) -> Expression
Extract content (GCD of all coefficients)
The content is the GCD of all numeric coefficients in the polynomial.
§Examples
use mathhook_core::core::polynomial::PolynomialProperties;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let poly = expr!((6 * (x ^ 2)) + (9 * x) + 3);
// Content of 6x^2 + 9x + 3 is 3
let content = poly.content();Sourcefn primitive_part(&self) -> Expression
fn primitive_part(&self) -> Expression
Extract primitive part (polynomial divided by content)
The primitive part is the polynomial with content factored out.
§Examples
use mathhook_core::core::polynomial::PolynomialProperties;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let poly = expr!((6 * (x ^ 2)) + (9 * x) + 3);
// Primitive part of 6x^2 + 9x + 3 is 2x^2 + 3x + 1
let pp = poly.primitive_part();