Skip to content

Commit db82bbc

Browse files
committed
Replace some custom checks by check_parent
1 parent a30f7c4 commit db82bbc

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/algorithms/GenericFunctions.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ end
113113
Return `mod(f^e, m)` but possibly computed more efficiently.
114114
"""
115115
function powermod(a::T, n::Integer, m::T) where T <: RingElem
116-
parent(a) == parent(m) || error("Incompatible parents")
116+
check_parent(a, m)
117117
if n > 1
118118
return internal_powermod(a, n, m)
119119
elseif n == 1
@@ -149,7 +149,7 @@ case `q` is set to the quotient, or `flag` is set to `false` and `q`
149149
is set to `zero(f)`.
150150
"""
151151
function divides(a::T, b::T) where T <: RingElem
152-
parent(a) == parent(b) || error("Incompatible parents")
152+
check_parent(a, b)
153153
if iszero(b)
154154
return iszero(a), b
155155
end
@@ -166,7 +166,7 @@ the cofactor after $f$ is divided by this power.
166166
See also [`valuation`](@ref), which only returns the valuation.
167167
"""
168168
function remove(a::T, b::T) where T <: Union{RingElem, Number}
169-
parent(a) == parent(b) || error("Incompatible parents")
169+
check_parent(a, b)
170170
if (iszero(b) || is_unit(b))
171171
throw(ArgumentError("Second argument must be a non-zero non-unit"))
172172
end
@@ -205,7 +205,7 @@ any other common divisor of $a$ and $b$ divides $g$.
205205
way that if the return is a unit, that unit should be one.
206206
"""
207207
function gcd(a::T, b::T) where T <: RingElem
208-
parent(a) == parent(b) || error("Incompatible parents")
208+
check_parent(a, b)
209209
while !iszero(b)
210210
(a, b) = (b, mod(a, b))
211211
end
@@ -287,7 +287,7 @@ Return a triple `d, s, t` such that $d = gcd(f, g)$ and $d = sf + tg$, with $s$
287287
loosely reduced modulo $g/d$ and $t$ loosely reduced modulo $f/d$.
288288
"""
289289
function gcdx(a::T, b::T) where T <: RingElem
290-
parent(a) == parent(b) || error("Incompatible parents")
290+
check_parent(a, b)
291291
R = parent(a)
292292
if iszero(a)
293293
if iszero(b)

src/generic/FactoredFraction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ function *(b::Integer, a::FactoredFracFieldElem{T}) where T <: RingElem
304304
end
305305

306306
function *(b::FactoredFracFieldElem{T}, c::FactoredFracFieldElem{T}) where T <: RingElement
307-
parent(b) == parent(c) || error("Incompatible rings")
307+
check_parent(b, c)
308308
input_is_good = _bases_are_coprime(b) && _bases_are_coprime(b)
309309
z = FactoredFracFieldElem{T}(b.unit*c.unit, FactoredFracTerm{T}[], parent(b))
310310
if iszero(z.unit)

src/generic/LaurentPoly.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function canonical_unit(p::LaurentPolyWrap)
237237
end
238238

239239
function gcd(p::LaurentPolyWrap{T}, q::LaurentPolyWrap{T}) where T
240-
parent(p) == parent(q) || error("Incompatible parents")
240+
check_parent(p, q)
241241
if iszero(p)
242242
return divexact(q, canonical_unit(q))
243243
elseif iszero(q)
@@ -249,7 +249,7 @@ function gcd(p::LaurentPolyWrap{T}, q::LaurentPolyWrap{T}) where T
249249
end
250250

251251
function gcdx(a::LaurentPolyWrap{T}, b::LaurentPolyWrap{T}) where T
252-
parent(a) == parent(b) || error("Incompatible parents")
252+
check_parent(a, b)
253253
R = parent(a)
254254
if iszero(a)
255255
if iszero(b)

test/algorithms/GenericFunctions-test.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,32 +145,32 @@ end
145145
# Binary operations
146146

147147
function +(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
148-
parent(f) != parent(g) && error("Incompatible rings")
148+
check_parent(f, g)
149149
R = parent(f)
150150
return R(f.c + g.c)
151151
end
152152

153153
function -(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
154-
parent(f) != parent(g) && error("Incompatible rings")
154+
check_parent(f, g)
155155
R = parent(f)
156156
return R(f.c - g.c)
157157
end
158158

159159
function *(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
160-
parent(f) != parent(g) && error("Incompatible rings")
160+
check_parent(f, g)
161161
R = parent(f)
162162
return R(f.c*g.c)
163163
end
164164

165165
# Comparison
166166

167167
function ==(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
168-
parent(f) != parent(g) && error("Incompatible rings")
168+
check_parent(f, g)
169169
return f.c == g.c
170170
end
171171

172172
function isequal(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
173-
parent(f) != parent(g) && error("Incompatible rings")
173+
check_parent(f, g)
174174
return isequal(f.c, g.c)
175175
end
176176

@@ -179,7 +179,7 @@ end
179179
# Exact division
180180

181181
function divexact(f::ConstPoly{T}, g::ConstPoly{T}; check::Bool = true) where T <: RingElement
182-
parent(f) != parent(g) && error("Incompatible rings")
182+
check_parent(f, g)
183183
R = parent(f)
184184
return R(divexact(f.c, g.c, check = check))
185185
end
@@ -271,7 +271,7 @@ end
271271
# Euclidean interface
272272

273273
function Base.divrem(a::ConstPoly{elem_type(ZZ)}, b::ConstPoly{elem_type(ZZ)})
274-
parent(a) != parent(b) && error("Incompatible rings")
274+
check_parent(a, b)
275275
q, r = AbstractAlgebra.divrem(a.c, b.c)
276276
return parent(a)(q), parent(a)(r)
277277
end

0 commit comments

Comments
 (0)