Skip to content

Commit

Permalink
LieAlgebras: Follow-up to #2753 (#2818)
Browse files Browse the repository at this point in the history
* Cleanup after thofma/Hecke.jl#1196

* Fix for 0-th powers

* Fix 0-dim Lie algebras

* Add tests for 0-dim modules
  • Loading branch information
lgoettgens authored Sep 19, 2023
1 parent 86e16b5 commit 3768cf3
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 37 deletions.
8 changes: 1 addition & 7 deletions experimental/LieAlgebras/docs/src/lie_algebras.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion experimental/LieAlgebras/src/AbstractLieAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions experimental/LieAlgebras/src/LieAlgebraModuleHom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions experimental/LieAlgebras/src/LieAlgebras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,6 +15,10 @@ import ..Oscar:
action,
basis,
basis_matrix,
canonical_injection,
canonical_injections,
canonical_projection,
canonical_projections,
center,
centralizer,
coeff,
Expand Down Expand Up @@ -79,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
Expand Down Expand Up @@ -141,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
Expand All @@ -165,6 +166,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
32 changes: 17 additions & 15 deletions experimental/LieAlgebras/src/LinearLieAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

###############################################################################
Expand All @@ -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(
Expand All @@ -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

###############################################################################
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions experimental/LieAlgebras/test/AbstractLieAlgebra-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion experimental/LieAlgebras/test/LieAlgebra-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion experimental/LieAlgebras/test/LieAlgebraModule-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions experimental/LieAlgebras/test/LieAlgebraModuleHom-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions experimental/LieAlgebras/test/LinearLieAlgebra-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3768cf3

Please sign in to comment.