From 260d48744ff55c61803401cdd1e5ab24a935f4c5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 9 Oct 2024 22:55:55 +0200 Subject: [PATCH] Strict parent checks in == methods --- src/AbsSeries.jl | 3 +-- src/Fraction.jl | 3 +-- src/Matrix.jl | 3 +-- src/NCPoly.jl | 12 +++++------- src/Poly.jl | 13 ++++++------- src/RelSeries.jl | 3 +-- src/Residue.jl | 3 +-- src/ResidueField.jl | 3 +-- src/generic/FreeAssociativeAlgebra.jl | 3 +-- src/generic/LaurentMPoly.jl | 2 +- src/generic/LaurentSeries.jl | 3 +-- src/generic/MPoly.jl | 3 +-- src/generic/PuiseuxSeries.jl | 3 +-- src/generic/TotalFraction.jl | 3 +-- 14 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/AbsSeries.jl b/src/AbsSeries.jl index a6eb4ace5f..cfd27ec9d0 100644 --- a/src/AbsSeries.jl +++ b/src/AbsSeries.jl @@ -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)) diff --git a/src/Fraction.jl b/src/Fraction.jl index 05e5a41f5d..8fe08fbc65 100644 --- a/src/Fraction.jl +++ b/src/Fraction.jl @@ -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)) || diff --git a/src/Matrix.jl b/src/Matrix.jl index c60217cfe9..2565f82b8a 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -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] diff --git a/src/NCPoly.jl b/src/NCPoly.jl index e27c49c396..91ca1eb074 100644 --- a/src/NCPoly.jl +++ b/src/NCPoly.jl @@ -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 diff --git a/src/Poly.jl b/src/Poly.jl index 2bbaf01c1a..e8925a322b 100644 --- a/src/Poly.jl +++ b/src/Poly.jl @@ -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 diff --git a/src/RelSeries.jl b/src/RelSeries.jl index ca6d792d58..dfc3eb8a76 100644 --- a/src/RelSeries.jl +++ b/src/RelSeries.jl @@ -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) diff --git a/src/Residue.jl b/src/Residue.jl index 89126cb566..0fa8b3dbe8 100644 --- a/src/Residue.jl +++ b/src/Residue.jl @@ -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 diff --git a/src/ResidueField.jl b/src/ResidueField.jl index 0bea998023..c98205e089 100644 --- a/src/ResidueField.jl +++ b/src/ResidueField.jl @@ -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 diff --git a/src/generic/FreeAssociativeAlgebra.jl b/src/generic/FreeAssociativeAlgebra.jl index b82756a4a7..13c686b5f3 100644 --- a/src/generic/FreeAssociativeAlgebra.jl +++ b/src/generic/FreeAssociativeAlgebra.jl @@ -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) diff --git a/src/generic/LaurentMPoly.jl b/src/generic/LaurentMPoly.jl index 2c00ddc846..8547d69dbc 100644 --- a/src/generic/LaurentMPoly.jl +++ b/src/generic/LaurentMPoly.jl @@ -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 diff --git a/src/generic/LaurentSeries.jl b/src/generic/LaurentSeries.jl index 9f5bb1e560..d0d1c29394 100644 --- a/src/generic/LaurentSeries.jl +++ b/src/generic/LaurentSeries.jl @@ -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) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index 96861478bd..216a220984 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -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 diff --git a/src/generic/PuiseuxSeries.jl b/src/generic/PuiseuxSeries.jl index 0dcf434951..46ac6cf4b1 100644 --- a/src/generic/PuiseuxSeries.jl +++ b/src/generic/PuiseuxSeries.jl @@ -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) diff --git a/src/generic/TotalFraction.jl b/src/generic/TotalFraction.jl index 0a957dfee3..41f899ffa5 100644 --- a/src/generic/TotalFraction.jl +++ b/src/generic/TotalFraction.jl @@ -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)) ||