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

add most of the direct_sum new stuff #1620

Merged
merged 1 commit into from
Feb 22, 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
19 changes: 19 additions & 0 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,10 @@
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 @@ -851,6 +855,7 @@
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 @@ -1162,6 +1167,12 @@
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 @@ -1177,6 +1188,14 @@
Generic.sub(m, subs)
end

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

Check warning on line 1194 in src/AbstractAlgebra.jl

View check run for this annotation

Codecov / codecov/patch

src/AbstractAlgebra.jl#L1193-L1194

Added lines #L1193 - L1194 were not covered by tests
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 @@
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)])

Check warning on line 157 in src/generic/DirectSum.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/DirectSum.jl#L155-L157

Added lines #L155 - L157 were not covered by tests
end

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

Check warning on line 160 in src/generic/DirectSum.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/DirectSum.jl#L160

Added line #L160 was not covered by tests

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 @@
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)])

Check warning on line 175 in src/generic/DirectSum.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/DirectSum.jl#L174-L175

Added lines #L174 - L175 were not covered by tests
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 @@

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

Check warning on line 263 in src/generic/DirectSum.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/DirectSum.jl#L254-L263

Added lines #L254 - L263 were not covered by tests
end

Loading