realroot_doc 0.1.1
/Users/mourrain/Devel/mmx/realroot/src/monomial_ordering.cpp
Go to the documentation of this file.
00001 #ifndef mmx_realroot_monomial_ordering_cpp
00002 #define mmx_realroot_monomial_ordering_cpp
00003 #include <math.h>
00004 #include <iostream>
00005 #include <realroot/monomial_ordering.hpp>
00006 namespace mmx {
00007 
00008   bool DegRevLex::less(const int *m1, int n1, const int *m2, int n2) const {
00009     
00010     int d1=0, d2=0;
00011     for(int i=0;i<n1;i++) d1+=m1[i];
00012     for(int i=0;i<n2;i++) d2+=m2[i];
00013   
00014     //    std::cout<< "less d1:= "<<d1<<std::endl;
00015     //    std::cout<< "less d2:= "<<d2<<std::endl;
00016     if (d1 < d2 ) return true;
00017     else if (d1 > d2) return false;
00018     else {
00019       //     if(n1 <=0 && n2>0) return false;
00020       //     if(n1 <=0 && n2<=0) return false;
00021       //     if(n2 <=0 && n1>0) return true;
00022      int n = (n1>n2?n1:n2); 
00023      //     std::cout<< "less n:= "<<n<<std::endl;
00024      int i;
00025      for(i = (n>0?n:0); i>=0 && (i<n1?m1[i]:0) == (i<n2?m2[i]:0);i--);
00026      //     std::cout<< "less i:= "<<i<<std::endl;
00027      if(i < 0) 
00028        return false;
00029      else 
00030        return ((i<n1?m1[i]:0) > (i<n2?m2[i]:0));
00031    }
00032   }
00033 
00034   bool LexRevDegree::less(const int *m1, int n1, const int *m2, int n2) const {
00035     
00036     int d1=0, d2=0;
00037     for(int i=0;i<n1;i++) d1+=m1[i];
00038     for(int i=0;i<n2;i++) d2+=m2[i];
00039   
00040     //    std::cout<< "less d1:= "<<d1<<std::endl;
00041     //    std::cout<< "less d2:= "<<d2<<std::endl;
00042     if (d1 < d2 ) return false;
00043     else if (d1 > d2) return true;
00044     else {
00045       //     if(n1 <=0 && n2>0) return false;
00046       //     if(n1 <=0 && n2<=0) return false;
00047       //     if(n2 <=0 && n1>0) return true;
00048      int n = (n1>n2?n1:n2); 
00049      //     std::cout<< "less n:= "<<n<<std::endl;
00050      int i;
00051      for(i = (n>0?n:0); i>=0 && (i<n1?m1[i]:0) == (i<n2?m2[i]:0);i--);
00052      //     std::cout<< "less i:= "<<i<<std::endl;
00053      if(i < 0) 
00054        return false;
00055      else 
00056        return ((i<n1?m1[i]:0) > (i<n2?m2[i]:0));
00057    }
00058   }
00059 
00060 
00061   bool Lex::less(const int *m1, int n1, const int *m2, int n2) const {
00062     int i = 0;
00063     for(i=0; i< (n1>n2?n1:n2) && (i<n1?m1[i]:0) == (i<n2?m2[i]:0); i++);
00064     
00065     return ((i<n1?m1[i]:0)< (i<n2?m2[i]:0));
00066   }
00067 //====================================================================== 
00068 } //namespace mmx
00069 #endif //mmx_realroot_monomial_ordering_cpp