Skip to content

Commit

Permalink
Refactor passing around lie_algebra
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Oct 24, 2023
1 parent 0f84365 commit 1cfdc19
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 58 deletions.
22 changes: 20 additions & 2 deletions experimental/BasisLieHighestWeight/src/LieAlgebras.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct LieAlgebraStructure
@attributes mutable struct LieAlgebraStructure
lie_type::Symbol
rank::Int
lie_algebra_gap::GAP.Obj
Expand All @@ -11,11 +11,29 @@ struct LieAlgebraStructure
end
end

rank(L::LieAlgebraStructure) = L.rank

@attr QQMatrix function cartan_matrix(L::LieAlgebraStructure)
R = GAP.Globals.RootSystem(L.lie_algebra_gap)
C = matrix(QQ, GAP.Globals.CartanMatrix(R))
return C
end

@attr QQMatrix function inv_cartan_matrix(L::LieAlgebraStructure)
return inv(cartan_matrix(L))
end

function Base.show(io::IO, lie_algebra::LieAlgebraStructure)
print(io, "Lie-Algebra of type ", lie_algebra.lie_type, " and rank ", lie_algebra.rank)
end

gapReshape(A) = sparse_matrix(QQ, hcat(A...))
function lie_algebra_with_basis(type::Symbol, rk::Int)
lie_algebra = LieAlgebraStructure(type, rk)
chevalley_basis = NTuple{3,Vector{GAP.Obj}}(
GAP.Globals.ChevalleyBasis(lie_algebra.lie_algebra_gap)
)
return lie_algebra, chevalley_basis
end

