2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1993--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 * polynomial.hh -- routines for manipulation of polynomials in one var
27 #include "std-vector.hh"
28 #include "arithmetic-operator.hh"
31 /// structure for a polynomial in one var.
34 /// degree of polynomial
46 Real
eval (Real
) const;
47 void print_sols (vector
<Real
>) const;
48 void check_sols (vector
<Real
>) const;
49 void check_sol (Real x
) const;
50 static Polynomial
multiply (const Polynomial
&p1
, const Polynomial
&p2
);
51 static Polynomial
power (int exponent
, const Polynomial
&src
);
53 /// chop low coefficients
56 /// eliminate #x# close to zero
58 void scalarmultiply (Real fact
);
59 void operator *= (Real f
) { scalarmultiply (f
); }
60 void operator /= (Real f
) { scalarmultiply (1 / f
); }
61 void operator += (Polynomial
const &p2
);
62 void operator *= (Polynomial
const &p2
);
63 void operator -= (Polynomial
const &p2
);
64 Polynomial (Real a
, Real b
= 0.0);
66 void set_negate (const Polynomial
&src
);
68 /// take the derivative
69 void differentiate ();
70 int set_mod (const Polynomial
&u
, const Polynomial
&v
);
74 vector
<Real
> solve_quadric ()const;
75 vector
<Real
> solve_cubic ()const;
76 vector
<Real
> solve_linear ()const;
78 vector
<Real
> solve () const;
81 IMPLEMENT_ARITHMETIC_OPERATOR (Polynomial
, -);
82 IMPLEMENT_ARITHMETIC_OPERATOR (Polynomial
, +);
83 IMPLEMENT_ARITHMETIC_OPERATOR (Polynomial
, *);
86 operator * (Polynomial p
, Real a
)
92 operator * (Real a
, Polynomial p
)