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

Function winter_math::polynom::add[][src]

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

Returns a polynomial resulting from adding two polynomials together.

Polynomials a and b 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 max(a.len(), b.len()).

Examples

// p1(x) = 4 * x^2 + 3 * x + 2
let p1 = (2_u32..5).map(BaseElement::from).collect::<Vec<_>>();
// p2(x) = 2 * x + 1
let p2 = (1_u32..3).map(BaseElement::from).collect::<Vec<_>>();

// expected result = 4 * x^2 + 5 * x + 3
let expected = vec![
    BaseElement::new(3),
    BaseElement::new(5),
    BaseElement::new(4),
];
assert_eq!(expected, add(&p1, &p2));