00001 #ifndef realroot_tensor_bernstein_hpp
00002 #define realroot_tensor_bernstein_hpp
00003
00004 #include "realroot/tensor_monomials.hpp"
00005
00006 #define TMPL template<class C>
00007 #define Polynomial bernstein<C>
00008 namespace mmx {
00009
00010 namespace tensor
00011 {
00012 template<class C>
00013 struct bernstein : monomials<C>
00014 {
00015 typedef monomials<C> base_type;
00016 typedef typename base_type::value_type value_type;
00017 typedef typename base_type::vector_type vector_type;
00018 typedef typename base_type::iterator iterator;
00019 typedef typename base_type::const_iterator const_iterator;
00020 typedef typename base_type::size_type size_type;
00021
00022 bernstein( const C& x = 0 );
00023 bernstein( int v, int d): base_type(v,d) {
00024 convertm2b(*this);
00025 }
00026 bernstein( const C& c, int v, int d): base_type(c,v,d) {
00027 convertm2b(*this);
00028 }
00029 bernstein( const bernstein<C>& p) : base_type(p) {
00030
00031 }
00032
00033 template<class X, class O>
00034 bernstein( const sparse::monomial_seq<X,O>& pol ):base_type(pol) {
00035 convertm2b(*this);
00036 }
00037
00038 bernstein( const char* str ):base_type(str) {
00039 convertm2b(*this);
00040 }
00041
00042 template<class VECT>
00043 bernstein( const char* str, const VECT& bx):base_type(str) {
00044 convertm2b(*this, bx);
00045 }
00046
00047 template<class O, class VECT>
00048 bernstein( const sparse::monomial_seq<C,O>& pol, const VECT& bx):base_type(pol) {
00049 convertm2b(*this, bx);
00050 }
00051
00052
00053 template<class X, class O, class VECT>
00054 bernstein(const sparse::monomial_seq<X,O>& mpol, const VECT& bx ):base_type(mpol) {
00055 convertm2b(*this, bx);
00056 }
00057
00058 bernstein( const eenv & e);
00059 bernstein( const eenv& e, const C& c );
00060 bernstein( int nvr, const int * szs, const int * vrs = 0 );
00061
00062 bernstein& operator=( const C& x );
00063 C& operator[]( int i ) { return this->data[i]; };
00064 C operator[]( int i ) const { return this->data[i]; };
00065 bool operator==( const C& c ) const { return base_type::esz() == 1 && base_type::data[0] == c; };
00066 bool operator==( const bernstein& mp ) const;
00067 };
00068
00069 template<class C> inline
00070 unsigned size(const bernstein<C>& p) {return p.size();}
00071
00072 template<class C> inline int
00073 degree(const bernstein<C>& p) {return degree((const monomials<C>&)p);}
00074
00075 template<class C> inline int
00076 degree(const bernstein<C>& p, int v) {return degree((const monomials<C>&)p,v);}
00077
00078
00079 TMPL Polynomial diff(const Polynomial& p, int v)
00080 {
00081 Polynomial dp(p); diff(dp,p,v); return dp;
00082 }
00083
00084 template<class C,class U> void coefficients(Seq<U>& r, const Polynomial& p, int v){
00085
00086 }
00087
00088 };
00089
00090 }
00091
00092 #include "tensor_bernstein_fcts.hpp"
00093
00094
00095 namespace mmx {
00096 # undef Polynomial
00097 # define Polynomial tensor::bernstein<C>
00098 # define TMPL template<class C>
00099
00100 template<class A, class B> struct use;
00101 struct operators_of;
00102
00103 TMPL struct use<operators_of,Polynomial> {
00104
00105 static inline void
00106 add (Polynomial &r, const Polynomial &a ) {
00107 tensor::add (r, a);
00108 }
00109 static inline void
00110 add (Polynomial &r, const Polynomial &a, const Polynomial &b) {
00111 tensor::add (r, a, b);
00112 }
00113 static inline void
00114 add (Polynomial &r, const Polynomial &a, const C & b) {
00115 tensor::add (r, a, b);
00116 }
00117 static inline void
00118 add (Polynomial &r, const C & a, const Polynomial &b) {
00119 tensor::add (r, b, a);
00120 }
00121 static inline void
00122 sub (Polynomial &r, const Polynomial &a ) {
00123 tensor::sub (r, a );
00124 }
00125 static inline void
00126 sub (Polynomial &r, const Polynomial &a, const Polynomial &b) {
00127 tensor::sub (r, a, b);
00128 }
00129 static inline void
00130 sub (Polynomial &r, const C & a, const Polynomial &b) {
00131 tensor::sub (r, a, b);
00132 }
00133 static inline void
00134 sub (Polynomial &r, const Polynomial &a, const C & b) {
00135 tensor::sub (r, a, b);
00136 }
00137 static inline void
00138 mul (Polynomial &r, const Polynomial &a ) {
00139 tensor::mul (r, a );
00140 }
00141 static inline void
00142 mul (Polynomial &r, const Polynomial &a, const Polynomial &b) {
00143 tensor::mul (r, a, b);
00144 }
00145 static inline void
00146 mul (Polynomial &r, const Polynomial &a, const C & b) {
00147 tensor::mul (r, a, b); }
00148 static inline void
00149 mul (Polynomial &r, const C & a, const Polynomial &b) {
00150 tensor::mul (r, b, a);
00151 }
00152 static inline void
00153 div (Polynomial &r, const Polynomial &a, const Polynomial &b) {
00154 tensor::div (r, a, b);
00155 }
00156 static inline void
00157 div (Polynomial &r, const Polynomial &a, const C & b) {
00158 tensor::div (r, a, b);
00159 }
00160
00161
00162
00163
00164 };
00165 # undef Polynomial
00166 # undef TMPL
00167
00168 }
00169 #undef TMPL
00170 #undef Polynomial
00171 #endif