Function winter_math::polynom::syn_div_in_place
source · pub fn syn_div_in_place<E>(p: &mut [E], a: usize, b: E)where
E: FieldElement,
Expand description
Divides a polynomial by a polynomial of special form and saves the result into the original polynomial.
Specifically, divides polynomial p
by polynomial (x^a
- b
) using
synthetic division method and saves the
result into p
. If the polynomials don’t divide evenly, the remainder is ignored. Polynomial
p
is expected to be in the coefficient form, and the result will be in coefficient form as
well.
This function is significantly faster than the generic polynom::div()
function, and as
compared to polynom::syn_div()
function, this function does not allocate any additional
memory.
Panics
Panics if:
a
is zero;b
is zero;p.len()
is smaller than or equal toa
.
Examples
// p(x) = x^3 + x^2 + 2 * x + 2
let mut p = [
BaseElement::new(2),
BaseElement::new(2),
BaseElement::new(1),
BaseElement::new(1),
];
// divide by x + 1
syn_div_in_place(&mut p, 1, -BaseElement::ONE);
// expected result = x^2 + 2
let expected = [
BaseElement::new(2),
BaseElement::ZERO,
BaseElement::new(1),
BaseElement::ZERO,
];
assert_eq!(expected, p);