lilypond-1.3.18
[lilypond.git] / flower / include / polynomial.hh
blobdf79274bdc96d45e9408953b4655327cde2d77f3
2 /*
3 * poly.h -- routines for manipulation of polynomials in one var
5 * (c) 1993, 1996,1999 Han-Wen Nienhuys
6 */
8 #ifndef POLY_H
9 #define POLY_H
11 #include "array.hh"
12 #include "arithmetic-operator.hh"
13 #include "real.hh"
15 /// structure for a polynomial in one var.
16 struct Polynomial
18 /// degree of polynomial
19 int degree ()const;
21 /// coefficients
22 Array<Real> coefs_;
24 // leading coef
25 Real &lc();
27 // leading coef
28 Real lc() const;
29 void print() const ;
30 Real eval(Real) const ;
31 void print_sols(Array<Real>) const ;
32 void check_sols(Array<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
38 void clean();
40 /// eliminate #x# close to zero
41 void real_clean();
42 static Polynomial add(const Polynomial & p1, const Polynomial & p2);
43 void scalarmultiply(Real fact);
44 void operator *= (Real f) { scalarmultiply(f); }
45 void operator /= (Real f) { scalarmultiply(1/f); }
46 void operator += (Polynomial const &p2);
47 void operator *= (Polynomial const &p2);
48 void operator -= (Polynomial const &p2);
49 Polynomial (Real a, Real b =0.0);
50 Polynomial (){}
51 static Polynomial subtract(const Polynomial & p1, const Polynomial & p2);
52 void set_negate(const Polynomial & src);
54 /// take the derivative
55 void differentiate();
56 int set_mod(const Polynomial &u, const Polynomial &v);
58 void debug_clean();
60 Array<Real> solve_quadric()const;
61 Array<Real> solve_cubic()const;
62 Array<Real> solve_linear()const;
64 Array<Real> solve () const;
68 IMPLEMENT_ARITHMETIC_OPERATOR(Polynomial, - );
69 IMPLEMENT_ARITHMETIC_OPERATOR(Polynomial, + );
70 IMPLEMENT_ARITHMETIC_OPERATOR(Polynomial, * );
72 inline Polynomial
73 operator * (Polynomial p, Real a)
75 p *=a;
76 return p;
78 inline Polynomial
79 operator * (Real a,Polynomial p)
81 p *=a;
82 return p;
84 #endif