Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/algorithms/GenericFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 n == 1
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/generic/FactoredFraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/generic/LaurentPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions test/algorithms/GenericFunctions-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,32 +145,32 @@ 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

# 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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading