algebramix_doc 0.3
/Users/mourrain/Devel/mmx/algebramix/include/algebramix/quotient_series.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : quotient_series.hpp
00004 * DESCRIPTION: Laurent series (both univariate and multivariate)
00005 * COPYRIGHT  : (C) 2007  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00011 ******************************************************************************/
00012 
00013 #ifndef __MMX__QUOTIENT_SERIES__HPP
00014 #define __MMX__QUOTIENT_SERIES__HPP
00015 #include <algebramix/series.hpp>
00016 
00017 namespace mmx {
00018 #define TMPL_DEF template<typename Series, typename Monomial>
00019 #define TMPL template<typename Series, typename Monomial>
00020 #define C typename scalar_type_helper<Series>::val
00021 #define Stair list<Monomial >
00022 #define Variable typename Series::variable_type
00023 #define Quotient_series quotient_series<Series,Monomial>
00024 #define Quotient_series_rep quotient_series_rep<Series,Monomial>
00025 #define Set table<bool,Variable >
00026 TMPL class quotient_series_rep;
00027 TMPL class quotient_series;
00028 
00029 /******************************************************************************
00030 * Quotient_series
00031 ******************************************************************************/
00032 
00033 TMPL_DEF
00034 class quotient_series_rep REP_STRUCT {
00035 public:
00036   Series   f;
00037   Monomial m;
00038   inline quotient_series_rep ():
00039     f (0), m (1) {}
00040   inline quotient_series_rep (const Series& f2):
00041     f (f2), m (1) {}
00042   inline quotient_series_rep (const Series& f2, const Monomial& m2):
00043     f (f2), m (m2) {}
00044   inline quotient_series_rep (const Monomial& m2):
00045     f (1), m (m2) {}
00046   inline ~quotient_series_rep () {}
00047 };
00048 
00049 TMPL_DEF
00050 class quotient_series {
00051 INDIRECT_PROTO_2 (quotient_series, quotient_series_rep, Series, Monomial)
00052 public:
00053   inline quotient_series ():
00054     rep (new Quotient_series_rep ()) {}
00055   template<typename T> inline quotient_series (const T& c):
00056     rep (new Quotient_series_rep (Series (c))) {}
00057   inline quotient_series (const Monomial& m):
00058     rep (new Quotient_series_rep (m)) {}
00059   inline quotient_series (const Series& f, const Monomial& m):
00060     rep (new Quotient_series_rep (f, m)) {}
00061   inline C operator [] (const Monomial& m) const {
00062     return rep->f [m / rep->m]; }
00063 
00064   static inline generic get_variable_name () {
00065     return Series::get_variable_name (); }
00066   static inline void set_variable_name (const generic& x) {
00067     Series::set_variable_name (x); }
00068 
00069   static inline nat get_output_order () {
00070     return Series::get_output_order (); }
00071   static inline void set_output_order (const nat& x) {
00072     Series::set_output_order (x); }
00073 
00074   static inline nat get_cancel_order () {
00075     return Series::get_cancel_order (); }
00076   static inline void set_cancel_order (const nat& x) {
00077     Series::set_cancel_order (x); }
00078 
00079   static inline bool get_formula_output () {
00080     return Series::get_formula_output (); }
00081   static inline void set_formula_output (const bool& x) {
00082     Series::set_formula_output (x); }
00083 };
00084 INDIRECT_IMPL_2 (quotient_series, quotient_series_rep,
00085                  typename Series, Series, typename Monomial, Monomial)
00086 
00087 STYPE_TO_TYPE(TMPL,scalar_type,Quotient_series);
00088 
00089 TMPL inline nat hash (const Quotient_series& f) {
00090   // FIXME: find something better to return here
00091   (void) f; return 0; }
00092 TMPL inline bool
00093 operator == (const Quotient_series& f, const Quotient_series& g) {
00094   Monomial m= gcd (f->m, g->m);
00095   return f->f * (g->m / m) == g->f * (f->m / m); }
00096 TMPL inline bool
00097 operator != (const Quotient_series& f, const Quotient_series& g) {
00098   return !(f == g); }
00099 TMPL inline nat exact_hash (const Quotient_series& f) {
00100   return exact_hash (f->f) ^ exact_hash (f->m); }
00101 TMPL inline bool
00102 exact_eq (const Quotient_series& f, const Quotient_series& g) {
00103   return exact_eq (f->f, g->f) && exact_eq (f->m, g->m); }
00104 TMPL inline bool
00105 exact_neq (const Quotient_series& f, const Quotient_series& g) {
00106   return !exact_eq (f, g); }
00107 
00108 TMPL inline syntactic flatten (const Quotient_series& f) {
00109   return flatten (f->f) * flatten (f->m); }
00110 
00111 /******************************************************************************
00112 * Support related routines
00113 ******************************************************************************/
00114 
00115 TMPL inline Set variables (const Quotient_series& f) {
00116   return variables (f->f) | variables (f->m); }
00117 TMPL inline int val (const Quotient_series& f, const Variable& v) {
00118   return val (f->f, v) * f->m[v]; }
00119 TMPL inline Monomial monomial_val (const Quotient_series f) {
00120   return monomial_val (f->f) * f->m; }
00121 
00122 TMPL Quotient_series project (const Quotient_series& f, const Stair& l) {
00123   return Quotient_series (project (f->f, stair_mul (1/f->m, l)), f->m); }
00124 TMPL Quotient_series head (const Quotient_series& f, const Stair& l) {
00125   return Quotient_series (head (f->f, stair_mul (1/f->m, l)), f->m); }
00126 TMPL Quotient_series tail (const Quotient_series& f, const Stair& l) {
00127   return Quotient_series (tail (f->f, stair_mul (1/f->m, l)), f->m); }
00128 TMPL Stair dominant_monomials (const Quotient_series& f) {
00129   return stair_mul (f->m, dominant_monomials (f->f)); }
00130 TMPL inline Quotient_series
00131 normalize (const Quotient_series& f, const Monomial& dom_m) {
00132   return Quotient_series (lshiftz (f->f, f->m / dom_m), dom_m); }
00133 
00134 /******************************************************************************
00135 * Basic arithmetic
00136 ******************************************************************************/
00137 
00138 TMPL Quotient_series
00139 operator + (const Quotient_series& f, const Quotient_series& g) {
00140   if (f->m == g->m) return Quotient_series (f->f + g->f, f->m);
00141   else {
00142     Monomial m= gcd (f->m, g->m);
00143     return Quotient_series (f->f * (f->m / m) + g->f * (g->m / m), m);
00144   }
00145 }
00146 
00147 TMPL Quotient_series
00148 operator + (const Quotient_series& f, const C& c) {
00149   return Quotient_series (f->f + Quotient_series (c));
00150 }
00151 
00152 TMPL Quotient_series
00153 operator + (const C& c, const Quotient_series& f) {
00154   return Quotient_series (Quotient_series (c) + f->f);
00155 }
00156 
00157 TMPL Quotient_series
00158 operator - (const Quotient_series& f) {
00159   return Quotient_series (-f->f, f->m);
00160 }
00161 
00162 TMPL Quotient_series
00163 operator - (const Quotient_series& f, const Quotient_series& g) {
00164   if (f->m == g->m) return Quotient_series (f->f - g->f, f->m);
00165   else {
00166     Monomial m= gcd (f->m, g->m);
00167     return Quotient_series (f->f * (f->m / m) - g->f * (g->m / m), m);
00168   }
00169 }
00170 
00171 TMPL Quotient_series
00172 operator - (const Quotient_series& f, const C& c) {
00173   return Quotient_series (f->f - Quotient_series (c));
00174 }
00175 
00176 TMPL Quotient_series
00177 operator - (const C& c, const Quotient_series& f) {
00178   return Quotient_series (Quotient_series (c) - f->f);
00179 }
00180 
00181 TMPL Quotient_series
00182 operator * (const Monomial& m, const Quotient_series& f) {
00183   return Quotient_series (f->f, m * f->m);
00184 }
00185 
00186 TMPL Quotient_series
00187 operator * (const Quotient_series& f, const Monomial& m) {
00188   return Quotient_series (f->f, f->m * m);
00189 }
00190 
00191 TMPL Quotient_series
00192 operator * (const C& c, const Quotient_series& f) {
00193   return Quotient_series (c * f->f, f->m);
00194 }
00195 
00196 TMPL Quotient_series
00197 operator * (const Quotient_series& f, const C& c) {
00198   return Quotient_series (c * f->f, f->m);
00199 }
00200 
00201 TMPL Quotient_series
00202 operator * (const Quotient_series& f, const Quotient_series& g) {
00203   return Quotient_series (f->f * g->f, f->m * g->m);
00204 }
00205 
00206 TMPL Quotient_series
00207 operator / (const Quotient_series& f, const Monomial& m) {
00208   return Quotient_series (f->f, f->m / m);
00209 }
00210 
00211 TMPL Quotient_series
00212 operator / (const Monomial& m, const Quotient_series& f) {
00213   Monomial v= monomial_val (f);
00214   if (v != Monomial (1)) return (m/v) / (f/v);
00215   return Quotient_series (C(1) / f->f, m / f->m);
00216 }
00217 
00218 TMPL Quotient_series
00219 operator / (const Quotient_series& f, const C& c) {
00220   return Quotient_series (f->f / c, f->m);
00221 }
00222 
00223 TMPL Quotient_series
00224 operator / (const C& c, const Quotient_series& f) {
00225   Monomial v= monomial_val (f);
00226   if (v != Monomial (1)) return (c / (f/v)) / v;
00227   return Quotient_series (c / f->f, Monomial (1) / f->m);
00228 }
00229 
00230 TMPL Quotient_series
00231 operator / (const Quotient_series& f, const Quotient_series& g) {
00232   Monomial v= monomial_val (g);
00233   if (v != Monomial (1)) return (f/v) / (g/v);
00234   return Quotient_series (f->f / g->f, f->m);
00235 }
00236 
00237 ARITH_SCALAR_INT_SUGAR(TMPL,Quotient_series);
00238 
00239 #undef TMPL_DEF
00240 #undef TMPL
00241 #undef C
00242 #undef Stair
00243 #undef Variable
00244 #undef Quotient_series
00245 #undef Quotient_series_rep
00246 #undef Set
00247 } // namespace mmx
00248 #endif // __MMX__QUOTIENT_SERIES__HPP
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines