Skip to content

Commit

Permalink
add most of the direct_sum new stuff (#1620)
Browse files Browse the repository at this point in the history
  • Loading branch information
fieker authored Feb 22, 2024
1 parent f90718f commit fc5b3c9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ export cached
export can_solve
export can_solve_with_solution
export can_solve_with_solution_and_kernel
export canonical_injection
export canonical_injections
export canonical_projection
export canonical_projections
export canonical_unit
export change_base_ring
export change_coefficient_ring
Expand Down Expand Up @@ -849,6 +853,7 @@ export hnf_minors_with_transform
export hnf_via_popov
export hnf_via_popov_with_transform
export hnf_with_transform
export hom
export hooklength
export ideal
export identity_map
Expand Down Expand Up @@ -1160,6 +1165,12 @@ function YoungTableau(part::Generic.Partition, fill::Vector{T}=collect(1:part.n)
Generic.YoungTableau(part, fill)
end

################################################################################
#
# generic stubs for sub, quo, ...
#
################################################################################

@doc raw"""
sub(m::Module{T}, subs::Vector{<:Generic.Submodule{T}}) where T <: RingElement
Expand All @@ -1175,6 +1186,14 @@ function sub(m::Module{T}, subs::Vector{<:Generic.Submodule{U}}) where {T <: Rin
Generic.sub(m, subs)
end

function canonical_injections(D)
return [canonical_injection(D, i) for i=1:_number_of_direct_product_factors(D)]
end

function canonical_projections(D)
return [canonical_projections(D, i) for i=1:_number_of_direct_product_factors(D)]
end

export Generic

###############################################################################
Expand Down
29 changes: 29 additions & 0 deletions src/fundamental_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,32 @@ function sub! end
Return `b*c`, possibly modifying the object `a` in the process.
"""
function mul! end

@doc raw"""
canonical_injection(D, i)
Return the i-th canonical injection into the direct sum or product objects `D`.
"""
function canonical_injection end

@doc raw"""
canonical_projection(D, i)
Return the i-th canonical projection into the direct sum or product objects `D`.
"""
function canonical_projection end

@doc raw"""
_number_of_direct_product_factors(D)
Return the number of factors/ summands in the direct product/ sum object `D`
"""
function _number_of_direct_product_factors end

@doc raw"""
hom(D, C, data)
Return the homomorphism from the domain `D` into the codomain `C` defined by the data.
"""
function hom end

24 changes: 24 additions & 0 deletions src/generic/DirectSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ function direct_sum_injection(i::Int, D::DirectSumModule{T}, v::AbstractAlgebra.
return DirectSumModuleElem{T}(D, matv)
end

function AbstractAlgebra.canonical_injection(A::DirectSumModule, i::Int)
B = summands(A)[i]
return hom(B, A, [direct_sum_injection(i, A, x) for x = gens(B)])
end

AbstractAlgebra._number_of_direct_product_factors(A::DirectSumModule) = length(summands(A))

function direct_sum_projection(D::DirectSumModule{T}, i::Int, v::AbstractAlgebra.FPModuleElem{T}) where {T <: RingElement}
# Find starting point of the given module in the large vectors
S = summands(D)
Expand All @@ -164,6 +171,10 @@ function direct_sum_projection(D::DirectSumModule{T}, i::Int, v::AbstractAlgebra
return elem_type(m)(m, matv)
end

function AbstractAlgebra.canonical_projection(A::DirectSumModule, i::Int)
return hom(A, summands(A)[i], [direct_sum_projection(A, i, x) for x = gens(A)])
end

function direct_sum(m::Vector{<:AbstractAlgebra.FPModule{T}}) where T <: RingElement
length(m) == 0 && error("Cannot take a direct sum of an empty vector of modules")
# Check base rings are the same
Expand Down Expand Up @@ -239,3 +250,16 @@ function ModuleHomomorphism(D::DirectSumModule{T}, A::DirectSumModule{T}, m::Mat

return ModuleHomomorphism(D, A, transpose(hvcat(Tuple([length(SD) for i = 1:length(SA)]), map(x->transpose(x.matrix), m)...)))
end

function AbstractAlgebra.hom(A::AbstractAlgebra.Generic.DirectSumModule{T}, B::AbstractAlgebra.Generic.DirectSumModule{T}, M::Matrix{<:Map{<:AbstractAlgebra.FPModule{T}, <:AbstractAlgebra.FPModule{T}}}) where {T}
pro = canonical_projections(A)
im = canonical_injections(B)
s = hom(A, B, [zero(B) for i = 1:dim(A)])
for i=1:length(pro)
for j=1:length(im)
s += pro[i]*M[i,j]*im[j]
end
end
return s
end

0 comments on commit fc5b3c9

Please sign in to comment.