Skip to content

Commit fba896a

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 555a183 commit fba896a

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
@@ -1286,8 +1286,7 @@ series. Only if the power series are precisely the same, to the same precision,
12861286
are they declared equal by this function.
12871287
"""
12881288
function isequal(x::MatrixElem{T}, y::MatrixElem{T}) where {T <: NCRingElement}
1289-
b = check_parent(x, y, false)
1290-
!b && return false
1289+
parent(x) == parent(y) || return false
12911290
for i = 1:nrows(x)
12921291
for j = 1:ncols(x)
12931292
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
@@ -361,9 +361,7 @@ power series. Only if the power series are precisely the same, to the same
361361
precision, are they declared equal by this function.
362362
"""
363363
function isequal(x::NCPolyRingElem{T}, y::NCPolyRingElem{T}) where T <: NCRingElem
364-
if parent(x) != parent(y)
365-
return false
366-
end
364+
parent(x) == parent(y) || return false
367365
if length(x) != length(y)
368366
return false
369367
end

src/Poly.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,8 @@ power series. Only if the power series are precisely the same, to the same
859859
precision, are they declared equal by this function.
860860
"""
861861
function isequal(x::PolyRingElem{T}, y::PolyRingElem{T}) where T <: RingElement
862-
if parent(x) != parent(y)
863-
return false
864-
end
862+
parent(x) == parent(y) || return false
863+
865864
if length(x) != length(y)
866865
return false
867866
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)