synaps/mpol/lisp.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS library.       *
00003 *   Author(s): B. Mourrain, GALAAD, INRIA                            *
00004 **********************************************************************
00005 History: 
00006 **********************************************************************/
00007 #ifndef synaps_mpol_lisp_H
00008 #define synaps_mpol_lisp_H
00009 //--------------------------------------------------------------------
00010 #include <iostream>
00011 #include <synaps/base/lisp.h>
00012 #include <synaps/mpol/Variables.h>
00013 //--------------------------------------------------------------------
00014 __BEGIN_NAMESPACE_SYNAPS
00015 //--------------------------------------------------------------------
00016 namespace MONOMIAL 
00017 {     
00018   template<class OSTREAM, class MONOM> 
00019   OSTREAM& lisp(OSTREAM& os, 
00020                 const MONOM & m,
00021                 const Variables & V,
00022                 int i=-1) 
00023   {
00024     //    std::cout <<"\nP: "<<i<<" "<<m<<" "<<m.rep().size()<<std::endl;
00025     if(i<int(m.rep().size()))
00026       {
00027         os<<"(* ";
00028         if(i<0)    
00029           {
00030             print_lisp(os,m.coeff())<<" ";
00031             MONOMIAL::lisp(os,m,V,i+1);
00032           }
00033         else
00034           {
00035           if(m[i] <=1)
00036             {
00037               os<<" "<<V[i]<<" ";
00038             }
00039           else if(m[i]>1)
00040             {
00041               os<<"(^ "<<V[i]<<" "<<m[i]<<") ";
00042             }
00043             MONOMIAL::lisp(os,m,V,i+1);
00044           }
00045         os<<")";
00046       }
00047     else
00048       os<<" 1";
00049     return os;
00050   }
00051 }
00052 //--------------------------------------------------------------------
00053 namespace MPOLDST
00054 {
00055   template <class OSTREAM, class ITER> inline 
00056   OSTREAM& lisp(OSTREAM& os, ITER it,  const ITER &ed, 
00057                 const Variables & V= Variables::default_) 
00058   {
00059     using namespace lisp;
00060     if(it==ed)
00061       return os<<" 0";
00062     else
00063       {
00064         os<<"(+ ";
00065         MONOMIAL::lisp(os,*it,V);
00066         os <<" ";
00067         MPOLDST::lisp(os,++it,ed,V);
00068         os<<")";
00069       } 
00070     return os;
00071   }
00072 } 
00073 //----------------------------------------------------------------------
00074 template<typename C,typename O,typename R> struct MPol;
00075 //----------------------------------------------------------------------
00076 template<class OSTREAM, class C, class R,class O> 
00077 OSTREAM& print_lisp(OSTREAM& os, const MPol<C,O,R>& p) 
00078 {
00079   return MPOLDST::lisp(os,p.begin(),p.end());
00080 }
00081 
00082 template<class C, class R,class O> 
00083 std::ostream& print_lisp(std::ostream& os, const MPol<C,O,R>& p) 
00084 {
00085   return MPOLDST::lisp(os,p.begin(),p.end());
00086 }
00087 //----------------------------------------------------------------------
00088 __END_NAMESPACE_SYNAPS
00089 //----------------------------------------------------------------------
00090 #endif //synaps_mpol_lisp_h

SYNAPS DOCUMENTATION
logo