From 69591a1f70601039cfb56239930a106e4c286e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 19 Sep 2023 09:42:03 +0200 Subject: [PATCH 1/4] Cleanup after thofma/Hecke.jl#1196 --- experimental/LieAlgebras/src/LieAlgebras.jl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/experimental/LieAlgebras/src/LieAlgebras.jl b/experimental/LieAlgebras/src/LieAlgebras.jl index 18a2daf3bb66..d98b1d7ae1a6 100644 --- a/experimental/LieAlgebras/src/LieAlgebras.jl +++ b/experimental/LieAlgebras/src/LieAlgebras.jl @@ -4,11 +4,6 @@ using ..Oscar import Oscar: GAPWrap, IntegerUnion, MapHeader -import Hecke: - canonical_injection, canonical_injections, canonical_projection, canonical_projections # Until https://github.com/thofma/Hecke.jl/pull/1196 is available -export canonical_injection, - canonical_injections, canonical_projection, canonical_projections # Until https://github.com/thofma/Hecke.jl/pull/1196 is available - # not importet in Oscar using AbstractAlgebra: CacheDictType, ProductIterator, get_cached!, ordinal_number_string @@ -20,6 +15,10 @@ import ..Oscar: action, basis, basis_matrix, + canonical_injection, + canonical_injections, + canonical_projection, + canonical_projections, center, centralizer, coeff, @@ -165,6 +164,3 @@ export symmetric_power export tensor_power export trivial_module export universal_enveloping_algebra - -export canonical_injection, - canonical_injections, canonical_projection, canonical_projections # Until https://github.com/thofma/Hecke.jl/pull/1196 is available From d7d75a287375198510e8850fbe1c31059191b18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 19 Sep 2023 09:53:38 +0200 Subject: [PATCH 2/4] Fix for 0-th powers --- experimental/LieAlgebras/src/LieAlgebraModuleHom.jl | 12 ++++++++++-- .../LieAlgebras/test/LieAlgebraModuleHom-test.jl | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/experimental/LieAlgebras/src/LieAlgebraModuleHom.jl b/experimental/LieAlgebras/src/LieAlgebraModuleHom.jl index 618d42478015..323e0a3582ba 100644 --- a/experimental/LieAlgebras/src/LieAlgebraModuleHom.jl +++ b/experimental/LieAlgebras/src/LieAlgebraModuleHom.jl @@ -484,7 +484,11 @@ function hom_tensor( @req length(Vs) == length(Ws) == length(hs) "Length mismatch" @req all(i -> domain(hs[i]) === Vs[i] && codomain(hs[i]) === Ws[i], 1:length(hs)) "Domain/codomain mismatch" - mat = reduce(kronecker_product, [matrix(hi) for hi in hs]) + mat = reduce( + kronecker_product, + [matrix(hi) for hi in hs]; + init=identity_matrix(coefficient_ring(W), 1), + ) return hom(V, W, mat; check=false) end @@ -516,7 +520,11 @@ function hom_power( TV = type == :tensor ? V : get_attribute(V, :embedding_tensor_power) TW = type == :tensor ? W : get_attribute(W, :embedding_tensor_power) - mat = reduce(kronecker_product, [matrix(h) for _ in 1:get_attribute(V, :power)]) + mat = reduce( + kronecker_product, + [matrix(h) for _ in 1:get_attribute(V, :power)]; + init=identity_matrix(coefficient_ring(W), 1), + ) TV_to_TW = hom(TV, TW, mat; check=false) if type == :tensor diff --git a/experimental/LieAlgebras/test/LieAlgebraModuleHom-test.jl b/experimental/LieAlgebras/test/LieAlgebraModuleHom-test.jl index 5cd052799f3e..78e374680f44 100644 --- a/experimental/LieAlgebras/test/LieAlgebraModuleHom-test.jl +++ b/experimental/LieAlgebras/test/LieAlgebraModuleHom-test.jl @@ -176,7 +176,7 @@ @testset "hom_power ($f_power)" for f_power in [exterior_power, symmetric_power, tensor_power] - for k in 1:3 + for k in 0:3 L = special_orthogonal_lie_algebra(QQ, 4) Vb = standard_module(L) Wb = dual(dual(standard_module(L))) @@ -188,7 +188,7 @@ @test domain(h) == V @test codomain(h) == W @test is_welldefined(h) - vs = [Vb(rand(-10:10, dim(Vb))) for _ in 1:k] + vs = elem_type(Vb)[Vb(rand(-10:10, dim(Vb))) for _ in 1:k] @test h(V(vs)) == W(hb.(vs)) end end From d0daf59c60d88f61a4e073cd6d9ffccb1ccfd377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 19 Sep 2023 11:08:11 +0200 Subject: [PATCH 3/4] Fix 0-dim Lie algebras --- .../LieAlgebras/docs/src/lie_algebras.md | 8 +---- .../LieAlgebras/src/AbstractLieAlgebra.jl | 4 ++- experimental/LieAlgebras/src/LieAlgebras.jl | 2 ++ .../LieAlgebras/src/LinearLieAlgebra.jl | 32 ++++++++++--------- .../test/AbstractLieAlgebra-test.jl | 8 +++++ .../LieAlgebras/test/LieAlgebra-test.jl | 2 +- .../LieAlgebras/test/LinearLieAlgebra-test.jl | 8 +++++ 7 files changed, 40 insertions(+), 24 deletions(-) diff --git a/experimental/LieAlgebras/docs/src/lie_algebras.md b/experimental/LieAlgebras/docs/src/lie_algebras.md index 9fd3c2fa85e1..4fedc32a33ff 100644 --- a/experimental/LieAlgebras/docs/src/lie_algebras.md +++ b/experimental/LieAlgebras/docs/src/lie_algebras.md @@ -29,6 +29,7 @@ symbols(::LieAlgebra) ## Special functions for `LinearLieAlgebra`s ```@docs +coerce_to_lie_algebra_elem(::LinearLieAlgebra{C}, ::MatElem{C}) where {C<:RingElement} matrix_repr_basis(::LinearLieAlgebra{C}) where {C<:RingElement} matrix_repr_basis(::LinearLieAlgebra{C}, ::Int) where {C<:RingElement} matrix_repr(::LinearLieAlgebraElem{C}) where {C<:RingElement} @@ -45,13 +46,6 @@ and fails otherwise. `v` can be of type `Vector{C}`, `Vector{Int}`, `SRow{C}`, or `MatElem{C}` (of size $1 \times \dim(L)$). -If `L` is a `LinearLieAlgebra` of `dim(L) > 1`, the call -`(L::LinearLieAlgebra{C})(m::MatElem{C})` returns the Lie algebra element whose -matrix representation corresponds to `m`. -This requires `m` to be a square matrix of size `n > 1` (the dimension of `L`), and -to lie in the Lie algebra `L` (i.e. to be in the span of `basis(L)`). -The case of `m` being a $1 \times \dim(L)$ matrix still works as explained above. - ## Arithmetics The usual arithmetics, e.g. `+`, `-`, and `*`, are defined for `LieAlgebraElem`s. diff --git a/experimental/LieAlgebras/src/AbstractLieAlgebra.jl b/experimental/LieAlgebras/src/AbstractLieAlgebra.jl index c8cf34b1da92..2959e13728b6 100644 --- a/experimental/LieAlgebras/src/AbstractLieAlgebra.jl +++ b/experimental/LieAlgebras/src/AbstractLieAlgebra.jl @@ -119,7 +119,8 @@ function bracket( L = parent(x) mat = sum( cxi * cyj * L.struct_consts[i, j] for (i, cxi) in enumerate(coefficients(x)), - (j, cyj) in enumerate(coefficients(y)) + (j, cyj) in enumerate(coefficients(y)); + init=sparse_row(coefficient_ring(L)), ) return L(mat) end @@ -287,6 +288,7 @@ function lie_algebra(R::Ring, dynkin::Tuple{Char,Int}; cached::Bool=true) end function abelian_lie_algebra(::Type{T}, R::Ring, n::Int) where {T<:AbstractLieAlgebra} + @req n >= 0 "Dimension must be non-negative." basis = [(b = zero_matrix(R, n, n); b[i, i] = 1; b) for i in 1:n] s = ["x_$(i)" for i in 1:n] L = lie_algebra(R, n, basis, s; check=false) diff --git a/experimental/LieAlgebras/src/LieAlgebras.jl b/experimental/LieAlgebras/src/LieAlgebras.jl index d98b1d7ae1a6..37067f8e5a9c 100644 --- a/experimental/LieAlgebras/src/LieAlgebras.jl +++ b/experimental/LieAlgebras/src/LieAlgebras.jl @@ -78,6 +78,7 @@ export base_module export base_modules export bracket export coefficient_vector +export coerce_to_lie_algebra_elem export combinations export derived_algebra export exterior_power @@ -140,6 +141,7 @@ export base_lie_algebra export base_module export base_modules export bracket +export coerce_to_lie_algebra_elem export derived_algebra export exterior_power export general_linear_lie_algebra diff --git a/experimental/LieAlgebras/src/LinearLieAlgebra.jl b/experimental/LieAlgebras/src/LinearLieAlgebra.jl index d48f70d74654..34008ca7d8c8 100644 --- a/experimental/LieAlgebras/src/LinearLieAlgebra.jl +++ b/experimental/LieAlgebras/src/LinearLieAlgebra.jl @@ -140,21 +140,17 @@ end ############################################################################### @doc raw""" - (L::LinearLieAlgebra{C})(m::MatElem{C}) -> LieAlgebraElem{C} + coerce_to_lie_algebra_elem(L::LinearLieAlgebra{C}, x::MatElem{C}) -> LinearLieAlgebraElem{C} -Return the Lie algebra element whose matrix representation corresponds to `m`. -This requires `m` to be a square matrix of size `n > 1` (the dimension of `L`), and -to lie in the Lie algebra `L` (i.e. to be in the span of `basis(L)`). - -If `m` is a $1 \times \dim(L)` vector, it is assumed to be a coefficient vector in the -basis `basis(L)`. +Returns the element of `L` whose matrix representation corresponds to `x`. +If no such element exists, an error is thrown. """ -function (L::LinearLieAlgebra{C})(m::MatElem{C}) where {C<:RingElement} - if L.n > 1 && size(m) == (L.n, L.n) - m = coefficient_vector(m, matrix_repr_basis(L)) - end - @req size(m) == (1, dim(L)) "Invalid matrix dimensions." - return elem_type(L)(L, m) +function coerce_to_lie_algebra_elem( + L::LinearLieAlgebra{C}, x::MatElem{C} +) where {C<:RingElement} + @req size(x) == (L.n, L.n) "Invalid matrix dimensions." + m = coefficient_vector(x, matrix_repr_basis(L)) + return L(m) end ############################################################################### @@ -169,7 +165,11 @@ end Return the Lie algebra element `x` in the underlying matrix representation. """ function Generic.matrix_repr(x::LinearLieAlgebraElem) - return sum(c * b for (c, b) in zip(_matrix(x), matrix_repr_basis(parent(x)))) + L = parent(x) + return sum( + c * b for (c, b) in zip(_matrix(x), matrix_repr_basis(L)); + init=zero_matrix(coefficient_ring(L), L.n, L.n), + ) end function bracket( @@ -179,7 +179,7 @@ function bracket( L = parent(x) x_mat = matrix_repr(x) y_mat = matrix_repr(y) - return L(x_mat * y_mat - y_mat * x_mat) + return coerce_to_lie_algebra_elem(L, x_mat * y_mat - y_mat * x_mat) end ############################################################################### @@ -230,10 +230,12 @@ The first argument can be optionally provided to specify the type of the returne Lie algebra. """ function abelian_lie_algebra(R::Ring, n::Int) + @req n >= 0 "Dimension must be non-negative." return abelian_lie_algebra(LinearLieAlgebra, R, n) end function abelian_lie_algebra(::Type{T}, R::Ring, n::Int) where {T<:LinearLieAlgebra} + @req n >= 0 "Dimension must be non-negative." basis = [(b = zero_matrix(R, n, n); b[i, i] = 1; b) for i in 1:n] s = ["x_$(i)" for i in 1:n] L = lie_algebra(R, n, basis, s; check=false) diff --git a/experimental/LieAlgebras/test/AbstractLieAlgebra-test.jl b/experimental/LieAlgebras/test/AbstractLieAlgebra-test.jl index 7143432cd116..72967ef74a1f 100644 --- a/experimental/LieAlgebras/test/AbstractLieAlgebra-test.jl +++ b/experimental/LieAlgebras/test/AbstractLieAlgebra-test.jl @@ -11,6 +11,14 @@ end @testset "conformance tests" begin + @testset "0-dim Lie algebra /QQ" begin + L = lie_algebra(QQ, Matrix{SRow{QQFieldElem}}(undef, 0, 0), Symbol[]) + lie_algebra_conformance_test( + L, AbstractLieAlgebra{QQFieldElem}, AbstractLieAlgebraElem{QQFieldElem} + ) + @test is_abelian(L) + end + @testset "sl_2(QQ) using structure constants" begin L = lie_algebra(QQ, sl2_struct_consts(QQ), ["e", "f", "h"]) lie_algebra_conformance_test( diff --git a/experimental/LieAlgebras/test/LieAlgebra-test.jl b/experimental/LieAlgebras/test/LieAlgebra-test.jl index da05730a3b75..7970ea183ca3 100644 --- a/experimental/LieAlgebras/test/LieAlgebra-test.jl +++ b/experimental/LieAlgebras/test/LieAlgebra-test.jl @@ -30,7 +30,7 @@ function lie_algebra_conformance_test( @test coefficients(x) == [coeff(x, i) for i in 1:dim(L)] @test all(i -> coeff(x, i) == x[i], 1:dim(L)) - @test sum(x[i] * basis(L, i) for i in 1:dim(L)) == x + @test sum(x[i] * basis(L, i) for i in 1:dim(L); init=zero(L)) == x @test x == x @test deepcopy(x) == x diff --git a/experimental/LieAlgebras/test/LinearLieAlgebra-test.jl b/experimental/LieAlgebras/test/LinearLieAlgebra-test.jl index 4c6c160a1978..8ff1da2ab3a9 100644 --- a/experimental/LieAlgebras/test/LinearLieAlgebra-test.jl +++ b/experimental/LieAlgebras/test/LinearLieAlgebra-test.jl @@ -11,6 +11,14 @@ end @testset "conformance tests" begin + @testset "0-dim Lie algebra /QQ" begin + L = lie_algebra(QQ, 0, MatElem{QQFieldElem}[], Symbol[]) + lie_algebra_conformance_test( + L, LinearLieAlgebra{QQFieldElem}, LinearLieAlgebraElem{QQFieldElem} + ) + @test is_abelian(L) + end + @testset "4-dim abelian Lie algebra /QQ" begin L = abelian_lie_algebra(LinearLieAlgebra, QQ, 4) lie_algebra_conformance_test( From 4158bf4745ee13ffc6d614dcd1deed201ae9670e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 19 Sep 2023 11:29:02 +0200 Subject: [PATCH 4/4] Add tests for 0-dim modules --- .../LieAlgebras/test/LieAlgebraModule-test.jl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/experimental/LieAlgebras/test/LieAlgebraModule-test.jl b/experimental/LieAlgebras/test/LieAlgebraModule-test.jl index 512d632ce0c1..f9d17df5d7ae 100644 --- a/experimental/LieAlgebras/test/LieAlgebraModule-test.jl +++ b/experimental/LieAlgebras/test/LieAlgebraModule-test.jl @@ -36,7 +36,7 @@ function lie_algebra_module_conformance_test( @test coefficients(v) == [coeff(v, i) for i in 1:dim(V)] @test all(i -> coeff(v, i) == v[i], 1:dim(V)) - @test sum(v[i] * basis(V, i) for i in 1:dim(V)) == v + @test sum(v[i] * basis(V, i) for i in 1:dim(V); init=zero(V)) == v @test v == v @test deepcopy(v) == v @@ -115,6 +115,18 @@ end sc[3, 2] = sparse_row(QQ, [1, 2], [0, -1]) @testset "conformance tests" begin + @testset "0-dim module of sl_2(QQ)" begin + L = special_linear_lie_algebra(QQ, 2) + V = trivial_module(L, 0) + lie_algebra_module_conformance_test(L, V) + end + + @testset "3-dim trivial module of so_3(QQ)" begin + L = special_orthogonal_lie_algebra(QQ, 2) + V = trivial_module(L, 3) + lie_algebra_module_conformance_test(L, V) + end + @testset "V of sl_2(QQ) using structure constants" begin L = special_linear_lie_algebra(QQ, 2) V = abstract_module(L, 2, sc)