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

Fix sub and quo for modules #3237

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1189e1b
Remove :task from sub methods for modules.
HechtiDerLachs Jan 24, 2024
aab6439
Introduce new function submodule.
HechtiDerLachs Jan 24, 2024
668a853
Remove all deprecated uses of sub.
HechtiDerLachs Jan 24, 2024
e11109f
Export submodule.
HechtiDerLachs Jan 24, 2024
da8193a
Fix tests.
HechtiDerLachs Jan 24, 2024
585c592
Fix tests again.
HechtiDerLachs Jan 24, 2024
2b706ac
Register morphisms in general.
HechtiDerLachs Jan 24, 2024
085e7f4
Rebase network of natural maps on WeakKeyIdDicts.
HechtiDerLachs Jan 24, 2024
b7237f6
Clean up the morphisms network and dont store the actual morphisms.
HechtiDerLachs Jan 24, 2024
8d3cfea
Some small fix for Wolfram.
HechtiDerLachs Jan 24, 2024
8a737e3
Some fixes and marking the test as broken again.
HechtiDerLachs Jan 24, 2024
a0f6e4f
Fix documentation.
HechtiDerLachs Jan 24, 2024
ca22781
Another small fix for Wolfram.
HechtiDerLachs Jan 24, 2024
b08fb1d
Fix the fix.
HechtiDerLachs Jan 24, 2024
3b42596
Fix method selection.
HechtiDerLachs Jan 24, 2024
2317eb7
Introduce kw argument for caching morphisms.
HechtiDerLachs Jan 25, 2024
8a1b09f
Redirect previous usages.
HechtiDerLachs Jan 25, 2024
832bfae
Adjust tests.
HechtiDerLachs Jan 25, 2024
6b37340
Merge branch 'master' into fix_sub_and_quo_for_modules
HechtiDerLachs Jan 26, 2024
6936b15
submodule -> sub_object.
HechtiDerLachs Jan 31, 2024
7102f40
Fix docstrings and signatures for quo.
HechtiDerLachs Jan 31, 2024
2e1a6c3
Fix methods for quo.
HechtiDerLachs Jan 31, 2024
b17dcaf
Adjust documentation.
HechtiDerLachs Jan 31, 2024
4defc97
Merge branch 'fix_sub_and_quo_for_modules' of github.com:HechtiDerLac…
HechtiDerLachs Jan 31, 2024
8e592a1
Merge branch 'master' into fix_sub_and_quo_for_modules
HechtiDerLachs Jan 31, 2024
ba08f84
Fix up usages of quo.
HechtiDerLachs Jan 31, 2024
c6adba0
Export new functions.
HechtiDerLachs Jan 31, 2024
ed582e4
Some fixes.
HechtiDerLachs Jan 31, 2024
5817b87
Fix tests.
HechtiDerLachs Feb 1, 2024
db52db0
Fix tests.
HechtiDerLachs Feb 1, 2024
4e0437c
Fix tests.
HechtiDerLachs Feb 1, 2024
775e267
Fix tests.
HechtiDerLachs Feb 1, 2024
4844564
Fix tests.
HechtiDerLachs Feb 1, 2024
88fab65
Fix tests.
HechtiDerLachs Feb 1, 2024
c13caa3
Fix up the truncation.
HechtiDerLachs Feb 1, 2024
c988130
Merge branch 'master' into fix_sub_and_quo_for_modules
HechtiDerLachs Feb 2, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ direct_product(M::ModuleFP{T}...; task::Symbol = :prod) where T
## Truncation

```@docs
truncate(M::ModuleFP, g::FinGenAbGroupElem, task::Symbol = :with_morphism)
truncate(M::ModuleFP, g::GrpAbFinGenElem, task::Symbol=:with_morphism)

```

## Twists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ intersect(M::SubquoModule{T}, N::SubquoModule{T}) where T
## Submodules and Quotients

```@docs
sub(M::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}, task::Symbol = :with_morphism) where T
sub(M::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}) where T
```

```@docs
quo(M::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}, task::Symbol = :with_morphism) where T
quo(M::ModuleFP{T}, V::Vector{<:ModuleFPElem{T}}; cache_morphism::Bool=false) where T
```

## Homomorphisms From Subqotients
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/FreeModules-graded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ function hom(M::ModuleFP_dec, N::ModuleFP_dec)
psi = kDelta[2]*pro[1]
psi = hom(kDelta[1], H_s0_t0, [psi(g) for g = gens(kDelta[1])])

