Macaulay2 Engine
Loading...
Searching...
No Matches

◆ compare() [2/2]

int FreeMonoid::compare ( const Word & w1,
const Word & m2 ) const

Definition at line 132 of file FreeMonoid.cpp.

133{
134 int weight1;
135 int weight2;
136
137 // compute and compare weights
138 for (int i = 0; i < mNumWeights; ++i)
139 {
140 weight1 = 0;
141 weight2 = 0;
142 for (int j = 0; j < w1.size(); ++j)
143 weight1 += weightOfVar(w1[j],i);
144 for (int j = 0; j < w2.size(); ++j)
145 weight2 += weightOfVar(w2[j],i);
146 if (weight1 > weight2) return GT;
147 if (weight1 < weight2) return LT;
148 }
149
150 if (w1.size() > w2.size()) return GT;
151 if (w1.size() < w2.size()) return LT;
152 // at this stage, they have the same weights and word length, so use lex order
153 for (int i = 0; i < w1.size(); ++i)
154 {
155 if (w1[i] > w2[i]) return LT;
156 if (w1[i] < w2[i]) return GT;
157 }
158 // if we are here, the monomials corresponding to the words are the same.
159 return EQ;
160}
const int mNumWeights
int weightOfVar(int v, int wt) const
int size() const
Definition Word.hpp:74
const int EQ
Definition style.hpp:40
const int GT
Definition style.hpp:41
const int LT
Definition style.hpp:39

References EQ, GT, LT, mNumWeights, Word::size(), and weightOfVar().