18 #ifndef _POLYNOMIALMULTIPLICATIONSIMPLE_IPP_
19 #define _POLYNOMIALMULTIPLICATIONSIMPLE_IPP_
20 #include "../include/PolynomialMultiplicationSimple.hpp"
21 #include "../include/Polynomial.hpp"
25 template <
typename FieldT>
32 if ((p1.
size() ==0) || (p2.
size() == 0)) {
35 size_t result_size = p1.
size() + p2.
size() -1;
48 const std::list<FieldT>* pptr = &(this->getPolynomialCoefficients(p2));
49 const std::list<FieldT>* qptr = &(this->getPolynomialCoefficients(p1));
52 pptr = &(this->getPolynomialCoefficients(p1));
53 qptr = &(this->getPolynomialCoefficients(p2));
55 const std::list<FieldT>& p = *pptr;
56 const std::list<FieldT>& q = *qptr;
57 size_t deg_p = p.size() -1;
58 size_t deg_q = q.size() -1;
59 auto convolve = [&](
typename std::list<FieldT>::const_iterator q_begin,
typename std::list<FieldT>::const_iterator q_end,
typename std::list<FieldT>::const_iterator p_begin)
62 std::list<FieldT>& result_coeffs = this->getPolynomialCoefficients(result);
63 auto rj_it = (result_coeffs).rbegin();
64 for(;q_begin!=q_end;) {
65 *rj_it += (*q_begin)*(*p_begin);
71 typename std::list<FieldT>::const_iterator p_it_begin = p.begin();
72 for(
size_t j = 0; j < result_size; ++j) {
74 typename std::list<FieldT>::const_iterator q_it_begin = q.begin();
75 typename std::list<FieldT>::const_iterator q_it_end = std::next(q.begin(), std::min(j,deg_q)+1);
76 convolve(q_it_begin,q_it_end, p_it_begin);
80 typename std::list<FieldT>::const_iterator q_it_begin = std::next(q.begin(),j-deg_p);
81 typename std::list<FieldT>::const_iterator q_it_end = q.end();
82 p_it_begin = std::prev(p.end(),1);
83 convolve(q_it_begin,q_it_end, p_it_begin);
91 #endif // _POLYNOMIALMULTIPLICATIONSIMPLE_IPP_
virtual Polynomial< FieldT > multiply(const Polynomial< FieldT > &p1, const Polynomial< FieldT > &p2) override
The method which should be overloaded by the derived class to implement its own multiplication algori...
void appendTerm(FieldT coeff)
Append new terms by pushing back coefficients.
Contains the definition for the abstract base class which will be used by different multiplication al...