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
29 changes: 26 additions & 3 deletions src/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,40 @@
#
###############################################################################

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

# the following helper enables things like `ideal(R, [])` or `ideal(R, [1])`
# the type check ensures we don't run into an infinite recursion
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])

Check warning on line 17 in src/Ideal.jl

View check run for this annotation

Codecov / codecov/patch

src/Ideal.jl#L15-L17

Added lines #L15 - L17 were not covered by tests
end

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

Check warning on line 21 in src/Ideal.jl

View check run for this annotation

Codecov / codecov/patch

src/Ideal.jl#L20-L21

Added lines #L20 - L21 were not covered by tests
end

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

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

Check warning on line 29 in src/Ideal.jl

View check run for this annotation

Codecov / codecov/patch

src/Ideal.jl#L28-L29

Added lines #L28 - L29 were not covered by tests
end

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

Check warning on line 33 in src/Ideal.jl

View check run for this annotation

Codecov / codecov/patch

src/Ideal.jl#L32-L33

Added lines #L32 - L33 were not covered by tests
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)

Check warning on line 38 in src/Ideal.jl

View check run for this annotation

Codecov / codecov/patch

src/Ideal.jl#L36-L38

Added lines #L36 - L38 were not covered by tests
end

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

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