Skip to content

Commit

Permalink
Lax parent checks in isequal methods
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fingolfin committed Oct 11, 2024
1 parent 260d487 commit 0a069dc
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/src/ring_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ function ==(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
end

function isequal(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
check_parent(f, g)
parent(f) == parent(g) || return false
return isequal(f.c, g.c)
end

Expand Down
5 changes: 2 additions & 3 deletions src/AbsSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,8 @@ power series are precisely the same, to the same precision, are they declared
equal by this function.
"""
function isequal(x::AbsPowerSeriesRingElem{T}, y::AbsPowerSeriesRingElem{T}) where T <: RingElement
if parent(x) != parent(y)
return false
end
parent(x) == parent(y) || return false

if precision(x) != precision(y) || length(x) != length(y)
return false
end
Expand Down
4 changes: 1 addition & 3 deletions src/Fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,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
Expand Down
3 changes: 1 addition & 2 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,7 @@ series. Only if the power series are precisely the same, to the same precision,
are they declared equal by this function.
"""
function isequal(x::MatrixElem{T}, y::MatrixElem{T}) where {T <: NCRingElement}
b = check_parent(x, y, false)
!b && return false
parent(x) == parent(y) || return false
for i = 1:nrows(x)
for j = 1:ncols(x)
if !isequal(x[i, j], y[i, j])
Expand Down
4 changes: 1 addition & 3 deletions src/NCPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ 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::NCPolyRingElem{T}, y::NCPolyRingElem{T}) where T <: NCRingElem
if parent(x) != parent(y)
return false
end
parent(x) == parent(y) || return false
if length(x) != length(y)
return false
end
Expand Down
5 changes: 2 additions & 3 deletions src/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,8 @@ 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::PolyRingElem{T}, y::PolyRingElem{T}) where T <: RingElement
if parent(x) != parent(y)
return false
end
parent(x) == parent(y) || return false

if length(x) != length(y)
return false
end
Expand Down
5 changes: 2 additions & 3 deletions src/RelSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,8 @@ power series are precisely the same, to the same precision, are they declared
equal by this function.
"""
function isequal(x::RelPowerSeriesRingElem{T}, y::RelPowerSeriesRingElem{T}) where T <: RingElement
if parent(x) != parent(y)
return false
end
parent(x) == parent(y) || return false

if precision(x) != precision(y) || pol_length(x) != pol_length(y) ||
valuation(x) != valuation(y)
return false
Expand Down
3 changes: 1 addition & 2 deletions src/Residue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ Only if the power series are precisely the same, to the same precision, are
they declared equal by this function.
"""
function isequal(a::ResElem{T}, b::ResElem{T}) where {T <: RingElement}
fl = check_parent(a, b, false)
!fl && return false
parent(a) == parent(b) || return false
return isequal(data(a), data(b))
end

Expand Down
4 changes: 1 addition & 3 deletions src/generic/LaurentSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,7 @@ power series are precisely the same, to the same precision, are they declared
equal by this function.
"""
function isequal(x::LaurentSeriesElem{T}, y::LaurentSeriesElem{T}) where {T <: RingElement}
if parent(x) != parent(y)
return false
end
parent(x) == parent(y) || return false
if precision(x) != precision(y) || pol_length(x) != pol_length(y) ||
valuation(x) != valuation(y) || scale(x) != scale(y)
return false
Expand Down
1 change: 1 addition & 0 deletions src/generic/PuiseuxSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ function ==(a::PuiseuxSeriesElem{T}, b::PuiseuxSeriesElem{T}) where T <: RingEle
end

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

Expand Down
2 changes: 1 addition & 1 deletion test/algorithms/GenericFunctions-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function ==(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
end

function isequal(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
check_parent(f, g)
parent(f) == parent(g) || return false
return isequal(f.c, g.c)
end

Expand Down

0 comments on commit 0a069dc

Please sign in to comment.