-
Notifications
You must be signed in to change notification settings - Fork 63
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
Revise == and isequal for ring elements #1854
base: master
Are you sure you want to change the base?
Conversation
I am always confused about the difference in contracts of |
I like it. (It won't work for So the rules would be:
Right? |
In magma it's 'eq' which throws if apples and pears are compared, and
'cmpeq' which returns false. Both are useful, but I prefer errors in bad
comparisons. Julia has some strange ideas there...I think based on
narrow(ish) use cases in numeric.
Generically, almost always it parents do not match it illustrates flaws in
my code.
Also dicts with mixed key space and "same" keys in different worlds are
going to produce lots of oain
…On Thu, 10 Oct 2024, 09:31 Tommy Hofmann, ***@***.***> wrote:
I like it. (It won't work for x in [y, z] (since this uses == for
whatever reasons), but dictionaries seem to work, which is fine for me.)
So the rules would be:
- == errors if parents are not equal, taken promotion into account,
- isequal yields false in case == would raise an error.
Right?
—
Reply to this email directly, view it on GitHub
<#1854 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA36CV4TI2E24C7GN5MI7NLZ2YUNTAVCNFSM6AAAAABPVNKDN2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBUGI4DANRZGU>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
As Claus said, this turns
I would not say that julia has strange ideas. It allows for a difference between But I am in favor of turning
I can now just write
|
The strange is to define == to default to false
…On Thu, 10 Oct 2024, 09:52 Tommy Hofmann, ***@***.***> wrote:
As Claus said, this turns isequal into cmpeq from Magma. Here is the
docstring (from https://magma.maths.usyd.edu.au/magma/handbook/text/8):
x cmpeq y : Any, Any -> BoolElt
If x and y are comparable, return whether x equals y. Otherwise, return
false. Thus this operator always returns a value and an error never
results. It is useful when comparing two objects of completely different
types where it is desired that no error should occur. However, it is
strongly recommended that eq is usually used to allow Magma to pick up
common unintentional type errors.
I would not say that julia has strange ideas. It allows for a difference
between isequal and ==, which one can use, but one does not need to use.
Nothing is broken if one only sticks to == and forgets that isequal
exists.
But I am in favor of turning isequal into cmpeq. For a user it is not
useful, but it is very useful for library code when doing argument
checking. For example, instead of writing
for x in A
@Req parent(x) == R && x == a # where parent(a) == R
end
I can now just write
@Req all(isequal(a), A)
—
Reply to this email directly, view it on GitHub
<#1854 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA36CV7PT5PXQGJ2WF4S7ZLZ2YW5HAVCNFSM6AAAAABPVNKDN2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBUGM2DCOBZGE>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
x-ref JuliaLang/julia#40717 |
To clarify: we already had a bunch of Honestly I am not sure how useful it is to have this more generous BTW there are more things to wonder about: e.g. some rings have separate |
@@ -900,7 +900,7 @@ function ==(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement | |||
end | |||
|
|||
function isequal(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement | |||
check_parent(f, g) | |||
parent(f) == parent(g) || return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got more generous (but it's only example code)
@@ -417,8 +417,7 @@ that power series to different precisions may still be arithmetically | |||
equal to the minimum of the two precisions. | |||
""" | |||
function ==(x::FracElem{T}, y::FracElem{T}) where {T <: RingElem} | |||
b = check_parent(x, y, false) | |||
!b && return false | |||
check_parent(x, y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got stricter. An alternative would be to allow comparison of x and y with differing parents, but IMHO only if that means arithmetic comparison, i.e.: removing the parent check entirely and just proceeding to the following checks involving comparison of numerators and denominators and all. Returning false
just because the parents are different is IMHO the worst of all ways to handle this, and a source of errors.
(To be clear, I prefer the error; the point I am trying to make here is that the current behavior is worse than either of the alternatives)
The default method already delegates to ==
... to delegate to isequal for the data
Since isequal is called for e.g. keys in dictionaries, it makes sense to allow comparing rings with different parents, and reporting them as being non-equal
fba896a
to
0a069dc
Compare
This fails in a really strange test in
I call this strange because (a) this test has nothing to do with free associative algebras, and (b) it is completely unclear to me what this should test in the first place. Regarding (a) I think this may be due to copy&paste, because the exact same test is also in I am tempted to just delete this in both places, unless someone has an idea what this is about (which then might inform how to modify the copy in Actually as I type this, I wonder: perhaps the mistake is that it does |
This is exactly what I thought this did until I re-checked the code again. This would make sense to me, and could be some non-trivial issue with the change of ==. |
@@ -83,15 +83,22 @@ end | |||
|
|||
*(x::NCRingElement, y::NCRingElem) = parent(y)(x)*y | |||
|
|||
function ==(x::NCRingElem, y::NCRingElem) | |||
fl, u, v = try_promote(x, y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's look into retaining this, and documenting this promotion system (and then perhaps we can also use it to simplify some other code which does ad-hoc stuff right now)
I found what I vaguely remembered. For some reason we made AbstractAlgebra.jl/docs/src/series.md Lines 293 to 300 in 983f6ec
Unfortunately, this makes the idea of having |
This makes it so that
==
throws if parents don't match, whileisequal
does not (just returnsfalse
). Does not (yet) adjust docs to explain that.However retain ad-hoc
==
methods, were the inputs obviously don't have matching parents, so they don't throw.Question is: do we want this? I think for polynomial & series rings: yes. But in general?
Note have some code to ad-hoc matrix comparison... So the current behavior is not actually changed for matrices. In particular we get this on
master
but also with this PR:Closes #1800, resolves oscar-system/Oscar.jl#4107.
Does not replace #1853 which acts on a lower level.