45 namespace polynomials {
75 typename std::vector<C>::iterator bottom=
d_data.begin()+d;
76 std::fill(
d_data.begin(),bottom,C(0));
107 while (j-->0 and
d_data[j]==C(0))
121 const C* src=&*q.
d_data.end();
124 while (src>&q.
d_data[0]) *--dst += *--src;
137 const C* src=&*q.
d_data.end();
140 while (src>&q.
d_data[0]) *--dst -= *--src;
153 { --dst; *dst= -*dst; }
156 const C* src=&*p.
d_data.end();
157 while (dst-->&
d_data[0]) { *dst= *--src - *dst; }
176 throw std::runtime_error(
"Polynomial division by 0");
181 throw std::runtime_error(
"Inexact polynomial integer division");
194 result.
d_data[result.degree()]=C(0);
196 for (
size_t j=
size(); j-->0; )
199 const C* src=&*q.
d_data.end();
200 C* dst=&result.d_data[q.
size()+j];
201 while (src>&q.
d_data[0]) *--dst += c * *--src;
213 for (
Degree i=1; i<=d; ++i)
227 for (
Degree i=1; i<=d; ++i)
228 remainder = (
d_data[i] -= c*remainder);
240 if ((*
this)[i]!=C(0))
258 for (
size_t j = p.
size(); j-->0; )
284 if (c<C(0) and c == C(-1))
299 std::ostringstream o;
303 for (
size_t i = p.
size(); i-->0; )
307 return strm << o.str();
327 if (b > std::numeric_limits<C>::max() - a)
359 if (b > std::numeric_limits<C>::max()/a)
396 size_t qs = q.
size();
400 base::resize(q.
size()+d);
402 for (
size_t j = qs; j-->0;)
418 size_t qs = q.
size();
422 base::resize(q.
size()+d);
424 for (
size_t j = qs; j-->0; )
457 for (
size_t j = 1; j <= base::degree(); ++j)
459 if ((*
this)[base::degree()]==0)
462 assert(2*base::degree()+1<delta);
465 assert(2*base::degree()+1==delta);
482 size_t qs = q.
size();
487 for (
size_t j = qs; j-->0; )
513 for (
size_t j = qs; j-->0;)
Denom_t remainder(I, Denom_t)
Definition: arithmetic.h:184
Polynomials with coefficients in |C|.
Definition: Atlas.h:121
void adjustSize()
Adjusts the size of d_data so that it corresponds to the degree + 1.
Definition: polynomials_def.h:104
Polynomial & operator+=(const Polynomial &q)
Definition: polynomials_def.h:112
unsigned long size
Definition: testprint.cpp:46
Polynomial()
Definition: polynomials.h:71
void safeDivide(C c)
Divides polynomial by scalar c, throwing an error is division is inexact.
Definition: polynomials_def.h:433
uA p
Definition: lists.cpp:26
C up_remainder(C c, Degree d) const
Definition: polynomials_def.h:207
Degree degree() const
Definition: polynomials.h:103
Polynomial & subtract_from(const Polynomial &p)
Definition: polynomials_def.h:146
void safeProd(C &, C)
a *= b.
Definition: polynomials_def.h:352
void safeSubtract(const Safe_Poly &p, Degree d, C c)
Subtracts x^d.c.q from *this, watching for underflow, assuming |c>0|.
Definition: polynomials_def.h:477
void safeAdd(C &, C)
a += b.
Definition: polynomials_def.h:323
void resize(Degree d)
Definition: polynomials.h:146
Polynomial & operator/=(C)
Definition: polynomials_def.h:173
std::vector< C > d_data
Definition: polynomials.h:66
Polynomial & operator-=(const Polynomial &q)
Definition: polynomials_def.h:130
void safeDivide(C &, C)
a /= b.
Definition: polynomials_def.h:338
void safeAdd(const Safe_Poly &p, Degree d, C c)
Adds x^d.c.q, to *this, watching for overflow, assuming |c>0|.
Definition: polynomials_def.h:391
const C coef(Degree i) const
Definition: polynomials.h:85
bool compare(const Polynomial< C > &, const Polynomial< C > &)
Polynomial comparison: whether p < q.
Definition: polynomials_def.h:252
std::ostream & print(std::ostream &strm, const char *x) const
Definition: polynomials_def.h:296
const C & operator[](Degree i) const
Definition: polynomials_def.h:83
void safeQuotient(Degree d=0)
Definition: polynomials_def.h:453
size_t Degree
Definition: Atlas.h:122
Polynomial & operator*=(C)
Definition: polynomials_def.h:163
Degree size() const
Definition: polynomials.h:104
void printMonomial(std::ostream &strm, C c, polynomials::Degree d, const char *x)
Definition: polynomials_def.h:278
void safeSubtract(C &, C)
a -= b.
Definition: polynomials_def.h:371
Polynomial operator*(C c) const
Definition: polynomials.h:123
bool multi_term() const
Definition: polynomials_def.h:235
bool isZero() const
Definition: polynomials.h:106
C factor_by(C c, Degree d)
Definition: polynomials_def.h:219