H = quo(sub(D, kDelta[1]), image(rho)[1])
H = quo_object(sub(D, kDelta[1]), image(rho)[1])
set_attribute!(H, :show => Hecke.show_hom, :hom => (M, N))

#x in ker delta: mH_s0_t0(pro[1](x)) should be a hom from M to N
Expand Down
36 changes: 25 additions & 11 deletions src/Modules/ModuleTypes.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import AbstractAlgebra.WeakKeyIdDict

@doc raw"""
ModuleFP{T}

Expand Down Expand Up @@ -74,8 +76,20 @@ option is set in suitable functions.
S::Vector{Symbol}
d::Union{Vector{FinGenAbGroupElem}, Nothing}

incoming_morphisms::Vector{<:ModuleFPHom}
outgoing_morphisms::Vector{<:ModuleFPHom}
# We register the incoming and outgoing natural morphisms.
# This must be done in a way that objects can be collected by the
# garbage collector. In particular, we can not store the actual
# map as the value for a specific key (domain or codomain depending
# on whether the map is incoming or outgoing), because then the
# value has a reference to the key and thus the pair will never be
# deleted.
#
# Instead, we store a sparse matrix which allows us to reconstruct
# the map and potentially a change of rings. This allows us to
# reconstruct the map on request (which should be of relatively
# low cost).
incoming::WeakKeyIdDict{<:ModuleFP, <:Tuple{<:SMat, <:Any}}
outgoing::WeakKeyIdDict{<:ModuleFP, <:Tuple{<:SMat, <:Any}}

function FreeMod{T}(n::Int,R::Ring,S::Vector{Symbol}) where T <: RingElem
r = new{elem_type(R)}()
Expand All @@ -84,9 +98,8 @@ option is set in suitable functions.
r.S = S
r.d = nothing

r.incoming_morphisms = Vector{ModuleFPHom}()
r.outgoing_morphisms = Vector{ModuleFPHom}()

r.incoming = WeakKeyIdDict{ModuleFP, Tuple{SMat, Any}}()
r.outgoing = WeakKeyIdDict{ModuleFP, Tuple{SMat, Any}}()
return r
end
end
Expand Down Expand Up @@ -232,17 +245,18 @@ option is set in suitable functions.

groebner_basis::Dict{ModuleOrdering, ModuleGens{T}}

incoming_morphisms::Vector{<:ModuleFPHom}
outgoing_morphisms::Vector{<:ModuleFPHom} # TODO is it possible to make ModuleFPHom to SubQuoHom?
incoming::WeakKeyIdDict{<:ModuleFP, <:Tuple{<:SMat, <:Any}}
outgoing::WeakKeyIdDict{<:ModuleFP, <:Tuple{<:SMat, <:Any}}

function SubquoModule{R}(F::FreeMod{R}) where {R}
# this does not construct a valid subquotient
r = new{R}()
r.F = F

r.groebner_basis = Dict()
r.incoming_morphisms = Vector{ModuleFPHom}()
r.outgoing_morphisms = Vector{ModuleFPHom}()

r.incoming = WeakKeyIdDict{ModuleFP, Tuple{SMat, Any}}()
r.outgoing = WeakKeyIdDict{ModuleFP, Tuple{SMat, Any}}()

return r
end
Expand Down Expand Up @@ -562,7 +576,7 @@ When computed, the corresponding matrix (via `matrix()`) and inverse isomorphism
end
function pr_func(x)
@assert parent(x) === G
c = coordinates(repres(x), sub(G, a, :module))
c = coordinates(repres(x), sub_object(G, a))
return FreeModElem(c, F)
end
r.header = MapHeader{typeof(F), typeof(G)}(F, G, im_func, pr_func)
Expand Down Expand Up @@ -591,7 +605,7 @@ When computed, the corresponding matrix (via `matrix()`) and inverse isomorphism
end
function pr_func(x)
@assert parent(x) === G
c = coordinates(repres(x), sub(G, a, :module))
c = coordinates(repres(x), sub_object(G, a))
cc = map_entries(x->preimage(h, x), c)
return FreeModElem(cc, F)
end
Expand Down
36 changes: 24 additions & 12 deletions src/Modules/ModulesGraded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2601,21 +2601,17 @@ end
#############truncation#############

@doc raw"""
truncate(M::ModuleFP, g::FinGenAbGroupElem, task::Symbol = :with_morphism)
truncate(I::ModuleFP, g::GrpAbFinGenElem, task::Symbol=:with_morphism)

