PolynomialGcdOps

Trait PolynomialGcdOps 

Source
pub trait PolynomialGcdOps: PolynomialClassification {
    // Required methods
    fn polynomial_gcd(
        &self,
        other: &Self,
    ) -> Result<Expression, PolynomialError>;
    fn polynomial_lcm(
        &self,
        other: &Self,
    ) -> Result<Expression, PolynomialError>;
    fn polynomial_cofactors(
        &self,
        other: &Self,
    ) -> Result<(Expression, Expression, Expression), PolynomialError>;
}
Expand description

Trait for polynomial GCD operations

Provides methods for computing GCD, LCM, and cofactors of polynomial expressions. The implementation uses IntPoly fast-path when possible.

§Examples

use mathhook_core::core::polynomial::PolynomialGcdOps;
use mathhook_core::core::Expression;
use mathhook_core::{symbol, expr};

let x = symbol!(x);
// x^2 - 1 = (x-1)(x+1)
let p1 = expr!((x ^ 2) - 1);
// x - 1
let p2 = expr!(x - 1);

let gcd = p1.polynomial_gcd(&p2).unwrap();
// GCD divides both polynomials

Required Methods§

Source

fn polynomial_gcd(&self, other: &Self) -> Result<Expression, PolynomialError>

Compute GCD of two polynomials

Returns the greatest common divisor of self and other. Uses IntPoly fast-path for integer univariate polynomials.

§Arguments
  • other - The other polynomial
§Returns

Returns Ok(gcd) on success, or Err(PolynomialError) if the operation fails.

Source

fn polynomial_lcm(&self, other: &Self) -> Result<Expression, PolynomialError>

Compute LCM of two polynomials

Returns the least common multiple of self and other.

Source

fn polynomial_cofactors( &self, other: &Self, ) -> Result<(Expression, Expression, Expression), PolynomialError>

Compute GCD and cofactors

Returns tuple (gcd, self/gcd, other/gcd).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§