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

Sets poly ring caching to false for modules #3872

Merged
merged 7 commits into from
Jul 19, 2024
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
60 changes: 43 additions & 17 deletions src/Modules/hilbert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@


@doc raw"""
multi_hilbert_series(M::SubquoModule; parent::Union{Nothing,Ring} = nothing)
multi_hilbert_series(M::SubquoModule; parent::Ring)

Compute a pair of pairs `(N ,D), (H ,iso)` where `N` and `D` are the non-reduced numerator and denominator of the Hilbert
series of the subquotient `M`, and `H` is the SNF of the grading group together with the identifying isomorphism `iso`.
Expand Down Expand Up @@ -81,7 +81,11 @@

```
"""
function multi_hilbert_series(SubM::SubquoModule{T}; parent::Union{Nothing, Ring} = nothing, backend::Symbol = :Abbott) where T <: MPolyRingElem
function multi_hilbert_series(
SubM::SubquoModule{T};
parent::Ring = multi_hilbert_series_parent(base_ring(SubM)),
backend::Symbol = :Abbott
) where T <: MPolyRingElem
R = base_ring(SubM)
@req coefficient_ring(R) isa AbstractAlgebra.Field "The coefficient ring must be a field"
@req is_positively_graded(R) "ring must be positively graded"
Expand All @@ -99,32 +103,36 @@
V = [preimage(iso, x) for x in gens(G)]
isoinv = hom(G, H, V)
W = [isoinv(R.d[i]) for i = 1:ngens(R)]
S, _ = graded_polynomial_ring(coefficient_ring(R), symbols(R), W)
S, _ = graded_polynomial_ring(coefficient_ring(R), symbols(R), W; cached=false)

Check warning on line 106 in src/Modules/hilbert.jl

View check run for this annotation

Codecov / codecov/patch

src/Modules/hilbert.jl#L106

Added line #L106 was not covered by tests
map_into_S = hom(R, S, gens(S))
SubM2,_ = change_base_ring(map_into_S,SubM) # !!! BUG this seems to forget that things are graded BUG (issue #2657) !!!
(numer, denom), _ = hilbert_series(SubM2; parent=parent, backend=backend)
return (numer, denom), (H, iso)
end

# Now we may assume that the grading group is free Abelian.
m = ngens(G)
m = ngens(G)
n = ngens(R)
HSRing = _hilbert_series_ring(parent, m)
@req ngens(parent) >= m "Parent ring does not contain sufficiently many variables"
# Get the weights as Int values: W[k] contains the weight(s) of x[k]
W = [[ Int(R.d[i][j]) for j in 1:m] for i in 1:n]
denom = _hilbert_series_denominator(HSRing, W)
numer = HSNum_module(SubM, HSRing, backend)
denom = _hilbert_series_denominator(parent, W)
numer = HSNum_module(SubM, parent, backend)
return (numer, denom), (G, identity_map(G))
end

function multi_hilbert_series(F::FreeMod{T}; parent::Union{Nothing,Ring} = nothing, backend::Symbol = :Abbott) where T <: MPolyRingElem
function multi_hilbert_series(

Check warning on line 124 in src/Modules/hilbert.jl

View check run for this annotation

Codecov / codecov/patch

src/Modules/hilbert.jl#L124

Added line #L124 was not covered by tests
F::FreeMod{T};
parent::Ring = multi_hilbert_series_parent(base_ring(F)),
backend::Symbol = :Abbott
) where T <: MPolyRingElem
@req is_positively_graded(base_ring(F)) "ring must be positively graded"
return multi_hilbert_series(sub_object(F,gens(F)); parent=parent, backend=backend)
end


@doc raw"""
hilbert_series(M::SubquoModule; parent::Union{Nothing,Ring} = nothing)
hilbert_series(M::SubquoModule; parent::Ring)

Compute a pair `(N,D)` where `N` and `D` are the non-reduced numerator and denominator of the Hilbert
series of the subquotient `M`. If the kwarg `parent` is supplied `N` and `D` are computed in the ring `parent`.
Expand Down Expand Up @@ -160,19 +168,37 @@

```
"""
function hilbert_series(SubM::SubquoModule{T}; parent::Union{Nothing,Ring} = nothing, backend::Symbol = :Abbott) where T <: MPolyRingElem
function hilbert_series(
SubM::SubquoModule{T};
parent::Ring = hilbert_series_parent(base_ring(SubM)),
backend::Symbol = :Abbott
) where T <: MPolyRingElem
@req is_z_graded(base_ring(SubM)) "ring must be ZZ-graded; use `multi_hilbert_series` otherwise"
if parent === nothing
parent, _ = laurent_polynomial_ring(ZZ, :t)
end
HS, _ = multi_hilbert_series(SubM; parent=parent, backend=backend)
return HS
end

function hilbert_series(F::FreeMod{T}; parent::Union{Nothing,Ring} = nothing, backend::Symbol = :Abbott) where T <: MPolyRingElem
function hilbert_series(
F::FreeMod{T};
parent::Ring = hilbert_series_parent(base_ring(F)),
backend::Symbol = :Abbott
) where T <: MPolyRingElem
@req is_z_graded(base_ring(F)) "ring must be ZZ-graded; use `multi_hilbert_series` otherwise"
if parent === nothing
parent, _ = laurent_polynomial_ring(ZZ, :t)
end
return hilbert_series(sub_object(F,gens(F)); parent=parent, backend=backend)
end

function hilbert_series_parent(S::MPolyDecRing)
if !isdefined(S, :hilbert_series_parent)
S.hilbert_series_parent = laurent_polynomial_ring(ZZ, :t; cached=false)[1]
end
return S.hilbert_series_parent
end

function multi_hilbert_series_parent(S::MPolyDecRing)
if !isdefined(S, :multi_hilbert_series_parent)
G = grading_group(S)
m = ngens(G)
S.multi_hilbert_series_parent = laurent_polynomial_ring(ZZ, (isone(m) ? [:t] : [Symbol("t[$i]") for i in 1:m]); cached=false)[1]
end
return S.multi_hilbert_series_parent
end
3 changes: 3 additions & 0 deletions src/Rings/mpoly-graded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
D::FinGenAbGroup
d::Vector{FinGenAbGroupElem}
lt::Any
hilbert_series_parent::Generic.LaurentPolyWrapRing{ZZRingElem, ZZPolyRing}
multi_hilbert_series_parent::Generic.LaurentMPolyWrapRing{ZZRingElem, ZZMPolyRing}

function MPolyDecRing(R::S, d::Vector{FinGenAbGroupElem}) where {S}
@assert length(d) == ngens(R)
r = new{elem_type(base_ring(R)), S}()
Expand Down
12 changes: 12 additions & 0 deletions test/Modules/hilbert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@
num = numer
end

num,_ = hilbert_series(fr[fr_len]; parent=laurent_polynomial_ring(QQ, :T; cached=false)[1])
for i in fr_len:-1:1
phi = map(fr,i)
N = cokernel(phi)
numer,denom = hilbert_series(N; parent=parent(num))
numer_next,_ = hilbert_series(fr[i-1]; parent=parent(num))
dummy_num, _ = hilbert_series(N)
@test_throws ErrorException dummy_num - num
@test numer == numer_next- num
num = numer
end
end

Loading