Developer documentation

polynomial_operators.hpp
Go to the documentation of this file.
1 #ifndef realroot_polynom_operators_hpp
2 #define realroot_polynom_operators_hpp
3 //====================================================================
4 #include <realroot/texp_sup.hpp>
7 
8 # define TMPL template <class C, class Rep, class Ord>
9 # define TMPLX template <class C, class Rep, class Ord, class X>
10 # define VARIANT with<Rep,Ord>
11 # define POLYNOMIAL polynomial<C,VARIANT>
12 # define Scalar C
13 //====================================================================
14 namespace mmx {
15 
16 TMPL inline void
17 add (POLYNOMIAL &r, const POLYNOMIAL &a ) {
18  add (r.rep (), a.rep () );
19 }
20 TMPL inline void
21 add (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
22  add (r.rep (), a.rep (), b.rep ());
23 }
24 TMPL inline void
25 add (POLYNOMIAL &r, const POLYNOMIAL &a, const C & b) {
26  add (r.rep (), a.rep (), b);
27 }
28 TMPL inline void
29 add (POLYNOMIAL &r, const C & a, const POLYNOMIAL &b) {
30  add (r.rep(), b.rep(), a);
31 }
32 TMPL inline void
33 sub (POLYNOMIAL &r, const POLYNOMIAL &a ) {
34  sub (r.rep (), a.rep () );
35 }
36 TMPL inline void
37 sub (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
38  sub (r.rep (), a.rep (), b.rep ());
39 }
40 TMPL inline void
41 sub (POLYNOMIAL &r, const C & a, const POLYNOMIAL &b) {
42  sub (r.rep (), a, b.rep ());
43 }
44 TMPL inline void
45 sub (POLYNOMIAL &r, const POLYNOMIAL &a, const C & b) {
46  sub (r.rep (), a.rep (), b);
47 }
48 TMPL inline void
49 mul (POLYNOMIAL &r, const POLYNOMIAL &a ) {
50  mul (r.rep (), a.rep () );
51 }
52 TMPL inline void
53 mul (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
54  mul (r.rep (), a.rep (), b.rep ());
55 }
56 TMPL inline void
57 mul (POLYNOMIAL &r, const POLYNOMIAL &a, const C & b) {
58  mul (r.rep (), a.rep (), b);
59 }
60 TMPL inline void
61 mul (POLYNOMIAL &r, const C & a, const POLYNOMIAL &b) {
62  mul (r.rep (), b.rep (), a);
63 }
64 TMPL inline void
65 div (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
66  div (r.rep (), a.rep (), b.rep ());
67 }
68 TMPL inline void
69 div (POLYNOMIAL &r, const POLYNOMIAL &a, const C & b) {
70  div (r.rep (), a.rep (), b);
71 }
72 TMPL inline void
73 rem (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
74  rem (r.rep (), b.rep (), a.rep);
75 }
76 //====================================================================
77 struct operators_of {};
79  static inline void
80  add (POLYNOMIAL &r, const POLYNOMIAL &a ) {
81  add (r.rep (), a.rep () );
82  }
83  static inline void
84  add (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
85  add (r.rep (), a.rep (), b.rep ());
86  }
87  static inline void
88  add (POLYNOMIAL &r, const POLYNOMIAL &a, const C & b) {
89  add (r.rep (), a.rep (), b);
90  }
91  static inline void
92  add (POLYNOMIAL &r, const C & a, const POLYNOMIAL &b) {
93  add (r.rep(), b.rep(), a);
94  }
95  static inline void
96  sub (POLYNOMIAL &r, const POLYNOMIAL &a ) {
97  sub (r.rep (), a.rep () );
98  }
99  static inline void
100  sub (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
101  sub (r.rep (), a.rep (), b.rep ());
102  }
103  static inline void
104  sub (POLYNOMIAL &r, const C & a, const POLYNOMIAL &b) {
105  sub (r.rep (), a, b.rep ());
106  }
107  static inline void
108  sub (POLYNOMIAL &r, const POLYNOMIAL &a, const C & b) {
109  sub (r.rep (), a.rep (), b);
110  }
111  static inline void
112  mul (POLYNOMIAL &r, const POLYNOMIAL &a ) {
113  mul (r.rep (), a.rep () );
114  }
115  static inline void
116  mul (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
117  mul (r.rep (), a.rep (), b.rep ());
118 }
119  static inline void
120  mul (POLYNOMIAL &r, const POLYNOMIAL &a, const C & b) {
121  mul (r.rep (), a.rep (), b); }
122  static inline void
123  mul (POLYNOMIAL &r, const C & a, const POLYNOMIAL &b) {
124  mul (r.rep (), b.rep (), a);
125  }
126  static inline void
127  div (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
128  div (r.rep (), a.rep (), b.rep ());
129  }
130  static inline void
131  div (POLYNOMIAL &r, const POLYNOMIAL &a, const C & b) {
132  div (r.rep (), a.rep (), b);
133  }
134  static inline void
135  rem (POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b) {
136  rem (r.rep (), b.rep (), a.rep);
137  }
138 };
139 //====================================================================
140 TMPL inline POLYNOMIAL
141 operator-(const POLYNOMIAL& p) {
142  POLYNOMIAL r(p); mul(r.rep(),(typename POLYNOMIAL::value_type)(-1)); return r;
143 }
144 
145 //----------------------------------------------------------------------
146 # define OP use<operators_of,typename POLYNOMIAL::rep_t>
148 TMPLX define_operator_r_r(POLYNOMIAL,X ,POLYNOMIAL,operator+,OP::add)
149 TMPLX define_operator_rr_(POLYNOMIAL,POLYNOMIAL,X ,operator+,OP::add)
150 
151 TMPL define_operator_rrr(POLYNOMIAL,POLYNOMIAL,POLYNOMIAL,operator-,OP::sub)
152 TMPLX define_operator_rr_(POLYNOMIAL,POLYNOMIAL,X ,operator-,OP::sub)
153 TMPLX define_operator_r_r(POLYNOMIAL,X ,POLYNOMIAL,operator-,OP::sub)
154 
155 TMPL define_operator_rrr(POLYNOMIAL,POLYNOMIAL,POLYNOMIAL,operator*,OP::mul)
156 TMPLX define_operator_rr_(POLYNOMIAL,POLYNOMIAL,X ,operator*,OP::mul)
157 TMPLX define_operator_r_r(POLYNOMIAL,X ,POLYNOMIAL,operator*,OP::mul)
158 
159 TMPL define_operator_rrr(POLYNOMIAL,POLYNOMIAL,POLYNOMIAL,operator/,OP::div)
160 TMPLX define_operator_rr_(POLYNOMIAL,POLYNOMIAL,X,operator/,OP::div)
161 
162 TMPL define_operator_rrr(POLYNOMIAL,POLYNOMIAL,POLYNOMIAL,operator%,OP::rem)
163 # undef OP
164 //----------------------------------------------------------------------
165 TMPL POLYNOMIAL
166 operator^(const POLYNOMIAL &a, unsigned n) {
167  return pow (a, n); }
168 
169 
170 TMPL bool
171 operator== (const POLYNOMIAL &mp, const C & c) {
172  return mp.rep() == c;
173 }
174 
175 TMPL bool
176 operator== (const POLYNOMIAL &mp, unsigned n) {
177  return mp.rep() == (C)n;
178 }
179 
180 
181  template<class C, class V, class X>
182 bool operator !=( const polynomial<C,V>& p, const X& q ) {return !(p==q);}
183 
184 //======================================================================
185 } //namespace mmx
186 # undef TMPL
187 # undef TMPLX
188 # undef VARIANT
189 # undef POLYNOMIAL
190 # undef Scalar
191 //====================================================================
192 #endif
bool operator==(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:88
TMPL void rem(POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:73
T pow(const T &a, int i)
Definition: binomials.hpp:12
const C & b
Definition: Interval_glue.hpp:25
TMPL X
Definition: polynomial_operators.hpp:148
#define TMPL
Definition: polynomial_operators.hpp:8
static void mul(POLYNOMIAL &r, const C &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:123
static void sub(POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:100
static void sub(POLYNOMIAL &r, const C &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:104
static void add(POLYNOMIAL &r, const POLYNOMIAL &a, const C &b)
Definition: polynomial_operators.hpp:88
extended< NT > operator-(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:132
static void mul(POLYNOMIAL &r, const POLYNOMIAL &a)
Definition: polynomial_operators.hpp:112
#define define_operator_r_r(parm0, parm1, parm2, opname, function)
Definition: shared_object.hpp:37
static void add(POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:84
void mul(Interval< C, r > &a, const C &x)
Definition: Interval_fcts.hpp:259
#define TMPLX
Definition: polynomial_operators.hpp:9
static void sub(POLYNOMIAL &r, const POLYNOMIAL &a)
Definition: polynomial_operators.hpp:96
static void div(POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:127
static void div(POLYNOMIAL &r, const POLYNOMIAL &a, const C &b)
Definition: polynomial_operators.hpp:131
TMPL void add(POLYNOMIAL &r, const C &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:29
void sub(Interval< C, r > &a, const C &x)
Definition: Interval_fcts.hpp:231
Definition: polynomial.hpp:34
static void sub(POLYNOMIAL &r, const POLYNOMIAL &a, const C &b)
Definition: polynomial_operators.hpp:108
TMPL POLYNOMIAL
Definition: polynomial_operators.hpp:148
Definition: polynomial.hpp:37
#define OP
Definition: polynomial_operators.hpp:146
static void mul(POLYNOMIAL &r, const POLYNOMIAL &a, const C &b)
Definition: polynomial_operators.hpp:120
#define define_operator_rr_(parm0, parm1, parm2, opname, function)
Definition: shared_object.hpp:32
static void rem(POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:135
TMPL define_operator_rrr(DUALPOL, POL, DUALPOL, operator*, sparse::mul) TMPL define_operator_rrr(POL
const C & c
Definition: Interval_glue.hpp:45
Definition: polynomial_operators.hpp:77
double C
Definition: solver_mv_fatarcs.cpp:16
bool operator!=(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:95
static void add(POLYNOMIAL &r, const POLYNOMIAL &a)
Definition: polynomial_operators.hpp:80
static void mul(POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:116
Definition: array.hpp:12
void div(Interval< C, r > &a, const C &x)
Definition: Interval_fcts.hpp:430
void add(dynamic_exp< E > &r, const dynamic_exp< E > &A, const dynamic_exp< E > &B)
Definition: dynamicexp.hpp:295
static void add(POLYNOMIAL &r, const C &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:92
Home