Poly divide(Poly const &a, Poly const &b, Poly &r) { Poly c; r = a; // remainder assert(!b.empty()); const unsigned k = a.degree(); const unsigned l = b.degree(); c.resize(k, 0.); for(unsigned i = k; i >= l; i--) { assert(i >= 0); double ci = r.back()/b.back(); c[i-l] += ci; Poly bb = ci*b; //std::cout << ci <<"*(" << b.shifted(i-l) << ") = " // << bb.shifted(i-l) << " r= " << r << std::endl; r -= bb.shifted(i-l); r.pop_back(); } //std::cout << "r= " << r << std::endl; r.normalize(); c.normalize(); return c; }
void reduce(Poly &v) { while (!v.empty() && v.back() % MOD == 0) { v.pop_back(); } }
// Simplify the polynomial, eliminates the high-degree zero term. void tidy(Poly& c) { while(c.size() > 1 && fabs(c.back()) < EPS) c.pop_back(); }
// Simplify the polynomial, eliminates the high-degree zero term. void tidy(Poly& c) { while(!c.empty() && c.back() == 0) c.pop_back(); }