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

Adresses issue with equality/hashing on module orderings #3400

Merged
merged 8 commits into from
Apr 3, 2024

Conversation

RafaelDavidMohr
Copy link
Contributor

Adds == and hashing for ModuleOrderings.

I don't know if this is the best solution, I essentially just circumvent what julia does by default when calling == on structs (which is to call === on every field) by instead calling == recursively on every field.

If this is potentially to dangerous, let me know. It does fix #3347 on my machine.

Tag: @ederc

@RafaelDavidMohr RafaelDavidMohr changed the title Adresses https://github.com/oscar-system/Oscar.jl/issues/3347 Adresses #3347 Feb 20, 2024
@RafaelDavidMohr RafaelDavidMohr changed the title Adresses #3347 Adresses issue with equality/hashing on module orderings Feb 20, 2024
@fieker
Copy link
Contributor

fieker commented Feb 21, 2024

Can't this be handled by matrices or similar like in the monomial Case?
Is there a canonical normal form for those orderings?

@thofma
Copy link
Collaborator

thofma commented Feb 21, 2024

Hm, yes, I wonder whether this is correct:

mutable struct ModOrdering{T} <: AbsModOrdering
   gens::T
   ord::Symbol

If one only checks if gens and ord are equal, then this does not check equality of orderings.

@RafaelDavidMohr
Copy link
Contributor Author

Can't this be handled by matrices or similar like in the monomial Case? Is there a canonical normal form for those orderings?

It can but it is more involved, see theorem 2 here. I decided against this because it would go substantially beyond the addressed issue to implement this and because, as far as I can tell, we don't support any functionality for such general matrix orderings.

If required, I am however happy to take a look at a canonical matrix form for the orderings we do support, maybe it's easier in this case.

@RafaelDavidMohr
Copy link
Contributor Author

Hm, yes, I wonder whether this is correct:

mutable struct ModOrdering{T} <: AbsModOrdering
   gens::T
   ord::Symbol

If one only checks if gens and ord are equal, then this does not check equality of orderings.

I apologize I don't quite understand what you mean. Do you have an example?

@thofma
Copy link
Collaborator

thofma commented Feb 21, 2024

I was thinking about the following situation: The polynomial ring has one variable and the module is free of rank one. Then :lex and :degrevlex and whatnot define all the same orderings, but the equality check proposed here should yield false?

@RafaelDavidMohr
Copy link
Contributor Author

I was thinking about the following situation: The polynomial ring has one variable and the module is free of rank one. Then :lex and :degrevlex and whatnot define all the same orderings, but the equality check proposed here should yield false?

Yes, good point. Ok, I will think of something else.

@RafaelDavidMohr
Copy link
Contributor Author

Brief update: I am working on this but this will take a while. We will need canonical representations of module orderings and they will take a while to implement.

@RafaelDavidMohr RafaelDavidMohr force-pushed the rm/mod-ord-equality branch 2 times, most recently from 0594f99 to aaa3371 Compare March 18, 2024 16:40
@RafaelDavidMohr RafaelDavidMohr marked this pull request as ready for review March 28, 2024 13:41
@RafaelDavidMohr
Copy link
Contributor Author

I've added equality and hashing by embedding the underlying module of the ordering in question into a new polynomial ring and computing the canonical matrix there, which is then used for equality checking and hashing.

While this is not a unique representation of the ordering, it catches at least all reasonable cases that I could come up with.

end

function Base.:(==)(o1::ModuleOrdering, o2::ModuleOrdering)
return canonical_matrix(o1) == canonical_matrix(o2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that == should compare the underlying modules of the orderings as well. And then same for the hash: the field M should be used there as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I completely understand why. If I have two different modules and I want to find out if both share the same ordering, how shall I do that? Note that also for MonomialOrdering we do not compare the corresponding rings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we should definitely keep it consistent and revert the change here. Sorry for the double work @RafaelDavidMohr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, it's reverted.

src/Rings/orderings.jl Outdated Show resolved Hide resolved
@fingolfin fingolfin merged commit 2f95061 into oscar-system:master Apr 3, 2024
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Equality check and hashing for module orderings is broken
6 participants