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
00015
00016 if (d1 < d2 ) return true;
00017 else if (d1 > d2) return false;
00018 else {
00019
00020
00021
00022 int n = (n1>n2?n1:n2);
00023
00024 int i;
00025 for(i = (n>0?n:0); i>=0 && (i<n1?m1[i]:0) == (i<n2?m2[i]:0);i--);
00026
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
00041
00042 if (d1 < d2 ) return false;
00043 else if (d1 > d2) return true;
00044 else {
00045
00046
00047
00048 int n = (n1>n2?n1:n2);
00049
00050 int i;
00051 for(i = (n>0?n:0); i>=0 && (i<n1?m1[i]:0) == (i<n2?m2[i]:0);i--);
00052
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 }
00069 #endif //mmx_realroot_monomial_ordering_cpp