-
Notifications
You must be signed in to change notification settings - Fork 67
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?
Changes from all commits
a30f7c4
db82bbc
4ef9fc7
fd7aa4e
260d487
0a069dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 (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) |
||
|
||
return (denominator(x, false) == denominator(y, false) && | ||
numerator(x, false) == numerator(y, false)) || | ||
|
@@ -437,9 +436,7 @@ inexact, e.g. power series. Only if the power series are precisely the same, | |
to the same precision, are they declared equal by this function. | ||
""" | ||
function isequal(x::FracElem{T}, y::FracElem{T}) where {T <: RingElem} | ||
if parent(x) != parent(y) | ||
return false | ||
end | ||
parent(x) == parent(y) || return false | ||
return isequal(numerator(x, false)*denominator(y, false), | ||
denominator(x, false)*numerator(y, false)) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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) |
||
if fl | ||
return u == v | ||
else | ||
return false | ||
end | ||
end | ||
|
||
# == throws an error when inputs have different parent to help user | ||
# find bugs in their code | ||
function ==(a::NCRingElem, b::NCRingElem) | ||
check_parent(a, b) | ||
throw(NotImplementedError(:(==), x, y)) | ||
end | ||
|
||
# isequal treats ring elements with differing parent as simply being not equal | ||
# (instead of throwing an exception like == does) as it is used to compare set | ||
# elements or keys in dictionaries, and there it seems at least plausible to | ||
# allow mixed parents | ||
function isequal(a::NCRingElem, b::NCRingElem) | ||
return parent(a) == parent(b) && a == b | ||
end | ||
|
||
|
||
==(x::NCRingElem, y::NCRingElement) = x == parent(x)(y) | ||
|
||
==(x::NCRingElement, y::NCRingElem) = parent(y)(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 more generous (but it's only example code)