function matricesForOperators(
lie_algebra::GAP.Obj, highest_weight::Vector{ZZRingElem}, operators::Vector{GAP.Obj}
Expand Down
61 changes: 22 additions & 39 deletions experimental/BasisLieHighestWeight/src/MainAlgorithm.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

function basis_lie_highest_weight_compute(
type::Symbol,
rank::Int,
lie_algebra::LieAlgebraStructure,
chevalley_basis::NTuple{3,Vector{GAP.Obj}},
highest_weight::Vector{Int},
get_operators::Function,
operators::Vector{GAP.Obj}, # operators are represented by our monomials. x_i is connected to operators[i]
monomial_ordering::Union{Symbol,Function},
)
"""
Expand Down Expand Up @@ -43,21 +43,12 @@ function basis_lie_highest_weight_compute(
# The function precomputes objects that are independent of the highest weight and that can be used in all recursion
# steps. Then it starts the recursion and returns the result.

# initialization of objects that can be precomputed
# lie_algebra of type, rank and its chevalley_basis
lie_algebra = LieAlgebraStructure(type, rank)
chevalley_basis = NTuple{3,Vector{GAP.Obj}}(
GAP.Globals.ChevalleyBasis(lie_algebra.lie_algebra_gap)
)

# operators that are represented by our monomials. x_i is connected to operators[i]
operators = get_operators(lie_algebra, chevalley_basis)

weights_w = weights_for_operators(
lie_algebra.lie_algebra_gap, chevalley_basis[3], operators
) # weights of the operators
weights_alpha = [
w_to_alpha(type, rank, convert(Vector{QQFieldElem}, weight_w)) for weight_w in weights_w
w_to_alpha(lie_algebra, convert(Vector{QQFieldElem}, weight_w)) for
weight_w in weights_w
] # other root system

asVec(v) = Oscar.GAP.gap_to_julia(GAPWrap.ExtRepOfObj(v)) # TODO
Expand All @@ -70,7 +61,7 @@ function basis_lie_highest_weight_compute(

# save computations from recursions
calc_highest_weight = Dict{Vector{ZZRingElem},Set{ZZMPolyRingElem}}(
[ZZ(0) for i in 1:rank] => Set([ZZx(1)])
[ZZ(0) for i in 1:rank(lie_algebra)] => Set([ZZx(1)])
)
# save all highest weights, for which the Minkowski-sum did not suffice to gain all monomials
no_minkowski = Set{Vector{ZZRingElem}}()
Expand Down Expand Up @@ -206,11 +197,10 @@ function basis_lie_highest_weight(
"""
Standard function with all options
"""
get_operators =
(lie_algebra, chevalley_basis) ->
get_operators_normal(lie_algebra, chevalley_basis, reduced_expression)
lie_algebra, chevalley_basis = lie_algebra_with_basis(type, rank)
operators = get_operators_normal(lie_algebra, chevalley_basis, reduced_expression)
return basis_lie_highest_weight_compute(
type, rank, highest_weight, get_operators, monomial_ordering
lie_algebra, chevalley_basis, highest_weight, operators, monomial_ordering
)
end

Expand Down Expand Up @@ -256,11 +246,10 @@ function basis_lie_highest_weight_lustzig(
BasisLieHighestWeight.basis_lie_highest_weight_lustzig(:D, 4, [1,1,1,1], [4,3,2,4,3,2,1,2,4,3,2,1])
"""
# operators = some sequence of the String / Littelmann-Berenstein-Zelevinsky polytope
get_operators =
(lie_algebra, chevalley_basis) ->
get_operators_lustzig(lie_algebra, chevalley_basis, reduced_expression)
lie_algebra, chevalley_basis = lie_algebra_with_basis(type, rank)
operators = get_operators_lustzig(lie_algebra, chevalley_basis, reduced_expression)
return basis_lie_highest_weight_compute(
type, rank, highest_weight, get_operators, monomial_ordering
lie_algebra, chevalley_basis, highest_weight, operators, monomial_ordering
)
end

Expand Down Expand Up @@ -300,11 +289,10 @@ function basis_lie_highest_weight_string(
"""
# reduced_expression = some sequence of the String / Littelmann-Berenstein-Zelevinsky polytope
monomial_ordering = :oplex
get_operators =
(lie_algebra, chevalley_basis) ->
get_operators_normal(lie_algebra, chevalley_basis, reduced_expression)
lie_algebra, chevalley_basis = lie_algebra_with_basis(type, rank)
operators = get_operators_normal(lie_algebra, chevalley_basis, reduced_expression)
return basis_lie_highest_weight_compute(
type, rank, highest_weight, get_operators, monomial_ordering
lie_algebra, chevalley_basis, highest_weight, operators, monomial_ordering
)
end

Expand Down Expand Up @@ -336,12 +324,10 @@ function basis_lie_highest_weight_fflv(type::Symbol, rank::Int, highest_weight::
BasisLieHighestWeight.basis_lie_highest_weight_fflv(:A, 3, [1,1,1])
"""
monomial_ordering = :oplex
# operators = all positive roots, reverse ordering as GAP uses
get_operators =
(lie_algebra, chevalley_basis) ->
reverse(get_operators_normal(lie_algebra, chevalley_basis, "regular"))
lie_algebra, chevalley_basis = lie_algebra_with_basis(type, rank)
operators = reverse(get_operators_normal(lie_algebra, chevalley_basis, "regular"))
return basis_lie_highest_weight_compute(
type, rank, highest_weight, get_operators, monomial_ordering
lie_algebra, chevalley_basis, highest_weight, operators, monomial_ordering
)
end

Expand Down Expand Up @@ -379,11 +365,10 @@ function basis_lie_highest_weight_nz(
BasisLieHighestWeight.basis_lie_highest_weight_nz(:A, 4, [1,1,1,1], [4,3,2,1,2,3,4,3,2,3])
"""
monomial_ordering = :lex
get_operators =
(lie_algebra, chevalley_basis) ->
get_operators_normal(lie_algebra, chevalley_basis, reduced_expression)
lie_algebra, chevalley_basis = lie_algebra_with_basis(type, rank)
operators = get_operators_normal(lie_algebra, chevalley_basis, reduced_expression)
return basis_lie_highest_weight_compute(
type, rank, highest_weight, get_operators, monomial_ordering
lie_algebra, chevalley_basis, highest_weight, operators, monomial_ordering
)
end

Expand Down Expand Up @@ -542,9 +527,7 @@ function add_new_monomials!(
ZZx,
get_lattice_points_of_weightspace(
birational_sequence.weights_alpha,
w_to_alpha(
lie_algebra.lie_type, lie_algebra.rank, convert(Vector{QQFieldElem}, weight_w)
),
w_to_alpha(lie_algebra, convert(Vector{QQFieldElem}, weight_w)),
),
)
#println("before sort")
Expand Down
15 changes: 4 additions & 11 deletions experimental/BasisLieHighestWeight/src/RootConversion.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
function w_to_alpha(type::Symbol, rank::Int, weight_w::Vector{QQFieldElem})
return weight_w * inv(cartan_matrix(type, rank))
function w_to_alpha(L::LieAlgebraStructure, weight_w::Vector{QQFieldElem})
return weight_w * inv_cartan_matrix(L)
end

function alpha_to_w(type::Symbol, rank::Int, weight_alpha::Vector{QQFieldElem})
return weight_alpha * cartan_matrix(type, rank)
end

function cartan_matrix(type::Symbol, rank::Int)
L = GAP.Globals.SimpleLieAlgebra(GAP.Obj(type), rank, GAP.Globals.Rationals)
R = GAP.Globals.RootSystem(L)
C = matrix(QQ, GAP.Globals.CartanMatrix(R))
return C
function alpha_to_w(L::LieAlgebraStructure, weight_alpha::Vector{QQFieldElem})
return weight_alpha * cartan_matrix(L)
end
2 changes: 0 additions & 2 deletions experimental/BasisLieHighestWeight/test/MBOld.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ function lieAlgebra(t::String, n::Int)
return L, NTuple{3,Vector{GAP.Obj}}(GAP.Globals.ChevalleyBasis(L))
end

gapReshape(A) = sparse_matrix(QQ, hcat(A...))

function matricesForOperators(L, hw, ops)
"""
used to create tensorMatricesForOperators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
w_to_alpha = BasisLieHighestWeight.w_to_alpha
alpha_to_w = BasisLieHighestWeight.alpha_to_w

function test_inverse_alpha_w(lie_type, n, weight)
@test w_to_alpha(lie_type, n, alpha_to_w(lie_type, n, weight)) == weight # alpha -> w -> alpha
@test alpha_to_w(lie_type, n, w_to_alpha(lie_type, n, weight)) == weight # w -> alpha -> w
function test_inverse_alpha_w(lie_algebra, weight)
@test w_to_alpha(lie_algebra, alpha_to_w(lie_algebra, weight)) == weight # alpha -> w -> alpha
@test alpha_to_w(lie_algebra, w_to_alpha(lie_algebra, weight)) == weight # w -> alpha -> w
end

@testset "Dynkin type $dynkin" for dynkin in (:A, :B, :C, :D, :E, :F, :G)
Expand All @@ -20,7 +20,8 @@
)
weight = [rand(QQ, -10:10) for _ in 1:n]
print(".")
test_inverse_alpha_w(dynkin, n, weight)
lie_algebra = BasisLieHighestWeight.LieAlgebraStructure(dynkin, n)
test_inverse_alpha_w(lie_algebra, weight)
end
end
end
Expand Down

0 comments on commit 1cfdc19

Please sign in to comment.