Skip to content

Commit 0a069dc

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 260d487 commit 0a069dc

File tree

11 files changed

+14
-24
lines changed

11 files changed

+14
-24
lines changed

docs/src/ring_interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ function ==(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
900900
end
901901

902902
function isequal(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
903-
check_parent(f, g)
903+
parent(f) == parent(g) || return false
904904
return isequal(f.c, g.c)
905905
end
906906

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
@@ -436,9 +436,7 @@ inexact, e.g. power series. Only if the power series are precisely the same,
436436
to the same precision, are they declared equal by this function.
437437
"""
438438
function isequal(x::FracElem{T}, y::FracElem{T}) where {T <: RingElem}
439-
if parent(x) != parent(y)
440-
return false
441-
end
439+
parent(x) == parent(y) || return false
442440
return isequal(numerator(x, false)*denominator(y, false),
443441
denominator(x, false)*numerator(y, false))
444442
end

src/Matrix.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,8 +1323,7 @@ series. Only if the power series are precisely the same, to the same precision,
13231323
are they declared equal by this function.
13241324
"""
13251325
function isequal(x::MatrixElem{T}, y::MatrixElem{T}) where {T <: NCRingElement}
1326-
b = check_parent(x, y, false)
1327-
!b && return false
1326+
parent(x) == parent(y) || return false
13281327
for i = 1:nrows(x)
13291328
for j = 1:ncols(x)
13301329
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
@@ -363,9 +363,7 @@ power series. Only if the power series are precisely the same, to the same
363363
precision, are they declared equal by this function.
364364
"""
365365
function isequal(x::NCPolyRingElem{T}, y::NCPolyRingElem{T}) where T <: NCRingElem
366-
if parent(x) != parent(y)
367-
return false
368-
end
366+
parent(x) == parent(y) || return false
369367
if length(x) != length(y)
370368
return false
371369
end

src/Poly.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,8 @@ power series. Only if the power series are precisely the same, to the same
861861
precision, are they declared equal by this function.
862862
"""
863863
function isequal(x::PolyRingElem{T}, y::PolyRingElem{T}) where T <: RingElement
864-
if parent(x) != parent(y)
865-
return false
866-
end
864+
parent(x) == parent(y) || return false
865+
867866
if length(x) != length(y)
868867
return false
869868
end

src/RelSeries.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,8 @@ power series are precisely the same, to the same precision, are they declared
761761
equal by this function.
762762
"""
763763
function isequal(x::RelPowerSeriesRingElem{T}, y::RelPowerSeriesRingElem{T}) where T <: RingElement
764-
if parent(x) != parent(y)
765-
return false
766-
end
764+
parent(x) == parent(y) || return false
765+
767766
if precision(x) != precision(y) || pol_length(x) != pol_length(y) ||
768767
valuation(x) != valuation(y)
769768
return false

src/Residue.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ Only if the power series are precisely the same, to the same precision, are
256256
they declared equal by this function.
257257
"""
258258
function isequal(a::ResElem{T}, b::ResElem{T}) where {T <: RingElement}
259-
fl = check_parent(a, b, false)
260-
!fl && return false
259+
parent(a) == parent(b) || return false
261260
return isequal(data(a), data(b))
262261
end
263262

src/generic/LaurentSeries.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,7 @@ power series are precisely the same, to the same precision, are they declared
10931093
equal by this function.
10941094
"""
10951095
function isequal(x::LaurentSeriesElem{T}, y::LaurentSeriesElem{T}) where {T <: RingElement}
1096-
if parent(x) != parent(y)
1097-
return false
1098-
end
1096+
parent(x) == parent(y) || return false
10991097
if precision(x) != precision(y) || pol_length(x) != pol_length(y) ||
11001098
valuation(x) != valuation(y) || scale(x) != scale(y)
11011099
return false

src/generic/PuiseuxSeries.jl

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

566566
function isequal(a::PuiseuxSeriesElem{T}, b::PuiseuxSeriesElem{T}) where T <: RingElement
567+
parent(a) == parent(b) || return false
567568
return a.scale == b.scale && isequal(a.data, b.data)
568569
end
569570

0 commit comments

Comments
 (0)