synaps/mpol/MONOMIAL.m

00001 /*********************************************************************
00002 *   This file is part of the source code of the SYNAPS.              *
00003 *   Author(s): B. Mourrain, GALAAD, INRIA                            *
00004 **********************************************************************
00005 $Id: MONOMIAL.h,v 1.1 2005/07/11 11:17:56 mourrain Exp $
00006 **********************************************************************/
00007 #ifndef SYNAPS_MPOL_MONOMIAL_H
00008 #define SYNAPS_MPOL_MONOMIAL_H
00009 
00010 #include <synaps/init.h>
00011 #include <synaps/mpol/Variables.h>
00012 
00013 __BEGIN_NAMESPACE_SYNAPS
00014 
00016 namespace MONOMIAL
00017 {
00018   //--------------------------------------------------------------------   
00019   template <class R, class VARIABLES> inline
00020   std::ostream & print_pp (std::ostream & os, const R & m, const VARIABLES& V)
00021   { 
00022     bool first=true;
00023     for (typename R::size_type i = 0; i < m.rep().size(); ++i)
00024       {
00025         if (m[i] !=0)
00026           {
00027             if(first)
00028               first =false;
00029             else
00030               os<<'*';
00031             os << V;
00032             if (m[i] != 1)
00033               os << '^' <<m;
00034           }
00035       }
00036     return os;
00037   }
00038   //--------------------------------------------------------------------
00039   template <class R, class VARIABLES> inline
00040   std::ostream & print (std::ostream & os, const R & m, 
00041                         const VARIABLES& V)
00042   {
00043     if (m.coeff() ==0 )
00044       os<<"0";
00045     else {
00046       int i=m.nvars();
00047       while(i> -1 && m[i]==0) i--;
00048       if(i<0)
00049         os <<m.coeff();
00050       else{
00051       if(m.coeff() != 1) 
00052         if(m.coeff()==-1) os << "-";
00053         else 
00054           os << m.coeff() <<"*";
00055       print_pp(os,m,V);
00056       }
00057     }
00058     return os;
00059   }
00060   //--------------------------------------------------------------------
00061   template <class R> inline
00062   std::ostream& print (std::ostream& os, const R& m)
00063   {
00064     return print(os,m,Variables::default_);
00065   }
00066   //--------------------------------------------------------------------
00067   template <class X> inline
00068   bool has_no_sign(const X & x)
00069   {
00070     return true;
00071   }
00072 
00073 template <class X> inline
00074 bool has_no_sign(const int & x) {return (x>0);}
00075 
00076 inline bool has_no_sign(const unsigned & x)    {return true;}
00077 inline bool has_no_sign(const float & x)       {return (x>0);}
00078 inline bool has_no_sign(const double & x)      {return (x>0);}
00079 inline bool has_no_sign(const long double & x) {return (x>0);}
00080 
00081 //======================================================================
00082 } //CLOSE MONOMIAL
00083 
00084 __END_NAMESPACE_SYNAPS
00085 
00086 #endif // SYNAPS_MPOL_MONOMIAL_H
00087 

SYNAPS DOCUMENTATION
logo