pub trait PolynomialGcd {
// Required methods
fn gcd(&self, other: &Self) -> Self;
fn lcm(&self, other: &Self) -> Self;
fn factor_gcd(&self) -> Self;
fn cofactors(&self, other: &Self) -> (Expression, Expression, Expression);
fn div_polynomial(
&self,
divisor: &Expression,
var: &Symbol,
) -> (Expression, Expression);
fn quo_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression;
fn rem_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression;
}Expand description
Trait for GCD operations on expressions
Required Methods§
fn gcd(&self, other: &Self) -> Self
fn lcm(&self, other: &Self) -> Self
fn factor_gcd(&self) -> Self
fn cofactors(&self, other: &Self) -> (Expression, Expression, Expression)
Sourcefn div_polynomial(
&self,
divisor: &Expression,
var: &Symbol,
) -> (Expression, Expression)
fn div_polynomial( &self, divisor: &Expression, var: &Symbol, ) -> (Expression, Expression)
Divides this polynomial by another, returning (quotient, remainder).
Performs polynomial long division with respect to the specified variable.
Returns a tuple (quotient, remainder) satisfying the division identity:
dividend = divisor * quotient + remainder where degree(remainder) < degree(divisor).
§Arguments
divisor- The polynomial to divide by (must be non-zero)var- The variable to treat as the polynomial variable
§Examples
use mathhook_core::{symbol, expr, Expression, algebra::gcd::PolynomialGcd};
let x = symbol!(x);
// Divide (x^2 + 3x + 2) by (x + 1)
// Expected: (x + 1)(x + 2) = x^2 + 3x + 2
let dividend = expr!((x^2) + (3*x) + 2);
let divisor = expr!(x + 1);
let (quotient, remainder) = dividend.div_polynomial(&divisor, &x);
assert_eq!(remainder, Expression::integer(0));§Returns
Returns (quotient, remainder) tuple where both are expressions
Sourcefn quo_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression
fn quo_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression
Returns the quotient of polynomial division.
Computes only the quotient part of polynomial division, discarding the remainder.
Equivalent to div_polynomial(divisor, var).0.
§Arguments
divisor- The polynomial to divide byvar- The variable to treat as the polynomial variable
§Examples
use mathhook_core::{symbol, expr, algebra::gcd::PolynomialGcd};
let x = symbol!(x);
let dividend = expr!((x^2) - 1);
let divisor = expr!(x - 1);
let quotient = dividend.quo_polynomial(&divisor, &x);
// quotient = x + 1§Returns
Returns the quotient expression
Sourcefn rem_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression
fn rem_polynomial(&self, divisor: &Expression, var: &Symbol) -> Expression
Returns the remainder of polynomial division.
Computes only the remainder part of polynomial division, discarding the quotient.
Equivalent to div_polynomial(divisor, var).1.
§Arguments
divisor- The polynomial to divide byvar- The variable to treat as the polynomial variable
§Examples
use mathhook_core::{symbol, expr, Expression, algebra::gcd::PolynomialGcd};
let x = symbol!(x);
let dividend = expr!((x^2) + 1);
let divisor = expr!(x - 1);
let remainder = dividend.rem_polynomial(&divisor, &x);
assert_eq!(remainder, Expression::integer(2));§Returns
Returns the remainder expression
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".