Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend ideal interface #1731

Merged
merged 10 commits into from
Aug 18, 2024
27 changes: 24 additions & 3 deletions src/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,38 @@
#
###############################################################################

function ideal
# We assume that the function
# ideal(R::T, xs::Vector{U})
# with U === elem_type(T) is implemented by anyone implementing ideals
# for AbstractAlgebra rings.
# The functions in this file extend the interface for `ideal`.
fingolfin marked this conversation as resolved.
Show resolved Hide resolved

function ideal(R::Ring, xs::AbstractVector{T}) where T<:RingElement
fingolfin marked this conversation as resolved.
Show resolved Hide resolved
xs isa Vector{elem_type(R)} && error("ideals unsupported for ring $R")
return ideal(R, elem_type(R)[R(x) for x in xs])
end

function *(x::RingElement, R::Ring)
return ideal(R, x)
function ideal(R::Ring, x::RingElement)
return ideal(R, elem_type(R)[R(x)])
end

function *(R::Ring, x::RingElement)
return ideal(R, x)
end

function *(x::RingElement, R::Ring)
return ideal(R, x)
end

function ideal(x::RingElement)
return ideal(parent(x), x)
end

function ideal(xs::AbstractVector{T}) where T<:RingElement
!is_empty(xs) || throw(ArgumentError("Empty collection, cannot determine parent ring. Try ideal(ring, xs) instead of ideal(xs)"))
return ideal(parent(xs[1]), xs)
end

iszero(I::Ideal) = all(iszero, gens(I))

base_ring_type(::Type{<:IdealSet{T}}) where T <: RingElement = parent_type(T)