3 * poly.h -- routines for manipulation of polynomials in one var
5 * (c) 1993--2009 Han-Wen Nienhuys
11 #include "std-vector.hh"
12 #include "arithmetic-operator.hh"
15 /// structure for a polynomial in one var.
18 /// degree of polynomial
30 Real
eval (Real
) const;
31 void print_sols (vector
<Real
>) const;
32 void check_sols (vector
<Real
>) const;
33 void check_sol (Real x
) const;
34 static Polynomial
multiply (const Polynomial
&p1
, const Polynomial
&p2
);
35 static Polynomial
power (int exponent
, const Polynomial
&src
);
37 /// chop low coefficients
40 /// eliminate #x# close to zero
42 void scalarmultiply (Real fact
);
43 void operator *= (Real f
) { scalarmultiply (f
); }
44 void operator /= (Real f
) { scalarmultiply (1 / f
); }
45 void operator += (Polynomial
const &p2
);
46 void operator *= (Polynomial
const &p2
);
47 void operator -= (Polynomial
const &p2
);
48 Polynomial (Real a
, Real b
= 0.0);
50 void set_negate (const Polynomial
&src
);
52 /// take the derivative
53 void differentiate ();
54 int set_mod (const Polynomial
&u
, const Polynomial
&v
);
58 vector
<Real
> solve_quadric ()const;
59 vector
<Real
> solve_cubic ()const;
60 vector
<Real
> solve_linear ()const;
62 vector
<Real
> solve () const;
65 IMPLEMENT_ARITHMETIC_OPERATOR (Polynomial
, -);
66 IMPLEMENT_ARITHMETIC_OPERATOR (Polynomial
, +);
67 IMPLEMENT_ARITHMETIC_OPERATOR (Polynomial
, *);
70 operator * (Polynomial p
, Real a
)
76 operator * (Real a
, Polynomial p
)