synaps/mpol/MPol_with_texp.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS kernel.        *
00003 *      Author(s): B. Mourrain, GALAAD, INRIA                         *
00004 **********************************************************************
00005 $Id: MPol_with_texp.h,v 1.1 2005/07/11 11:17:56 mourrain Exp $
00006 **********************************************************************/
00007 #ifndef SYNAPS_MPOL_MPOL_WITH_TEXP_H
00008 #define SYNAPS_MPOL_MPOL_WITH_TEXP_H
00009 
00010 #include <synaps/init.h>
00011 
00012 __BEGIN_NAMESPACE_SYNAPS
00013 
00014 
00016 template <class C, class O, class R> 
00017 inline VAL<OP<'+',MPol<C,O,R>,MPol<C,O,R> > >
00018   operator+(const MPol<C,O,R> & a, const MPol<C,O,R> & b)
00019 {
00020   return VAL<OP<'+',MPol<C,O,R>,MPol<C,O,R> > >
00021     (OP<'+',MPol<C,O,R>,MPol<C,O,R> >(a,b));
00022 }
00023 //----------------------------------------------------------------------
00024 template<class C, class O, class R> inline
00025 void assign(MPol<C,O,R> & p, const OP<'+',MPol<C,O,R>, MPol<C,O,R> >& M) 
00026 {
00027   if(&p == &M.op1 && &p == &M.op2)
00028     MPOL::add<O,R>(p.rep(),MPol<C,O,R>(M.op2).rep());
00029   else if(&p == &M.op1)
00030     MPOL::add<O,R>(p.rep(),M.op2.rep());
00031   else if(&p == &M.op2)
00032     MPOL::add<O,R>(p.rep(),M.op1.rep());
00033   else 
00034     MPOL::add<O,R>(p.rep(),M.op1.rep(),M.op2.rep());
00035 }
00036 //----------------------------------------------------------------------
00037 // operator - 
00038 template <class C, class O, class R> 
00039 inline VAL<OP<'-',MPol<C,O,R>,MPol<C,O,R> > >
00040   operator-(const MPol<C,O,R> & a, const MPol<C,O,R> & b)
00041 {
00042   return VAL<OP<'-',MPol<C,O,R>,MPol<C,O,R> > >
00043     (OP<'-',MPol<C,O,R>,MPol<C,O,R> >(a,b));
00044 }
00045 //----------------------------------------------------------------------
00046 template<class C, class O, class R> inline
00047 void assign( MPol<C,O,R> & p, const OP<'-',MPol<C,O,R>, MPol<C,O,R> >& M) 
00048 {
00049   MPOL::minus<O,R>(p.rep(),M.op1.rep(),M.op2.rep());
00050 }
00051 //----------------------------------------------------------------------
00052 // Unary operator - 
00053 template <class C, class O, class R> 
00054 inline VAL<OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::coeff_t> >
00055   operator-(const MPol<C,O,R> & a)
00056 {
00057   return VAL<OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::coeff_t> >
00058     (OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::coeff_t>
00059      (a,(typename MPol<C,O,R>::coeff_t)-1));
00060 }
00061 //----------------------------------------------------------------------
00062 // Product of polynomials 
00063 template <class C, class O, class R>  inline 
00064 VAL<OP<'*',MPol<C,O,R>,MPol<C,O,R> > >
00065   operator*(const MPol<C,O,R> & a, const MPol<C,O,R> & b)
00066 {
00067   return VAL<OP<'*',MPol<C,O,R>,MPol<C,O,R> > >
00068    (OP<'*',MPol<C,O,R>,MPol<C,O,R> >(a,b));
00069 }
00070 //----------------------------------------------------------------------
00071 template<class C, class O, class R> inline
00072 void assign( MPol<C,O,R> & p, 
00073              const OP<'*',MPol<C,O,R>, MPol<C,O,R> >& M) 
00074 {
00075   if(M.op1 !=0 && M.op2 !=0)
00076     MPOL::mult(p.rep(),M.op1.rep(),M.op2.rep(),O());
00077   else
00078     p= MPol<C,O,R>(0);
00079 }
00080 //----------------------------------------------------------------------
00081 // Product of a polynomial by a scalar
00082 template <class C, class O, class R> inline 
00083 VAL<OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::coeff_t> >
00084   operator*(const MPol<C,O,R> & a, const typename MPol<C,O,R>::coeff_t & c)
00085 {
00086   typedef typename MPol<C,O,R>::coeff_t C;
00087   return VAL<OP<'.',MPol<C,O,R>,C> >(OP<'.',MPol<C,O,R>,C>(a,c));
00088 }
00089 //----------------------------------------------------------------------
00090 template<class C, class O, class R> inline
00091 void assign( MPol<C,O,R> & p, 
00092              const OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::coeff_t> & M) 
00093 { 
00094   if(M.op1 !=0)
00095     MPOL::mul_ext(p.rep(),M.op1.rep(),M.op2);
00096  else
00097     p= MPol<C,O,R>(0);
00098 }
00099 //----------------------------------------------------------------------
00100 // Product of a polynomial by a monomial
00101 template <class C, class O, class R> inline
00102 VAL<OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::monom_t> >
00103 operator*(const MPol<C,O,R> & P, 
00104                      const typename MPol<C,O,R>::monom_t & m) 
00105 {
00106   return VAL<OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::monom_t> >
00107     (OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::monom_t>(P,m));
00108 }
00109 //----------------------------------------------------------------------
00110 // Product of a polynomial by a monomial
00111 template <class C, class O, class R> inline
00112 VAL<OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::monom_t> >
00113 operator*(const typename MPol<C,O,R>::monom_t & m,const MPol<C,O,R> & P) 
00114 {
00115   return VAL<OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::monom_t> >
00116     (OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::monom_t>(P,m));
00117 }
00118 //----------------------------------------------------------------------
00119 template<class C, class O, class R> inline
00120 void assign( MPol<C,O,R> & p, 
00121              const OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::monom_t> & M) 
00122 {
00123   if(M.op1 !=0)
00124     MPOL::mul_ext(p.rep(),M.op1.rep(),M.op2);
00125   else
00126     p= MPol<C,O,R>(0);
00127 }
00128 //----------------------------------------------------------------------
00129 template <class C, class O, class R> inline
00130 VAL<OP<'/',MPol<C,O,R>,MPol<C,O,R> > >
00131 operator/(const MPol<C,O,R> & A, const MPol<C,O,R> & B) 
00132 {
00133   return VAL<OP<'/',MPol<C,O,R>,MPol<C,O,R> > >
00134     (OP<'/',MPol<C,O,R>,MPol<C,O,R> >(A,B));
00135 }
00136 //----------------------------------------------------------------------
00137 template<class C, class O, class R> inline
00138 void assign( MPol<C,O,R> & p, 
00139              const OP<'/',MPol<C,O,R>,MPol<C,O,R> > & M) 
00140 {
00141   p=M.op1; p/=M.op2;
00142 }
00143 //----------------------------------------------------------------------
00144 template <class C, class O, class R> inline
00145 VAL<OP<'^',MPol<C,O,R>, unsigned int> >
00146 operator^(const MPol<C,O,R> & A, unsigned int n) 
00147 {
00148   return VAL<OP<'^',MPol<C,O,R>,unsigned int > >
00149     (OP<'^',MPol<C,O,R>,unsigned int >(A,n));
00150 }
00151 //----------------------------------------------------------------------
00152 template<class C, class O, class R> inline
00153 void assign( MPol<C,O,R> & p, 
00154              const OP<'^',MPol<C,O,R>,unsigned int > & M) 
00155 {
00156   if(M.op2==0) p = MPol<C,O,R>(1);
00157   else {
00158     p=1;
00159     unsigned N = M.op2;
00160     while(N>0) {p*=M.op1; N--;}
00161   }
00162 }
00163 //----------------------------------------------------------------------
00164 template<class C, class O, class R> inline
00165 void assign( MPol<C,O,R> & p, 
00166              const OP<'.',MPol<C,O,R>,typename MPol<C,O,R>::monom_t> & M) 
00167 {
00168   if(M.op1 !=0)
00169     MPOL::mul_ext(p.rep(),M.op1.rep(),M.op2);
00170   else
00171     p= MPol<C,O,R>(0);
00172 }
00173 //----------------------------------------------------------------------
00174 
00175 __END_NAMESPACE_SYNAPS
00176 
00177 
00178 #endif // SYNAPS_MPOL_MPOL_WITH_TEXP_H
00179 

SYNAPS DOCUMENTATION
logo