diff --git a/src/algorithms/GenericFunctions.jl b/src/algorithms/GenericFunctions.jl index a852af807..0b35339f1 100644 --- a/src/algorithms/GenericFunctions.jl +++ b/src/algorithms/GenericFunctions.jl @@ -113,7 +113,7 @@ end Return `mod(f^e, m)` but possibly computed more efficiently. """ function powermod(a::T, n::Integer, m::T) where T <: RingElem - parent(a) == parent(m) || error("Incompatible parents") + check_parent(a, m) if n > 1 return internal_powermod(a, n, m) elseif isone(n) @@ -149,7 +149,7 @@ case `q` is set to the quotient, or `flag` is set to `false` and `q` is set to `zero(f)`. """ function divides(a::T, b::T) where T <: RingElem - parent(a) == parent(b) || error("Incompatible parents") + check_parent(a, b) if iszero(b) return iszero(a), b end @@ -166,7 +166,7 @@ the cofactor after $f$ is divided by this power. See also [`valuation`](@ref), which only returns the valuation. """ function remove(a::T, b::T) where T <: Union{RingElem, Number} - parent(a) == parent(b) || error("Incompatible parents") + check_parent(a, b) if (iszero(b) || is_unit(b)) throw(ArgumentError("Second argument must be a non-zero non-unit")) end @@ -205,7 +205,7 @@ any other common divisor of $a$ and $b$ divides $g$. way that if the return is a unit, that unit should be one. """ function gcd(a::T, b::T) where T <: RingElem - parent(a) == parent(b) || error("Incompatible parents") + check_parent(a, b) while !iszero(b) (a, b) = (b, mod(a, b)) end @@ -287,7 +287,7 @@ Return a triple `d, s, t` such that $d = gcd(f, g)$ and $d = sf + tg$, with $s$ loosely reduced modulo $g/d$ and $t$ loosely reduced modulo $f/d$. """ function gcdx(a::T, b::T) where T <: RingElem - parent(a) == parent(b) || error("Incompatible parents") + check_parent(a, b) R = parent(a) if iszero(a) if iszero(b) diff --git a/src/generic/FactoredFraction.jl b/src/generic/FactoredFraction.jl index eb31cba73..11c09ec9a 100644 --- a/src/generic/FactoredFraction.jl +++ b/src/generic/FactoredFraction.jl @@ -304,7 +304,7 @@ function *(b::Integer, a::FactoredFracFieldElem{T}) where T <: RingElem end function *(b::FactoredFracFieldElem{T}, c::FactoredFracFieldElem{T}) where T <: RingElement - parent(b) == parent(c) || error("Incompatible rings") + check_parent(b, c) input_is_good = _bases_are_coprime(b) && _bases_are_coprime(b) z = FactoredFracFieldElem{T}(b.unit*c.unit, FactoredFracTerm{T}[], parent(b)) if iszero(z.unit) diff --git a/src/generic/LaurentPoly.jl b/src/generic/LaurentPoly.jl index 7c94fc57b..b16c7a80d 100644 --- a/src/generic/LaurentPoly.jl +++ b/src/generic/LaurentPoly.jl @@ -237,7 +237,7 @@ function canonical_unit(p::LaurentPolyWrap) end function gcd(p::LaurentPolyWrap{T}, q::LaurentPolyWrap{T}) where T - parent(p) == parent(q) || error("Incompatible parents") + check_parent(p, q) if iszero(p) return divexact(q, canonical_unit(q)) elseif iszero(q) @@ -249,7 +249,7 @@ function gcd(p::LaurentPolyWrap{T}, q::LaurentPolyWrap{T}) where T end function gcdx(a::LaurentPolyWrap{T}, b::LaurentPolyWrap{T}) where T - parent(a) == parent(b) || error("Incompatible parents") + check_parent(a, b) R = parent(a) if iszero(a) if iszero(b) diff --git a/test/algorithms/GenericFunctions-test.jl b/test/algorithms/GenericFunctions-test.jl index be844b28b..6b4db98da 100644 --- a/test/algorithms/GenericFunctions-test.jl +++ b/test/algorithms/GenericFunctions-test.jl @@ -145,19 +145,19 @@ end # Binary operations function +(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement - parent(f) != parent(g) && error("Incompatible rings") + check_parent(f, g) R = parent(f) return R(f.c + g.c) end function -(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement - parent(f) != parent(g) && error("Incompatible rings") + check_parent(f, g) R = parent(f) return R(f.c - g.c) end function *(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement - parent(f) != parent(g) && error("Incompatible rings") + check_parent(f, g) R = parent(f) return R(f.c*g.c) end @@ -165,12 +165,12 @@ end # Comparison function ==(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement - parent(f) != parent(g) && error("Incompatible rings") + check_parent(f, g) return f.c == g.c end function isequal(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement - parent(f) != parent(g) && error("Incompatible rings") + check_parent(f, g) return isequal(f.c, g.c) end @@ -179,7 +179,7 @@ end # Exact division function divexact(f::ConstPoly{T}, g::ConstPoly{T}; check::Bool = true) where T <: RingElement - parent(f) != parent(g) && error("Incompatible rings") + check_parent(f, g) R = parent(f) return R(divexact(f.c, g.c, check = check)) end @@ -271,7 +271,7 @@ end # Euclidean interface function Base.divrem(a::ConstPoly{elem_type(ZZ)}, b::ConstPoly{elem_type(ZZ)}) - parent(a) != parent(b) && error("Incompatible rings") + check_parent(a, b) q, r = AbstractAlgebra.divrem(a.c, b.c) return parent(a)(q), parent(a)(r) end