Developer documentation

polynomial.hpp
Go to the documentation of this file.
1 #ifndef realroot_polynomial_hpp
2 #define realroot_polynomial_hpp
3 
20 //======================================================================
22 #include <realroot/texp_sup.hpp>
23 #include <realroot/variables.hpp>
24 #include <realroot/monomial.hpp>
25 #include <realroot/ring.hpp>
26 
27 #define TMPL template <class C, class Rep, class Ord>
28 #define VARIANT with<Rep,Ord>
29 #define SELF polynomial<C, VARIANT>
30 
31 //======================================================================
32 namespace mmx {
33 
34 template<class A, class B> struct use;
35 struct operators_of;
36 
37  template<class C, class V> struct polynomial;
38 #ifndef DECL_WITH
39 #define DECL_WITH
40  template<class V, class W=V> struct with;
41 #endif //DECL_WITH
42 
43 struct polynomial_of {};
47 TMPL
49 {
52  typedef typename Def::Ring Ring;
53  typedef Ring V;
54  typedef typename Def::rep_t R;
55  typedef typename Def::rep_t rep_t;
57  typedef C scalar_t;
58  typedef C Scalar;
59  typedef C value_type;
60  typedef C coeff_t;
61  typedef typename R::size_type size_type;
62  typedef R rep_type;
63  typedef Ord order_t;
64  typedef typename R::iterator iterator;
65  typedef typename R::const_iterator const_iterator;
66  typedef typename R::reverse_iterator reverse_iterator;
67  typedef typename R::const_reverse_iterator const_reverse_iterator;
68 
69  typedef typename Def::Monomial Monomial;
70 
71 
73  R & rep() { return (*data);}
74  const R & rep() const { return (*data);}
75 
76 //----------------------------------------------------------------------
77  polynomial(): data() {};
78 
79  polynomial( int c) : data() { rep()= R((Scalar)c); }
80  polynomial( const C& c): data() { rep() = R(c); }
81  polynomial( const C& c, int d, unsigned v=0) : data() { rep()=R(c,d,v); }
82  polynomial( const Monomial & m): data() { rep()=R(m);}
83  polynomial( const self_t & P): data(P.data) {}
85 
86  template<class S, class VECT>
87  polynomial( const char * s, const VECT& bx);
88 
89  template<class S, class W, class VECT>
90  polynomial( const polynomial<S,W>& pol, const VECT& bx);
91 
92  polynomial( const char * s, variables& vars = Ring::vars());
93  polynomial( const char * s, const variables& vars) {
94  variables v(vars);
95  *this= self_t(s,v);
96  }
97 //----------------------------------------------------------------------
98 
99  bool operator==( const C& c ) const;
100  bool operator!=( const C& c ) const;
101  bool operator==( const self_t& mp ) const;
102 
103  // polynomial & operator= ( const char* );
104  self_t & operator = ( const C& );
105  self_t & operator = ( const self_t & x ) { data=x.data; return *this;}
106 
107  template<class S>
108  polynomial& operator = ( const polynomial<S,VARIANT>& pol );
109 
110  template<class X>
111  polynomial& operator+= ( const X & x ) { *this = *this + x; return *this; };
112  polynomial& operator+= ( const self_t& p ) { Op::add(rep(),p.rep()); return *this;}
113  polynomial& operator+= ( const C& c ) { Op::add(rep(),c); return *this; }
114 
115  template<class X>
116  polynomial& operator-= ( const X & x ) { *this = *this - x; return *this; };
117  polynomial& operator-= ( const self_t& p ) { Op::sub(rep(),p.rep()); return *this;}
118  polynomial& operator-= ( const C& c ) { Op::sub(rep(),c); return *this; }
119 
120  template<class X>
121  polynomial& operator*= ( const X & x ) { *this = *this * x; return *this; };
122  polynomial& operator*= ( const C& c) { Op::mul(rep(),c); return *this; }
123  polynomial& operator*= ( const Monomial& m) { Op::mul(rep(),m); return *this; }
124  polynomial& operator*= ( const self_t& p) { Op::mul(rep(),p.rep()); return *this; }
125 
126 
127  polynomial& operator/= ( const C& c) { Op::div(rep(),c); return *this; }
128  polynomial& operator/= ( const self_t& p) { Op::div(rep(),p.rep()); return *this; }
129 
130  // Iterator functions
131  iterator begin() {return rep().begin();}
132  const_iterator begin() const {return rep().begin();}
133  iterator end() {return rep().end();}
134  const_iterator end() const {return rep().end();}
135 
136  reverse_iterator rbegin() {return rep().rbegin();}
137  const_reverse_iterator rbegin() const {return rep().rbegin();}
138  reverse_iterator rend() {return rep().rend();}
139  const_reverse_iterator rend() const {return rep().rend();}
140 
142  unsigned size() const {return rep().size();}
143 
145  int nbvar() const {return rep().nbvar();}
146 
148  const C coefof(int * deg) {return rep().entry(deg);}
149 
150  const C operator[]( int i ) const;
151  C& operator[]( int i ) ;
152  // std::string varname( int i ) const ;
153  // void lexsort();
154 
155  C operator()(const C& x) const {
156  assert(rep().nbvar()<=1);
157  C r; eval(r,rep(),x); return r;
158  }
159 
160  template<class T>
161  T operator()(const T& x) const {
162  // assert(rep().nbvar()==1);
163  T r; eval(r,rep(),x); return r;
164  }
165 
166  template<class T>
167  T operator()(const T& x, const T& y) const {
168  T p[2]={x,y};
169  T r; eval(r,rep(),p,2); return r;
170  // delete p;
171  }
172 
173  template<class T>
174  T operator()(const T& x, const T& y, const T& z) const {
175  T p[3]={x,y,z};
176  T r; eval(r,rep(),p,3); return r;
177  // delete p;
178  }
179 
180  template<class T>
181  T operator()(const T& x, unsigned n) const {
182  T r; eval(r,rep(), x, n); return r;
183  }
184 
186  template<class T>
187  typename T::value_type at(const T& x) const {
188  typename T::value_type r; eval_at(r,rep(), x); return r;
189  }
190 };
191 } // namespace mmx
192 //====================================================================
193 # undef TMPL
194 # undef SELF
195 # undef VARIANT
196 //======================================================================
200 //====================================================================
201 #endif //realroot_polynomial_hpp
extended< NT > & operator+=(extended< NT > &x, const extended< NT > &other)
Definition: extended.hpp:158
T operator()(const T &x, const T &y, const T &z) const
Definition: polynomial.hpp:174
bool operator==(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:88
polynomial(const self_t &P)
Definition: polynomial.hpp:83
use< polynomial_of, self_t > Def
Definition: polynomial.hpp:51
shared_object< R > data
Definition: polynomial.hpp:72
C operator()(const C &x) const
Definition: polynomial.hpp:155
#define TMPL
Definition: polynomial.hpp:27
Def::rep_t rep_t
Definition: polynomial.hpp:55
TMPL X
Definition: polynomial_operators.hpp:148
#define VARIANT
Definition: polynomial.hpp:28
C Scalar
Definition: polynomial.hpp:58
Result eval(const Polynomial &polynomial, const Parameters &parameters)
Multivariate Polynomial Evaluation.
Definition: polynomial_fcts.hpp:135
void eval_at(R &r, const Polynomial &p, const VCT &x)
Definition: sparse_monomials.hpp:642
R rep_type
Definition: polynomial.hpp:62
C value_type
Definition: polynomial.hpp:59
R & rep(R &r)
Definition: shared_object.hpp:180
Definition: polynomial.hpp:48
use< operators_of, R > Op
Definition: polynomial.hpp:56
#define Monomial
Definition: monomial.hpp:56
Def::Ring Ring
Definition: polynomial.hpp:52
extended< NT > & operator/=(extended< NT > &x, const extended< NT > &other)
Definition: extended.hpp:179
void mul(Interval< C, r > &a, const C &x)
Definition: Interval_fcts.hpp:259
Definition: polynomial.hpp:43
polynomial()
Definition: polynomial.hpp:77
T::value_type at(const T &x) const
Evaluate the polynomial at the "point" p.
Definition: polynomial.hpp:187
Definition: shared_object.hpp:64
polynomial(const char *s, const variables &vars)
Definition: polynomial.hpp:93
polynomial(int c)
Definition: polynomial.hpp:79
const_reverse_iterator rbegin() const
Definition: polynomial.hpp:137
R::reverse_iterator reverse_iterator
Definition: polynomial.hpp:66
const R & rep() const
Definition: polynomial.hpp:74
R::iterator iterator
Definition: polynomial.hpp:64
Ring V
Definition: polynomial.hpp:53
unsigned size() const
Return the number of terms in the polynomial.
Definition: polynomial.hpp:142
extended< NT > & operator*=(extended< NT > &x, const extended< NT > &other)
Definition: extended.hpp:172
polynomial(const C &c)
Definition: polynomial.hpp:80
R::const_iterator const_iterator
Definition: polynomial.hpp:65
Definition: polynomial.hpp:34
Definition: polynomial.hpp:37
polynomial< C, VARIANT > self_t
Definition: polynomial.hpp:50
int nbvar() const
Return the number of variables involved in the polynomial.
Definition: polynomial.hpp:145
void sub(V &a, const W &b)
Substraction of two vectors.
Definition: array.hpp:221
Ord order_t
Definition: polynomial.hpp:63
void add(V &a, const W &b)
Addition of two vectors.
Definition: array.hpp:154
R & rep()
Definition: polynomial.hpp:73
reverse_iterator rbegin()
Definition: polynomial.hpp:136
iterator end()
Definition: polynomial.hpp:133
iterator begin()
Definition: polynomial.hpp:131
reverse_iterator rend()
Definition: polynomial.hpp:138
C scalar_t
Definition: polynomial.hpp:57
R::size_type size_type
Definition: polynomial.hpp:61
const_iterator begin() const
Definition: polynomial.hpp:132
C coeff_t
Definition: polynomial.hpp:60
const C & c
Definition: Interval_glue.hpp:45
Definition: polynomial_operators.hpp:77
double C
Definition: solver_mv_fatarcs.cpp:16
T operator()(const T &x, unsigned n) const
Definition: polynomial.hpp:181
polynomial(const Monomial &m)
Definition: polynomial.hpp:82
bool operator!=(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:95
TMPL int nbvar(const Polynomial &mp)
Definition: polynomial_fcts.hpp:43
T operator()(const T &x, const T &y) const
Definition: polynomial.hpp:167
R::const_reverse_iterator const_reverse_iterator
Definition: polynomial.hpp:67
void div(V &a, const W &c)
Inplace scalar division.
Definition: array.hpp:334
polynomial(const C &c, int d, unsigned v=0)
Definition: polynomial.hpp:81
const_iterator end() const
Definition: polynomial.hpp:134
~polynomial()
Definition: polynomial.hpp:84
Definition: array.hpp:12
Definition: variables.hpp:65
extended< NT > & operator-=(extended< NT > &x, const extended< NT > &other)
Definition: extended.hpp:165
Def::rep_t R
Definition: polynomial.hpp:54
Definition: polynomial.hpp:40
T operator()(const T &x) const
Definition: polynomial.hpp:161
const C coefof(int *deg)
Return coeff of x^deg.
Definition: polynomial.hpp:148
Def::Monomial Monomial
Definition: polynomial.hpp:69
const_reverse_iterator rend() const
Definition: polynomial.hpp:139
#define assert(expr, msg)
Definition: shared_object.hpp:57
Home