realroot_doc 0.1.1
|
00001 #ifndef realroot_polynomial_univariate_hpp 00002 #define realroot_polynomial_univariate_hpp 00003 00014 #include <realroot/Seq.hpp> 00015 #include <realroot/univariate.hpp> 00016 #include <realroot/monomial.hpp> 00017 #include <realroot/polynomial.hpp> 00018 #include <realroot/ring.hpp> 00019 00020 #define TMPL template<class C> 00021 #define RING ring<C, Univariate > 00022 #define POLYNOMIAL polynomial< C, with<Univariate> > 00023 namespace mmx { 00024 00025 struct Univariate {}; 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 00032 template<class C> 00033 struct use<polynomial_of, polynomial< C, with<Univariate> > > { 00034 typedef ring<C, Univariate > Ring; 00035 typedef C scalar_t; 00036 typedef polynomial< C, with<Univariate> > Polynomial; 00037 typedef monom<C> Monomial; 00038 typedef Ring variable_t; 00039 typedef univariate::monomials<C> rep_t; 00040 }; 00041 00043 template<class C> 00044 struct ring<C, Univariate > { 00045 typedef ring<C, Univariate > self_t; 00046 typedef univariate::monomials<C> rep_t; 00047 typedef C scalar_t; 00048 typedef polynomial< C, with<Univariate> > Polynomial; 00049 typedef monom<C> Monomial; 00050 typedef self_t variable_t; 00051 00052 ring(const char* s) {var = variables(s); } 00053 00054 static variables var; 00055 static variables& vars () { return var;} 00056 static int nbvar() { return var.nbvar(); } 00057 00058 Polynomial operator[](int i) const { 00059 return Polynomial((C)1,1,i); 00060 } 00061 }; 00062 template<class C> variables ring<C, Univariate >::var; 00063 00064 //==================================================================== 00065 TMPL inline Seq<POLYNOMIAL> 00066 coefficients(const POLYNOMIAL & f, const int & v ) { 00067 int N = degree(f,v)+1; 00068 Seq<POLYNOMIAL> r(N); 00069 typename POLYNOMIAL::Monomial m; 00070 for(int i=0;i<N; i++) { 00071 r[i]=0; 00072 } 00073 return r; 00074 } 00075 00076 TMPL inline Seq<C> 00077 coefficients(const POLYNOMIAL & f) { 00078 Seq<C> r; 00079 for(int i=0;i<f.size(); i++) { 00080 r<<f[i]; 00081 } 00082 return r; 00083 } 00084 00085 00086 namespace let { 00087 template<class C, class D> inline void 00088 assign(polynomial<D, with<Univariate> >& p, 00089 const polynomial<C, with<Univariate> >& q){ 00090 int d = degree(q); 00091 p = polynomial< D, with<Univariate> >(D(1),d); 00092 for(int i=0;i<=d;i++) p[i]= D(q[i]); 00093 } 00094 } 00095 //==================================================================== 00096 } //namespace mmx 00097 # undef TMPL 00098 # undef RING 00099 # undef POLYNOMIAL 00100 # endif // realroot_polynom_mdse_hpp