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

Adds free resolutions over quotient rings by using Singular.sres #4134

Merged
merged 17 commits into from
Sep 30, 2024
Merged
29 changes: 20 additions & 9 deletions src/Modules/UngradedModules/FreeResolutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ function _extend_free_resolution(cc::Hecke.ComplexOfMorphisms, idx::Int)
end

@doc raw"""
free_resolution(M::SubquoModule{<:MPolyRingElem};
ordering::ModuleOrdering = default_ordering(M),
length::Int = 0, algorithm::Symbol = :fres
)
free_resolution(M::SubquoModule{T};
length::Int=0,
algorithm::Symbol = T <:MPolyRingElem ? :fres : :sres) where {T <: Union{MPolyRingElem, MPolyQuoRingElem}}

Return a free resolution of `M`.

If `length != 0`, the free resolution is only computed up to the `length`-th free module.
Current options for `algorithm` are `:fres`, `:nres`, and `:mres`.
Current options for `algorithm` are `:fres`, `:nres`, and `:mres` for modules over
polynomial rings and `:sres` for modules over quotients of polynomial rings.

!!! note
The function first computes a presentation of `M`. It then successively computes
Expand All @@ -255,6 +255,10 @@ Current options for `algorithm` are `:fres`, `:nres`, and `:mres`.
[EMSS16](@cite). Typically, this is more efficient than the approaches above, but the
resulting resolution is far from being minimal.

!!! note
If `M` is a module over a quotient of a polynomial ring then the `length` keyword must
be set to a nonzero value.

# Examples
```jldoctest
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"])
Expand Down Expand Up @@ -392,16 +396,20 @@ julia> matrix(map(FM3, 1))

```

**Note:** Over rings other than polynomial rings, the method will default to a lazy,
**Note:** Over rings other than polynomial rings or quotients of polynomial rings, the method will default to a lazy,
iterative kernel computation.
"""
function free_resolution(M::SubquoModule{<:MPolyRingElem};
ordering::ModuleOrdering = default_ordering(M),
length::Int=0, algorithm::Symbol=:fres)
function free_resolution(M::SubquoModule{T};
length::Int=0,
algorithm::Symbol = T <:MPolyRingElem ? :fres : :sres) where {T <: Union{MPolyRingElem, MPolyQuoRingElem}}

coefficient_ring(base_ring(M)) isa AbstractAlgebra.Field ||
error("Must be defined over a field.")

if T <: MPolyQuoRingElem
!iszero(length) || error("Specify a length up to which a free resolution should be computed")
end

Comment on lines +409 to +412
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Singular's sres sets a default of nvars(basering) modules to be computed, if no length is specified. It might be better for compatibility to document this fallback instead of throwing an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking a look. Having this default nvars(basering) length is the same they had in Macaulay2, they told me that they removed this at some point for clarity for the users.

But if you prefer to have this default, I will of course make the appropriate changes.

cc_complete = false

#= Start with presentation =#
Expand Down Expand Up @@ -435,6 +443,9 @@ function free_resolution(M::SubquoModule{<:MPolyRingElem};
elseif algorithm == :nres
gbpres = singular_kernel_entry
res = Singular.nres(gbpres, length)
elseif algorithm == :sres && T <: MPolyQuoRingElem
gbpres = Singular.std(singular_kernel_entry)
res = Singular.sres(gbpres, length)
else
error("Unsupported algorithm $algorithm")
end
Expand Down
14 changes: 7 additions & 7 deletions src/Modules/UngradedModules/ModuleGens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,19 @@ Convert a Singular vector to a free module element.
"""
function (F::FreeMod)(s::Singular.svector)
pos = Int[]
values = []
Rx = base_ring(F)
R = base_ring(Rx)
for (i, e, c) = s
f = Base.findfirst(==(i), pos)
R = coefficient_ring(Rx)
values = elem_type(Rx)[]
for (i, e, c) in s
f = Base.findfirst(x->x==i, pos)
if f === nothing
push!(values, MPolyBuildCtx(base_ring(F)))
push!(values, zero(Rx))
Copy link
Collaborator

@HechtiDerLachs HechtiDerLachs Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these deliberately reverted because we do not have an MPolyBuildCtx over quotient rings? In that case, I suggest to refactor this part of the code via type dispatch. We talked about it during last week's workshop how to speed this up, eventually. Also, I think @Lax202 's work in progress on non-commutative groebner bases might touch this part again. So we should eventually decide how to split this up here.

Edit: This does not need to hold this PR back for now. But before anyone merges, we should open an issue to remind us to clean this bit up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up: I tried do speed up some of our computations yesterday and made a patch for this part here in #4147 . Would it be desirable to push it directly to this PR? If so, please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look and fixing this! Merging this in unison would be good for me.

f = length(values)
push!(pos, i)
end
push_term!(values[f], R(c), e)
values[f] += R(c)*prod(gens(Rx) .^ e)
end
pv = Tuple{Int, elem_type(Rx)}[(pos[i], base_ring(F)(finish(values[i]))) for i=1:length(pos)]
pv = [(pos[i], values[i]) for i=1:length(pos)]
return FreeModElem(sparse_row(base_ring(F), pv), F)
end

Expand Down
5 changes: 3 additions & 2 deletions src/Modules/UngradedModules/Presentation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ function prune_with_map(M::ModuleFP)
return N, b
end

function prune_with_map(M::ModuleFP{T}) where {T<:MPolyRingElem{<:FieldElem}} # The case that can be handled by Singular
function prune_with_map(M::ModuleFP{T}) where {T<:Union{MPolyRingElem, MPolyQuoRingElem}} # The case that can be handled by Singular

# Singular presentation
pm = presentation(M)
Expand Down Expand Up @@ -577,7 +577,8 @@ function prune_with_map(M::ModuleFP{T}) where {T<:MPolyRingElem{<:FieldElem}} #
end

function _presentation_minimal(SQ::ModuleFP{T};
minimal_kernel::Bool=true) where {T<:MPolyRingElem{<:FieldElem}}
minimal_kernel::Bool=true) where {T <: Union{MPolyRingElem, MPolyQuoRingElem}}
R = base_ring(SQ)

R = base_ring(SQ)

Expand Down
2 changes: 1 addition & 1 deletion test/Modules/MPolyQuo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ end
A2 = FreeMod(A, 2)
v = [x*A2[1] + y*A2[2], z*A2[1] + (x-1)*A2[2]]
M, _ = quo(A2, v)
p = free_resolution(M)
p = free_resolution(M, length = 11)
@test !iszero(p[10])
RafaelDavidMohr marked this conversation as resolved.
Show resolved Hide resolved
end

Expand Down
8 changes: 8 additions & 0 deletions test/Modules/UngradedModules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ end
@test relations(C) == [zero(F)]
@test domain(isom) == F
@test codomain(isom) == C

R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"]);
A, p = quo(R, ideal(R, x^5))
M1 = identity_matrix(A, 2)
M2 = A[-x-y 2*x^2+x; z^4 0; 0 z^4; 8*x^3*y - 4*x^3 - 4*x^2*y + 2*x^2 + 2*x*y - x - y x; x^4 0]
M = SubquoModule(M1, M2)
fr = free_resolution(M, length = 9)
@test all(iszero, homology(fr)[2:end])
end

@testset "Prune With Map" begin
Expand Down
Loading