Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hint about how to sort with a monomial ordering #4626

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lgoettgens
Copy link
Member

@lgoettgens lgoettgens commented Feb 21, 2025

From slack:

@fingolfin : hmmm... should we perhaps define something like isless(ord) = (m1, m2) -> cmp(o, m1, m2) < 0 to make such things more convenient? So one can write sort(G; lt=isless(o)) But perhaps I am over-engineering again 🙂

@lgoettgens : That could break a lot of generic julia code, as that may expect isless to compare its arguments directly. So we would need a different name for that. But what we definitely could do, is add this line of code to the docstring of cmp

I opened this to not forget. If people have ideas what to do here, please chime in. (tagging triage to ask there for ideas)

@fingolfin
Copy link
Member

fingolfin commented Feb 21, 2025

I don't understand how this would break or even affect generic Julia code. AFAIK all such code expects a 2-arg isless. What I am suggesting is to have a convenient way to turn an "ordering" into a function that can be passed into places that want an "isless" / < function. Indeed, you omitted the example implementation I provided in that discussion:

isless(ord) = (m1, m2) -> cmp(ord, m1, m2) < 0 

So this unary method returns a binary method.

Of course we could do that under a different name, the main reason I thought to use isless(o) is that it's very easy to remember. But I also said:

But perhaps I am over-engineering again 🙂

@lgoettgens
Copy link
Member Author

For similar functions like isequal and < there is a 1-arg method that is defined via partial application. I am not sure if this is the case for isless as well, but if yes, this would be an ambiguity for isless(ord) if that gives an ordering function for mpolys, or a partial application of ordering of orderings

@fingolfin
Copy link
Member

Ok. Another option would be to just allow ord itself to be used as lt-competator, i.e. sort(x; lt=ord)

@joschmitt
Copy link
Member

This is slightly orthogonal to the discussion about sorting, but would it make sense to have isless(::MPolyRingElem, ::MPolyRingElem; ordering::MonomialOrdering)? We seem to have isless for (some?) multivariate polynomials, I assume it compares with respect to the "internal ordering". Putting the ordering as a keyword argument would fit similar functions like leading_monomial etc. But maybe this is against Julia conventions?

(Every time I have to use cmp I have to read up what it does again, so I would like to have a foolproof way to compare monomials.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants