realroot_doc 0.1.1
|
00001 #ifndef realroot_polynomial_tensor_hpp 00002 #define realroot_polynomial_tensor_hpp 00003 00014 //==================================================================== 00015 #include <realroot/Seq.hpp> 00016 #include <realroot/monomial.hpp> 00017 #include <realroot/tensor_monomials.hpp> 00018 #include <realroot/polynomial.hpp> 00019 #include <realroot/ring.hpp> 00020 00021 #define TMPL template<class C> 00022 #define RING ring<C, MonomialTensor > 00023 #define POLYNOMIAL polynomial<C, with<MonomialTensor> > 00024 //==================================================================== 00025 namespace mmx { 00026 00027 template<class A, class B> struct use; 00028 template<class C, class V> struct polynomial; 00029 template<class C, class V> struct with; 00030 00031 struct MonomialTensor {}; 00032 00033 template<class C> 00034 struct use<polynomial_of,polynomial<C,with<MonomialTensor> > > { 00035 typedef C Scalar; 00036 typedef monom<C> Monomial; 00037 typedef polynomial<C,with<MonomialTensor> > Polynomial; 00038 typedef ring<C, MonomialTensor> Ring; 00039 00040 typedef tensor::monomials<C> rep_t; 00041 typedef Ring variable_t; 00042 00043 00044 }; 00045 00047 template<class C> 00048 struct ring<C, MonomialTensor> { 00049 typedef C Scalar; 00050 typedef monom<C> Monomial; 00051 typedef polynomial<C,with<MonomialTensor> > Polynomial; 00052 typedef ring<C, MonomialTensor> Ring; 00053 00054 typedef tensor::monomials<C> rep_t; 00055 typedef ring<C, MonomialTensor> self_t; 00056 typedef self_t variable_t; 00057 00058 ring(const char* s) {var = variables(s); } 00059 00060 static variables var; 00061 static variables& vars () { return var;} 00062 static int nbvar() { return var.nbvar(); } 00063 00064 Polynomial operator[](int i) const { 00065 return Polynomial((C)1,1,i); 00066 } 00067 }; 00068 00069 template<class C> struct ring_of; 00070 template<class C> struct ring_of<polynomial<C,with<MonomialTensor> > > { 00071 typedef ring<C, MonomialTensor> Ring; 00072 } ; 00073 00074 template<class C> variables ring<C, MonomialTensor >::var; 00075 00076 //==================================================================== 00077 TMPL inline Seq<POLYNOMIAL> 00078 coefficients(const POLYNOMIAL & f, const int & v ) { 00079 int N = degree(f,v)+1; 00080 Seq<POLYNOMIAL> r(N); 00081 typename POLYNOMIAL::Monomial m; 00082 for(int i=0;i<N; i++) { 00083 r[i]=POLYNOMIAL(0); 00084 } 00085 return r; 00086 } 00087 00088 TMPL inline Seq<C> 00089 coefficients(const POLYNOMIAL & f) { 00090 Seq<C> r; 00091 for(int i=0;i<f.size(); i++) { 00092 r<<f[i]; 00093 } 00094 return r; 00095 } 00096 00097 namespace let { 00098 template<class C, class D> inline void 00099 assign(polynomial<D, with<MonomialTensor> >& p, 00100 const polynomial<C, with<MonomialTensor> >& q){ 00101 //int d = q.size(); 00102 p = polynomial< D, with<MonomialTensor> >(0); 00103 00104 const int * vr=q.rep().vrs(); 00105 const int * sz=q.rep().szs(); 00106 for (int i=0; i< q.nbvar();i++) 00107 p += polynomial< D, with<MonomialTensor> >(D(1),sz[i]-1,vr[i]); 00108 for(unsigned i=0;i<q.size();i++) p[i]= as<D>(q[i]); 00109 } 00110 } 00111 } //namespace mmx 00112 //==================================================================== 00113 # undef TMPL 00114 # undef RING 00115 # undef POLYNOMIAL 00116 //==================================================================== 00117 # endif // realroot_polynom_mdse_hpp