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

◆ compare_elems()

int FreeAlgebra::compare_elems ( const Poly & f,
const Poly & g ) const

Definition at line 260 of file FreeAlgebra.cpp.

261{
262 auto fIt = f.cbegin();
263 auto gIt = g.cbegin();
264 auto fEnd = f.cend();
265 auto gEnd = g.cend();
266 int cmp;
267 for ( ; ; fIt++, gIt++)
268 {
269 if (fIt == fEnd)
270 {
271 if (gIt == gEnd) return EQ;
272 return LT;
273 }
274 if (gIt == gEnd) return GT;
275 // TODO: can we remove the following block? Make sure monoid can handle zero variables...
276 if (numVars() > 0)
277 {
278 cmp = monoid().compare(fIt.monom(),gIt.monom());
279 if (cmp != 0) return cmp;
280 }
281 // if we are here, then the monomials are the same and we compare coefficients.
282 // for example if a,b are in the base and a > b then ax > bx.
283 cmp = coefficientRing()->compare_elems(fIt.coeff(), fIt.coeff());
284 if (cmp != 0) return cmp;
285 }
286}
const Ring * coefficientRing() const
int numVars() const
const FreeMonoid & monoid() const
int compare(const Monom &m1, const Monom &m2) const
virtual int compare_elems(const ring_elem f, const ring_elem g) const =0
const int EQ
Definition style.hpp:40
const int GT
Definition style.hpp:41
const int LT
Definition style.hpp:39

References coefficientRing(), FreeMonoid::compare(), Ring::compare_elems(), EQ, GT, LT, monoid(), and numVars().

Referenced by M2FreeAlgebra::compare_elems(), and TEST().