Polynomial Division and Factorization
Polynomial division algorithms including long division, exact division, and factorization capabilities such as square-free factorization, resultant, and discriminant computation.
Mathematical Definition
Polynomial Long Division: For polynomials with :
where is the quotient and is the remainder with .
Resultant: The resultant of polynomials of degrees is:
where are roots of respectively. Properties: - and share a common root - Computed as determinant of Sylvester matrix
Discriminant: For polynomial of degree with leading coefficient :
Properties: - has a repeated root - For quadratic :
Code Examples
Polynomial Long Division
Compute quotient and remainder using standard division algorithm
use mathhook_core::core::polynomial::algorithms::polynomial_long_division;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
// Divide (x^2 - 1) by (x - 1)
let dividend = expr!((x ^ 2) - 1);
let divisor = expr!(x - 1);
let (quotient, remainder) = polynomial_long_division(÷nd, &divisor, &x).unwrap();
// quotient = x + 1
// remainder = 0
// Verify: dividend = divisor * quotient + remainder
Exact Division
Division that errors if remainder is non-zero
use mathhook_core::core::polynomial::algorithms::exact_division;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
// x^2 / x = x (exact)
let dividend = expr!(x ^ 2);
let divisor = expr!(x);
match exact_division(÷nd, &divisor, &x) {
Ok(quotient) => println!("Exact quotient: {}", quotient),
Err(e) => println!("Division not exact: {:?}", e),
}
Trait-Based Division
Use PolynomialArithmetic trait for ergonomic API
use mathhook_core::core::polynomial::PolynomialArithmetic;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let f = expr!((x ^ 3) - 1);
let g = expr!(x - 1);
// Returns (quotient, remainder)
let (q, r) = f.poly_div(&g, &x).unwrap();
// q = x^2 + x + 1
// r = 0
Polynomial Resultant
Test for common roots using resultant
use mathhook_core::core::polynomial::algorithms::polynomial_resultant;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
// p1 = x - 1
let p1 = expr!(x - 1);
// p2 = x - 2
let p2 = expr!(x - 2);
let res = polynomial_resultant(&p1, &p2, &x).unwrap();
// Resultant is non-zero (distinct roots)
Polynomial Discriminant
Detect repeated roots using discriminant
use mathhook_core::core::polynomial::algorithms::polynomial_discriminant;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
// (x - 1)^2 = x^2 - 2x + 1 (repeated root at 1)
let poly = expr!((x ^ 2) - (2 * x) + 1);
let disc = polynomial_discriminant(&poly, &x).unwrap();
// Discriminant = 0 (repeated root)