Given a finitely presented graded module `M` over a $\mathbb Z$-graded multivariate
polynomial ring with positive weights, return the truncation of `M` at degree `g`.

Put more precisely, return the truncation as an object of type `SubquoModule`.

Additionally, if `N` denotes this object,

- return the inclusion map `N` $\to$ `M` if `task = :with_morphism` (default),
- return and cache the inclusion map `N` $\to$ `M` if `task = :cache_morphism`,
- do none of the above if `task = :none`.

If `task = :only_morphism`, return only the inclusion map.

truncate(M::ModuleFP, d::Int, task::Symbol = :with_morphism)

Given a module `M` as above, and given an integer `d`, convert `d` into an element `g`
Expand Down Expand Up @@ -2655,11 +2651,11 @@ by submodule of F generated by
3 -> z^5*e[1]
```
"""
function truncate(I::ModuleFP, g::FinGenAbGroupElem, task::Symbol = :with_morphism)
function truncate(I::ModuleFP, g::GrpAbFinGenElem, task::Symbol=:with_morphism)
return truncate(I, Int(g[1]), task)
end

function truncate(I::ModuleFP, d::Int, task::Symbol = :with_morphism)
function truncate(I::ModuleFP, d::Int, task::Symbol=:with_morphism)
@req I isa FreeMod || I isa SubquoModule "Not implemented for the given type"
R = base_ring(I)
@req coefficient_ring(R) isa AbstractAlgebra.Field "The coefficient ring must be a field"
Expand All @@ -2668,11 +2664,11 @@ function truncate(I::ModuleFP, d::Int, task::Symbol = :with_morphism)
W = [Int(W[i][1]) for i = 1:ngens(R)]
@req minimum(W) > 0 "The weights must be positive"
if is_zero(I)
return I
return _return_wrt_to_task((I, identity_map(I)), task)
end
dmin = minimum(degree(Int, x) for x in gens(I))
if d <= dmin
return I
return _return_wrt_to_task((I, identity_map(I)), task)
end
V = sort(gens(I), lt = (a, b) -> degree(Int, a) <= degree(Int, b))
RES = elem_type(I)[]
Expand All @@ -2689,8 +2685,24 @@ function truncate(I::ModuleFP, d::Int, task::Symbol = :with_morphism)
push!(RES, V[i])
end
end
return sub(I, RES, task)
return _return_wrt_to_task(sub(I, RES), task)
end

function _return_wrt_task(result, task)
if task == :with_morphism
return result
elseif task == :cache_morphism
register_morphism!(result[2])
return result[2]
elseif task == :only_morphism
return result[2]
elseif task == :none
return result[1]
else
error("task not recognized")
end
end



##################regularity#######################
Expand Down Expand Up @@ -2829,7 +2841,7 @@ function quotient_ring_as_module(I::MPolyIdeal)
R = base_ring(I)
F = is_graded(R) ? graded_free_module(R, 1) : free_module(R, 1)
e1 = F[1]
return quo(F, [x * e1 for x = gens(I)], :module)
return quo_object(F, [x * e1 for x = gens(I)])
end

#####ideals as modules#####
Expand Down Expand Up @@ -2873,7 +2885,7 @@ function ideal_as_module(I::MPolyIdeal)
R = base_ring(I)
F = is_graded(R) ? graded_free_module(R, 1) : free_module(R, 1)
e1 = F[1]
return sub(F, [x * e1 for x = gens(I)], :module)
return sub_object(F, [x * e1 for x = gens(I)])
end


Expand Down
4 changes: 2 additions & 2 deletions src/Modules/UngradedModules/DirectSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ Additionally, return
"""
function direct_product(M::ModuleFP{T}...; task::Symbol = :prod) where T
F, pro, mF = direct_product([ambient_free_module(x) for x = M]..., task = :both)
s, emb_sF = sub(F, vcat([elem_type(F)[mF[i](y) for y = ambient_representatives_generators(M[i])] for i=1:length(M)]...), :both)
s, emb_sF = sub(F, vcat([elem_type(F)[mF[i](y) for y = ambient_representatives_generators(M[i])] for i=1:length(M)]...))
q::Vector{elem_type(F)} = vcat([elem_type(F)[mF[i](y) for y = rels(M[i])] for i=1:length(M)]...)
pro_quo = nothing
if length(q) != 0
s, pro_quo = quo(s, q, :both)
s, pro_quo = quo(s, q)
end
set_attribute!(s, :show => Hecke.show_direct_product, :direct_product => M)
projection_dictionary = IdDict{Int,ModuleFPHom}()
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/UngradedModules/FreeModuleHom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ function kernel(h::FreeModuleHom) #ONLY for free modules...
G = domain(h)
R = base_ring(G)
if ngens(G) == 0
s = sub(G, gens(G), :module)
s = sub_object(G, gens(G))
help = hom(s, G, gens(G), check=false)
help.generators_map_to_generators = true
return s, help
Expand All @@ -480,10 +480,10 @@ function kernel(h::FreeModuleHom) #ONLY for free modules...
k = syzygy_module(b)
if isa(codomain(h), SubquoModule)
s = collect(k.sub.gens)
k = sub(G, [FreeModElem(x.coords[R,1:dim(G)], G) for x = s], :module)
k = sub_object(G, [FreeModElem(x.coords[R,1:dim(G)], G) for x = s])
else
#the syzygie_module creates a new free module to work in
k = sub(G, [FreeModElem(x.coords, G) for x = collect(k.sub.gens)], :module)
k = sub_object(G, [FreeModElem(x.coords, G) for x = collect(k.sub.gens)])
end
@assert k.F === G
c = collect(k.sub.gens)
Expand Down Expand Up @@ -560,7 +560,7 @@ Homogeneous module homomorphism)
"""
function image(h::FreeModuleHom)
si = filter(!iszero, images_of_generators(h))
s = sub(codomain(h), si, :module)
s = sub_object(codomain(h), si)
phi = hom(s, codomain(h), si, check=false)
return s, phi
end
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/UngradedModules/Hom_and_ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ julia> F = FreeMod(R, 2);

julia> V = [x*F[1], y^2*F[2]];

julia> M = quo(F, V)[1]
julia> M = quo_object(F, V)
Subquotient of Submodule with 2 generators
1 -> e[1]
2 -> e[2]
Expand Down Expand Up @@ -78,7 +78,7 @@ function hom(M::ModuleFP, N::ModuleFP, algorithm::Symbol=:maps)
kDelta = kernel(delta)

projected_kernel::Vector{elem_type(H_s0_t0)} = filter(v -> !is_zero(v), FreeModElem[pro[1](repres(AB)) for AB in gens(kDelta[1])])
H = quo(sub(H_s0_t0, projected_kernel, :module), image(rho_prime)[1], :module)
H = quo_object(sub_object(H_s0_t0, projected_kernel), image(rho_prime)[1])

H_simplified, s_inj, s_proj = simplify_light(H)

Expand Down Expand Up @@ -115,7 +115,7 @@ julia> F = FreeMod(R, 2);

julia> V = [x*F[1], y^2*F[2]];

julia> M = quo(F, V)[1]
julia> M = quo_object(F, V)
Subquotient of Submodule with 2 generators
1 -> e[1]
2 -> e[2]
Expand Down Expand Up @@ -181,7 +181,7 @@ julia> F = FreeMod(R, 2);

julia> V = [x*F[1], y^2*F[2]];

julia> M = quo(F, V)[1]
julia> M = quo_object(F, V)
Subquotient of Submodule with 2 generators
1 -> e[1]
2 -> e[2]
Expand Down
6 changes: 3 additions & 3 deletions src/Modules/UngradedModules/HomologicalAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ function homology(C::Hecke.ComplexOfMorphisms{<:ModuleFP}, i::Int)
return cokernel(f)
elseif i in chain_range
if Hecke.is_chain_complex(C)
return quo(kernel(map(C,i))[1], image(map(C,i+1))[1], :module)
return quo_object(kernel(map(C,i))[1], image(map(C,i+1))[1])
else
return quo(kernel(map(C,i))[1], image(map(C,i-1))[1], :module)
return quo_object(kernel(map(C,i))[1], image(map(C,i-1))[1])
end
else
return FreeMod(base_ring(obj(C,first(chain_range))),0)
Expand All @@ -549,7 +549,7 @@ julia> F = FreeMod(R, 1);

julia> V = [x*F[1], y*F[1]];

julia> M = quo(F, V)[1]
julia> M = quo_object(F, V)
Subquotient of Submodule with 1 generator
1 -> e[1]
by Submodule with 2 generators
Expand Down
Loading
Loading