synaps/mpol/DegLex.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS kernel.        *
00003 *      Author(s): B. Mourrain, GALAAD, INRIA                         *
00004 **********************************************************************
00005 $Id: DegLex.h,v 1.1 2005/07/11 11:17:56 mourrain Exp $
00006 **********************************************************************/
00007 #ifndef SYNAPS_MPOL_DEGLEX_H
00008 #define SYNAPS_MPOL_DEGLEX_H
00009 
00010 #include <synaps/init.h>
00011 
00012 __BEGIN_NAMESPACE_SYNAPS
00013 
00020 struct DegLex 
00021 {
00022   template <class M>  static bool less (const M &, const M &);
00023   template <class M>  bool operator() (const M & m1, const M & m2) const 
00024     {return less(m1,m2);}
00025 };
00026  
00027 template <class M>
00028 bool DegLex::less(const M & m1, const M & m2) {
00029   
00030    if (degree(m1) < degree(m2) ) return true;
00031    else if (degree(m1) > degree(m2)) return false;
00032    else {
00033      int n1 = m1.nvars(), n2 =m2.nvars();
00034      if(n1 <0 && n2>0) return false;
00035      if(n1 <0 && n2<0) return false;
00036      if(n2 <0 && n1>0) return true;
00037      int n = std::max(n1,n2); 
00038      int i = std::max(n,0); 
00039      while(i>=0 && m1[i] == m2[i]) i--;
00040      if(i <0) 
00041        return false;
00042      else 
00043        return (m1[i]> m2[i]);
00044    }
00045 }
00046 
00047 // template <class M>
00048 // bool operator<(const M & m1, const M & m2) {return DegLex<M>::less(m1,m2);}
00049 
00050 __END_NAMESPACE_SYNAPS
00051 
00052 #endif // SYNAPS_MPO_DEGLEX_H
00053 

SYNAPS DOCUMENTATION
logo