../../.cargo/katex-header.html

Function winter_math::polynom::div

source ·
pub fn div<E>(a: &[E], b: &[E]) -> Vec<E>
where E: FieldElement,
Expand description

Returns a polynomial resulting from dividing one polynomial by another.

Specifically, divides polynomial a by polynomial b and returns the result. If the polynomials don’t divide evenly, the remainder is ignored. Both polynomials are expected to be in the coefficient form, and the returned polynomial will be in the coefficient form as well. The length of the returned vector will be a.len() - b.len() + 1.

§Panics

Panics if:

  • Polynomial b is empty.
  • Degree of polynomial b is zero and the constant coefficient is ZERO.
  • The degree of polynomial b is greater than the degree of polynomial a.

§Examples

// p1(x) = x^3 + x^2 + 2 * x + 2
let p1 = [
    BaseElement::new(2),
    BaseElement::new(2),
    BaseElement::new(1),
    BaseElement::new(1),
];
// p2(x) = x^2 + 2
let p2 = [BaseElement::new(2), BaseElement::ZERO, BaseElement::ONE];

// expected result = x + 1
let expected = vec![BaseElement::ONE, BaseElement::ONE];
assert_eq!(expected, div(&p1, &p2));