Skip to content

Commit

Permalink
Strict parent checks in == methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Oct 11, 2024
1 parent fd7aa4e commit 260d487
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 37 deletions.
3 changes: 1 addition & 2 deletions src/AbsSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(x::AbsPowerSeriesRingElem{T}, y::AbsPowerSeriesRingElem{T}) where T <: RingElement
b = check_parent(x, y, false)
!b && return false
check_parent(x, y)

prec = min(precision(x), precision(y))
m1 = min(length(x), length(y))
Expand Down
3 changes: 1 addition & 2 deletions src/Fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(x::FracElem{T}, y::FracElem{T}) where {T <: RingElem}
b = check_parent(x, y, false)
!b && return false
check_parent(x, y)

return (denominator(x, false) == denominator(y, false) &&
numerator(x, false) == numerator(y, false)) ||
Expand Down
3 changes: 1 addition & 2 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,7 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(x::MatrixElem{T}, y::MatrixElem{T}) where {T <: NCRingElement}
b = check_parent(x, y, false)
!b && return false
check_parent(x, y)
for i = 1:nrows(x)
for j = 1:ncols(x)
if x[i, j] != y[i, j]
Expand Down
12 changes: 5 additions & 7 deletions src/NCPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,13 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(x::NCPolyRingElem{T}, y::NCPolyRingElem{T}) where T <: NCRingElem
b = check_parent(x, y, false)
!b && return false
check_parent(x, y)
if length(x) != length(y)
return false
else
for i = 1:length(x)
if coeff(x, i - 1) != coeff(y, i - 1)
return false
end
end
for i = 1:length(x)
if coeff(x, i - 1) != coeff(y, i - 1)
return false
end
end
return true
Expand Down
13 changes: 6 additions & 7 deletions src/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -839,15 +839,14 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(x::PolyRingElem{T}, y::PolyRingElem{T}) where T <: RingElement
b = check_parent(x, y, false)
!b && return false
check_parent(x, y)

if length(x) != length(y)
return false
else
for i = 1:length(x)
if coeff(x, i - 1) != coeff(y, i - 1)
return false
end
end
for i = 1:length(x)
if coeff(x, i - 1) != coeff(y, i - 1)
return false
end
end
return true
Expand Down
3 changes: 1 addition & 2 deletions src/RelSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,7 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(x::RelPowerSeriesRingElem{T}, y::RelPowerSeriesRingElem{T}) where T <: RingElement
b = check_parent(x, y, false)
!b && return false
check_parent(x, y)

xval = valuation(x)
xprec = precision(x)
Expand Down
3 changes: 1 addition & 2 deletions src/Residue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(a::ResElem{T}, b::ResElem{T}) where {T <: RingElement}
fl = check_parent(a, b, false)
!fl && return false
check_parent(a, b)
return data(a) == data(b)
end

Expand Down
3 changes: 1 addition & 2 deletions src/ResidueField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(a::ResFieldElem{T}, b::ResFieldElem{T}) where {T <: RingElement}
fl = check_parent(a, b, false)
!fl && return false
check_parent(a, b)
return data(a) == data(b)
end

Expand Down
3 changes: 1 addition & 2 deletions src/generic/FreeAssociativeAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ end
###############################################################################

function ==(a::FreeAssociativeAlgebraElem{T}, b::FreeAssociativeAlgebraElem{T}) where T
fl = check_parent(a, b, false)
!fl && return false
check_parent(a, b)
return a.length == b.length &&
view(a.exps, 1:a.length) == view(b.exps, 1:b.length) &&
view(a.coeffs, 1:a.length) == view(b.coeffs, 1:b.length)
Expand Down
2 changes: 1 addition & 1 deletion src/generic/LaurentMPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ end
###############################################################################

function ==(a::LaurentMPolyWrap, b::LaurentMPolyWrap)
check_parent(a, b, false) || return false
check_parent(a, b)
if a.mindegs == b.mindegs
return a.mpoly == b.mpoly
end
Expand Down
3 changes: 1 addition & 2 deletions src/generic/LaurentSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,7 @@ that power series to different precisions may still be arithmetically
equal to the minimum of the two precisions.
"""
function ==(x::LaurentSeriesElem{T}, y::LaurentSeriesElem{T}) where {T <: RingElement}
b = check_parent(x, y, false)
!b && return false
check_parent(x, y)
xval = valuation(x)
xprec = precision(x)
yval = valuation(y)
Expand Down
3 changes: 1 addition & 2 deletions src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2022,8 +2022,7 @@ end
###############################################################################

function ==(a::MPoly{T}, b::MPoly{T}) where {T <: RingElement}
fl = check_parent(a, b, false)
!fl && return false
check_parent(a, b)
if a.length != b.length
return false
end
Expand Down
3 changes: 1 addition & 2 deletions src/generic/PuiseuxSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ end
###############################################################################

function ==(a::PuiseuxSeriesElem{T}, b::PuiseuxSeriesElem{T}) where T <: RingElement
fl = check_parent(a, b, false)
!fl && return false
check_parent(a, b)
s = gcd(a.scale, b.scale)
zscale = div(a.scale*b.scale, s)
ainf = div(a.scale, s)
Expand Down
3 changes: 1 addition & 2 deletions src/generic/TotalFraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ end
###############################################################################

function ==(x::TotFrac{T}, y::TotFrac{T}) where {T <: RingElem}
b = check_parent(x, y, false)
!b && return false
check_parent(x, y)

return (denominator(x, false) == denominator(y, false) &&
numerator(x, false) == numerator(y, false)) ||
Expand Down

0 comments on commit 260d487

Please sign in to comment.