Skip to content

Commit ab6ff47

Browse files
committed
Lax parent checks in isequal methods
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
1 parent cd5214b commit ab6ff47

10 files changed

Lines changed: 13 additions & 23 deletions

File tree

docs/src/ring_interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ function ==(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
918918
end
919919
920920
function isequal(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
921-
check_parent(f, g)
921+
parent(f) == parent(g) || return false
922922
return isequal(f.c, g.c)
923923
end
924924

src/AbsSeries.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,8 @@ power series are precisely the same, to the same precision, are they declared
522522
equal by this function.
523523
"""
524524
function isequal(x::AbsPowerSeriesRingElem{T}, y::AbsPowerSeriesRingElem{T}) where T <: RingElement
525-
if parent(x) != parent(y)
526-
return false
527-
end
525+
parent(x) == parent(y) || return false
526+
528527
if precision(x) != precision(y) || length(x) != length(y)
529528
return false
530529
end

src/Fraction.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,7 @@ inexact, e.g. power series. Only if the power series are precisely the same,
431431
to the same precision, are they declared equal by this function.
432432
"""
433433
function isequal(x::FracElem{T}, y::FracElem{T}) where {T <: RingElem}
434-
if parent(x) != parent(y)
435-
return false
436-
end
434+
parent(x) == parent(y) || return false
437435
return isequal(numerator(x, false)*denominator(y, false),
438436
denominator(x, false)*numerator(y, false))
439437
end

src/Matrix.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,7 @@ series. Only if the power series are precisely the same, to the same precision,
13331333
are they declared equal by this function.
13341334
"""
13351335
function isequal(x::MatrixElem{T}, y::MatrixElem{T}) where {T <: NCRingElement}
1336-
b = check_parent(x, y, false)
1337-
!b && return false
1336+
parent(x) == parent(y) || return false
13381337
for i = 1:nrows(x)
13391338
for j = 1:ncols(x)
13401339
if !isequal(x[i, j], y[i, j])

src/NCPoly.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,7 @@ power series. Only if the power series are precisely the same, to the same
366366
precision, are they declared equal by this function.
367367
"""
368368
function isequal(x::NCPolyRingElem{T}, y::NCPolyRingElem{T}) where T <: NCRingElem
369-
if parent(x) != parent(y)
370-
return false
371-
end
369+
parent(x) == parent(y) || return false
372370
if length(x) != length(y)
373371
return false
374372
end

src/Poly.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,8 @@ power series. Only if the power series are precisely the same, to the same
920920
precision, are they declared equal by this function.
921921
"""
922922
function isequal(x::PolyRingElem{T}, y::PolyRingElem{T}) where T <: RingElement
923-
if parent(x) != parent(y)
924-
return false
925-
end
923+
parent(x) == parent(y) || return false
924+
926925
if length(x) != length(y)
927926
return false
928927
end

src/RelSeries.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,8 @@ power series are precisely the same, to the same precision, are they declared
765765
equal by this function.
766766
"""
767767
function isequal(x::RelPowerSeriesRingElem{T}, y::RelPowerSeriesRingElem{T}) where T <: RingElement
768-
if parent(x) != parent(y)
769-
return false
770-
end
768+
parent(x) == parent(y) || return false
769+
771770
if precision(x) != precision(y) || pol_length(x) != pol_length(y) ||
772771
valuation(x) != valuation(y)
773772
return false

src/Residue.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ Only if the power series are precisely the same, to the same precision, are
270270
they declared equal by this function.
271271
"""
272272
function isequal(a::ResElem{T}, b::ResElem{T}) where {T <: RingElement}
273-
fl = check_parent(a, b, false)
274-
!fl && return false
273+
parent(a) == parent(b) || return false
275274
return isequal(data(a), data(b))
276275
end
277276

src/generic/LaurentSeries.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,7 @@ power series are precisely the same, to the same precision, are they declared
11001100
equal by this function.
11011101
"""
11021102
function isequal(x::LaurentSeriesElem{T}, y::LaurentSeriesElem{T}) where {T <: RingElement}
1103-
if parent(x) != parent(y)
1104-
return false
1105-
end
1103+
parent(x) == parent(y) || return false
11061104
if precision(x) != precision(y) || pol_length(x) != pol_length(y) ||
11071105
valuation(x) != valuation(y) || scale(x) != scale(y)
11081106
return false

src/generic/PuiseuxSeries.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ function ==(a::PuiseuxSeriesElem{T}, b::PuiseuxSeriesElem{T}) where T <: RingEle
571571
end
572572

573573
function isequal(a::PuiseuxSeriesElem{T}, b::PuiseuxSeriesElem{T}) where T <: RingElement
574+
parent(a) == parent(b) || return false
574575
return a.scale == b.scale && isequal(a.data, b.data)
575576
end
576577

0 commit comments

Comments
 (0)