Skip to content

Commit a30f7c4

Browse files
committed
Default == and isequal for NCRingElem
1 parent abbe2ac commit a30f7c4

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/NCRings.jl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,22 @@ end
8383

8484
*(x::NCRingElement, y::NCRingElem) = parent(y)(x)*y
8585

86-
function ==(x::NCRingElem, y::NCRingElem)
87-
fl, u, v = try_promote(x, y)
88-
if fl
89-
return u == v
90-
else
91-
return false
92-
end
93-
end
94-
86+
# == throws an error when inputs have different parent to help user
87+
# find bugs in their code
88+
function ==(a::NCRingElem, b::NCRingElem)
89+
check_parent(a, b)
90+
throw(NotImplementedError(:(==), x, y))
91+
end
92+
93+
# isequal treats ring elements with differing parent as simply being not equal
94+
# (instead of throwing an exception like == does) as it is used to compare set
95+
# elements or keys in dictionaries, and there it seems at least plausible to
96+
# allow mixed parents
97+
function isequal(a::NCRingElem, b::NCRingElem)
98+
return parent(a) == parent(b) && a == b
99+
end
100+
101+
95102
==(x::NCRingElem, y::NCRingElement) = x == parent(x)(y)
96103

97104
==(x::NCRingElement, y::NCRingElem) = parent(y)(x) == y

src/Rings.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
#
55
###############################################################################
66

7-
function isequal(a::RingElem, b::RingElem)
8-
return parent(a) == parent(b) && a == b
9-
end
10-
117
# Implement `isapprox` for ring elements via equality by default. On the one
128
# hand, we need isapprox methods to be able to conformance test series rings.
139
# On the other hand this is essentially the only sensible thing to do in

0 commit comments

Comments
 (0)