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
6 changes: 6 additions & 0 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ function check_parent(a, b, throw::Bool = true)
return flag
end

function check_base_ring(a, b, throw::Bool = true)
flag = base_ring(a) === base_ring(b)
flag || !throw || error("base rings do not match")
return flag
end

include("algorithms/LaurentPoly.jl")
include("algorithms/FinField.jl")
include("algorithms/GenericFunctions.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/generic/FactoredFraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end
#
###############################################################################

function Base.deepcopy_internal(a::FactoredFracFieldElem{T}, dict::IdDict) where T <: RingElement
function deepcopy_internal(a::FactoredFracFieldElem{T}, dict::IdDict) where T <: RingElement
return FactoredFracFieldElem{T}(deepcopy_internal(a.unit, dict),
deepcopy_internal(a.terms, dict),
a.parent)
Expand Down
2 changes: 1 addition & 1 deletion src/generic/FreeAssociativeAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end
#
###############################################################################

function Base.deepcopy_internal(a::FreeAssociativeAlgebraElem{T}, dict::IdDict) where T <: RingElement
function deepcopy_internal(a::FreeAssociativeAlgebraElem{T}, dict::IdDict) where T <: RingElement
return FreeAssociativeAlgebraElem{T}(
a.parent,
deepcopy_internal(a.coeffs, dict),
Expand Down
33 changes: 19 additions & 14 deletions src/generic/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Return a list of generators of the ideal `I` in reduced form and canonicalised.
"""
gens(I::Ideal{T}) where T <: RingElement = I.gens

function deepcopy_internal(I::Ideal, dict::IdDict)
elms = [deepcopy_internal(x, dict) for x in I.gens]
return Ideal(base_ring(I), elms)
end

###############################################################################
#
# Heap and nodes
Expand Down Expand Up @@ -2099,6 +2104,7 @@ end
###############################################################################

function ==(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
check_base_ring(I, J)
return gens(I) == gens(J)
end

Expand All @@ -2118,6 +2124,7 @@ end
Return `true` if the ideal `I` is a subset of the ideal `J`.
"""
function Base.issubset(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
check_base_ring(I, J)
return all(in(J), gens(I))
end

Expand All @@ -2133,32 +2140,27 @@ end
Return the intersection of the ideals `I` and `J`.
"""
function intersect(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
check_base_ring(I, J)
R = base_ring(I)
G1 = gens(I)
G2 = gens(J)
if isempty(G1)
return deepcopy(I)
end
if isempty(G2)
return deepcopy(J)
end
return Ideal(R, lcm(G1[1], G2[1]))
isempty(G1) && return deepcopy(I)
isempty(G2) && return deepcopy(J)
return Ideal(R, lcm(only(G1), only(G2)))
end

function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: FieldElement, T <: AbstractAlgebra.PolyRingElem{U}}
check_base_ring(I, J)
R = base_ring(I)
G1 = gens(I)
G2 = gens(J)
if isempty(G1)
return deepcopy(I)
end
if isempty(G2)
return deepcopy(J)
end
return Ideal(R, lcm(G1[1], G2[1]))
isempty(G1) && return deepcopy(I)
isempty(G2) && return deepcopy(J)
return Ideal(R, lcm(only(G1), only(G2)))
end

function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: AbstractAlgebra.PolyRingElem{U}}
check_base_ring(I, J)
if is_subset(J, I)
return J
elseif is_subset(I, J)
Expand All @@ -2182,6 +2184,7 @@ function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: Abstr
end

function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: AbstractAlgebra.MPolyRingElem{U}}
check_base_ring(I, J)
if is_subset(J, I)
return J
elseif is_subset(I, J)
Expand Down Expand Up @@ -2211,13 +2214,15 @@ end
###############################################################################

function +(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
check_base_ring(I, J)
R = base_ring(I)
G1 = gens(I)
G2 = gens(J)
return Ideal(R, vcat(G1, G2))
end

function *(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
check_base_ring(I, J)
R = base_ring(I)
G1 = gens(I)
G2 = gens(J)
Expand Down
2 changes: 1 addition & 1 deletion src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ isone(x::MPoly) = is_trivial(parent(x)) || (x.length == 1 && monomial_iszero(x.e

is_constant(x::MPoly) = x.length == 0 || (x.length == 1 && monomial_iszero(x.exps, 1, size(x.exps, 1)))

function Base.deepcopy_internal(a::MPoly{T}, dict::IdDict) where {T <: RingElement}
function deepcopy_internal(a::MPoly{T}, dict::IdDict) where {T <: RingElement}
Re = deepcopy_internal(a.exps, dict)
Rc = Vector{T}(undef, a.length)
for i = 1:a.length
Expand Down
2 changes: 1 addition & 1 deletion src/generic/SparsePoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ base_ring(R::SparsePolyRing{T}) where {T <: RingElement} = R.base_ring::parent_t

parent(a::SparsePoly) = a.parent

function Base.deepcopy_internal(a::SparsePoly{T}, dict::IdDict) where {T <: RingElement}
function deepcopy_internal(a::SparsePoly{T}, dict::IdDict) where {T <: RingElement}
Re = Base.deepcopy_internal(a.exps, dict)
Rc = Vector{T}(undef, a.length)
for i = 1:a.length
Expand Down
1 change: 1 addition & 0 deletions src/generic/imports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import ..AbstractAlgebra: base_ring_type
import ..AbstractAlgebra: canonical_unit
import ..AbstractAlgebra: change_base_ring
import ..AbstractAlgebra: characteristic
import ..AbstractAlgebra: check_base_ring
import ..AbstractAlgebra: check_parent
import ..AbstractAlgebra: codomain
import ..AbstractAlgebra: coeff
Expand Down
Loading