Skip to content

Commit 3abc3d0

Browse files
authored
Merge pull request #2107 from Nemocas/mh/ideals
Add `is_subset` and membership test via `in` to `Generic.Ideal`; deprecate `contains`
2 parents cc4d115 + a5ceba2 commit 3abc3d0

File tree

4 files changed

+130
-74
lines changed

4 files changed

+130
-74
lines changed

docs/src/ideal.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ ideals.
116116
### Containment
117117

118118
```@docs
119-
contains(::Generic.Ideal{T}, ::Generic.Ideal{T}) where T <: RingElement
119+
is_subset(::Generic.Ideal{T}, ::Generic.Ideal{T}) where T <: RingElement
120120
```
121121

122122
```@docs
@@ -146,10 +146,10 @@ AbstractAlgebra.Generic.Ideal{AbstractAlgebra.Generic.Poly{BigInt}}(Univariate p
146146
julia> J = Generic.Ideal(R, W)
147147
AbstractAlgebra.Generic.Ideal{AbstractAlgebra.Generic.Poly{BigInt}}(Univariate polynomial ring in x over integers, AbstractAlgebra.Generic.Poly{BigInt}[282, 3*x + 255, x^2 + 107])
148148
149-
julia> contains(J, I)
149+
julia> is_subset(I, J)
150150
false
151151
152-
julia> contains(I, J)
152+
julia> is_subset(J, I)
153153
true
154154
155155
julia> intersect(I, J) == J

src/Deprecations.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ end
6262

6363
# deprecated in 0.45.0
6464
@deprecate test_iterate ConformanceTests.test_iterate
65+
66+
# deprecated in 0.45.2
67+
import Base: contains
68+
@deprecate contains(I::Ideal{T}, J::Ideal{T}) where {T <: RingElement} issubset(J, I)

src/generic/Ideal.jl

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,14 +2071,27 @@ end
20712071
###############################################################################
20722072

20732073
@doc raw"""
2074-
normal_form(p::U, I::Ideal{U}) where {T <: RingElement, U <: Union{AbstractAlgebra.PolyRingElem{T}, AbstractAlgebra.MPolyRingElem{T}}}
2074+
normal_form(p::U, I::Ideal{U}) where {U}
20752075
20762076
Return the normal form of the polynomial `p` with respect to the ideal `I`.
20772077
"""
2078-
function normal_form(p::U, I::Ideal{U}) where {T <: RingElement, U <: Union{AbstractAlgebra.PolyRingElem{T}, AbstractAlgebra.MPolyRingElem{T}}}
2078+
function normal_form(p::U, I::Ideal{U}) where {U}
2079+
is_zero(p) && return copy(p)
2080+
is_zero(I) && return copy(p)
20792081
return normal_form(p, gens(I))
20802082
end
20812083

2084+
function normal_form(p::U, I::Ideal{U}) where {U <: FieldElem}
2085+
iszero(I) && return copy(p)
2086+
return zero(p)
2087+
end
2088+
2089+
function normal_form(p::U, I::Ideal{U}) where {U <: Integer}
2090+
iszero(I) && return copy(p)
2091+
m = only(gens(I))
2092+
return rem(p, m, RoundDown)
2093+
end
2094+
20822095
###############################################################################
20832096
#
20842097
# Comparison
@@ -2095,31 +2108,17 @@ end
20952108
#
20962109
###############################################################################
20972110

2111+
function Base.in(v::T, I::Ideal{T}) where T <: RingElement
2112+
return is_zero(normal_form(v, I))
2113+
end
2114+
20982115
@doc raw"""
2099-
Base.contains(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
2116+
Base.issubset(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
21002117
2101-
Return `true` if the ideal `J` is contained in the ideal `I`.
2118+
Return `true` if the ideal `I` is a subset of the ideal `J`.
21022119
"""
2103-
function Base.contains(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
2104-
G1 = gens(J)
2105-
G2 = gens(I)
2106-
if isempty(G1)
2107-
return true
2108-
end
2109-
if isempty(G2)
2110-
return false
2111-
end
2112-
return divides(G1[1], G2[1])[1]
2113-
end
2114-
2115-
function Base.contains(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: Union{AbstractAlgebra.PolyRingElem{U}, AbstractAlgebra.MPolyRingElem{U}}}
2116-
G = gens(J)
2117-
for v in G
2118-
if !iszero(normal_form(v, I))
2119-
return false
2120-
end
2121-
end
2122-
return true
2120+
function Base.issubset(I::Ideal{T}, J::Ideal{T}) where T <: RingElement
2121+
return all(in(J), gens(I))
21232122
end
21242123

21252124
###############################################################################
@@ -2160,9 +2159,9 @@ function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: FieldElement, T <: Abst
21602159
end
21612160

21622161
function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: AbstractAlgebra.PolyRingElem{U}}
2163-
if contains(I, J)
2162+
if is_subset(J, I)
21642163
return J
2165-
elseif contains(J, I)
2164+
elseif is_subset(I, J)
21662165
return I
21672166
end
21682167
S = base_ring(I) # poly ring
@@ -2183,9 +2182,9 @@ function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: Abstr
21832182
end
21842183

21852184
function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: AbstractAlgebra.MPolyRingElem{U}}
2186-
if contains(I, J)
2185+
if is_subset(J, I)
21872186
return J
2188-
elseif contains(J, I)
2187+
elseif is_subset(I, J)
21892188
return I
21902189
end
21912190
S = base_ring(I) # poly ring

0 commit comments

Comments
 (0)