Skip to content

Commit ed31bdc

Browse files
committed
add weight structure computation for SumLieAlgebraAction
1 parent e0e9545 commit ed31bdc

File tree

5 files changed

+199
-155
lines changed

5 files changed

+199
-155
lines changed

src/on_varieties/lie-symmetries/lie-algebras/actions.jl

Lines changed: 128 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export AbstractLieAlgebraAction,
22
LieAlgebraAction,
33
ScalingLieAction,
44
SumLieAlgebraAction,
5-
var_groups
5+
var_groups,
6+
hw_spaces
67

78

89
abstract type AbstractLieAlgebraAction end
@@ -26,22 +27,22 @@ function ScalingLieAction(action_vars::AbstractArray; variables::AbstractArray=a
2627
return ScalingLieAction(act_vars, all_vars)
2728
end
2829

29-
algebra(g::ScalingLieAction) = g.alg
30-
variables(g::ScalingLieAction) = g.vars
31-
exponents(g::ScalingLieAction) = g.alg.exps
30+
algebra(a::ScalingLieAction) = a.alg
31+
variables(a::ScalingLieAction) = a.vars
32+
exponents(a::ScalingLieAction) = a.alg.exps
3233

33-
function Base.show(io::IO, g::ScalingLieAction)
34-
println(io, "ScalingLieAction of $(name(algebra(g)))")
34+
function Base.show(io::IO, a::ScalingLieAction)
35+
println(io, "ScalingLieAction of $(name(algebra(a)))")
3536
print(io, " action:")
36-
U = exponents(g)
37+
U = exponents(a)
3738
if size(U, 1) == 1
3839
@var λ
3940
λ = [λ]
4041
else
4142
@var λ[1:size(U₀, 1)]
4243
end
4344
action = Vector{Vector{Tuple{Variable, Expression}}}([[] for _ in axes(U, 1)])
44-
vars = variables(g)
45+
vars = variables(a)
4546
for j in axes(U, 1)
4647
nzind, nzval = findnz(U[j, :])
4748
exprs = (λ[j].^nzval).*vars[nzind]
@@ -56,6 +57,44 @@ function Base.show(io::IO, g::ScalingLieAction)
5657
end
5758
end
5859

60+
function act(elem::LieAlgebraElem{ScalingLieAlgebra}, f::Union{Expression, Monomial}, action::ScalingLieAction)
61+
X = as_matrix(elem)
62+
return expand(dot(differentiate(f, variables(action)), -X*variables(action)))
63+
end
64+
65+
function weight_structure(a::ScalingLieAction, vars::Vector{Variable})
66+
67+
end
68+
69+
function hw_spaces(a::ScalingLieAction, vars::Vector{Variable})
70+
@assert variables(a) vars
71+
vars_dict = Dict(zip(vars, 1:length(vars)))
72+
hw_spaces_dict = Dict{Vector{Int}, WeightSpace}()
73+
for (i, var) in enumerate(variables(a))
74+
weight = exponents(a)[:, i]
75+
if haskey(hw_spaces_dict, weight)
76+
sp = zeros(ComplexF64, length(vars))
77+
sp[vars_dict[var]] = 1
78+
hw_spaces_dict[weight].space = hcat(hw_spaces_dict[weight].space, sp)
79+
else
80+
hw_space = WeightSpace(weight, zeros(ComplexF64, length(vars)))
81+
hw_space.space[vars_dict[var]] = 1
82+
hw_spaces_dict[weight] = hw_space
83+
end
84+
end
85+
inv_vars = setdiff(vars, variables(a))
86+
isempty(inv_vars) && return collect(values(hw_spaces_dict))
87+
inv_hw_space = WeightSpace(zeros(Int, rank(algebra(a))), zeros(ComplexF64, length(vars), length(inv_vars)))
88+
for (i, var) in enumerate(inv_vars)
89+
inv_hw_space.space[vars_dict[var], i] = 1
90+
end
91+
if haskey(hw_spaces_dict, weight(inv_hw_space))
92+
hw_spaces_dict[weight(inv_hw_space)].space = hcat(hw_spaces_dict[weight(inv_hw_space)].space, inv_hw_space.space)
93+
else
94+
hw_spaces_dict[weight(inv_hw_space)] = inv_hw_space
95+
end
96+
return collect(values(hw_spaces_dict))
97+
end
5998

6099
struct LieAlgebraAction <: AbstractLieAlgebraAction
61100
alg::LieAlgebra
@@ -72,16 +111,54 @@ LieAlgebraAction(
72111
var_groups::AbstractArray
73112
) = LieAlgebraAction(alg, M2VV(hcat(var_groups...)))
74113

75-
algebra(g::LieAlgebraAction) = g.alg
76-
var_groups(g::LieAlgebraAction) = g.var_groups
77-
variables(g::LieAlgebraAction) = vcat(var_groups(g)...)
78-
weights(g::LieAlgebraAction) = weights(g.alg)
79-
weights(g::LieAlgebraAction, inds...) = weights(g.alg, inds...)
80-
nweights(g::LieAlgebraAction) = nweights(g.alg)
114+
algebra(a::LieAlgebraAction) = a.alg
115+
var_groups(a::LieAlgebraAction) = a.var_groups
116+
nvar_groups(a::LieAlgebraAction) = length(var_groups(a))
117+
variables(a::LieAlgebraAction) = vcat(var_groups(a)...)
118+
weights(a::LieAlgebraAction) = weights(a.alg)
119+
weights(a::LieAlgebraAction, inds...) = weights(a.alg, inds...)
120+
nweights(a::LieAlgebraAction) = nweights(a.alg)
121+
122+
function Base.show(io::IO, a::LieAlgebraAction)
123+
println(io, "LieAlgebraAction of $(name(algebra(a)))")
124+
print(io, " action: [", join([join(vars, ", ") for vars in var_groups(a)], "], ["), "]")
125+
end
81126

82-
function Base.show(io::IO, g::LieAlgebraAction)
83-
println(io, "LieAlgebraAction of $(name(algebra(g)))")
84-
print(io, " action: [", join([join(vars, ", ") for vars in var_groups(g)], "], ["), "]")
127+
function act(elem::LieAlgebraElem{LieAlgebra}, f::Union{Expression, Monomial}, action::LieAlgebraAction)
128+
X = as_matrix(elem)
129+
return expand(sum([dot(differentiate(f, vars), -X*vars) for vars in var_groups(action)]))
130+
end
131+
132+
function weight_structure(a::LieAlgebraAction, vars::Vector{Variable})
133+
134+
end
135+
136+
function hw_spaces(a::LieAlgebraAction, vars::Vector{Variable})
137+
@assert variables(a) vars
138+
vars_dict = Dict(zip(vars, 1:length(vars)))
139+
hw_spaces_vec = WeightSpace[]
140+
for hw_space in hw_spaces(algebra(a))
141+
hws = WeightSpace(hw_space.weight, zeros(ComplexF64, length(vars), dim(hw_space)*nvar_groups(a)))
142+
for (i, vars_group) in enumerate(var_groups(a))
143+
for (j, var) in enumerate(vars_group)
144+
hws.space[vars_dict[var], (i-1)*dim(hw_space)+1:i*dim(hw_space)] = hw_space.space[j, :]
145+
end
146+
end
147+
push!(hw_spaces_vec, hws)
148+
end
149+
inv_vars = setdiff(vars, variables(a))
150+
isempty(inv_vars) && return hw_spaces_vec
151+
inv_hw_space = WeightSpace(zeros(Int, rank(algebra(a))), zeros(ComplexF64, length(vars), length(inv_vars)))
152+
for (i, var) in enumerate(inv_vars)
153+
inv_hw_space.space[vars_dict[var], i] = 1
154+
end
155+
hws_dict = Dict(zip([weight(hws) for hws in hw_spaces_vec], hw_spaces_vec))
156+
if haskey(hws_dict, weight(inv_hw_space))
157+
hws_dict[weight(inv_hw_space)].space = hcat(hws_dict[weight(inv_hw_space)].space, inv_hw_space.space)
158+
else
159+
push!(hw_spaces_vec, inv_hw_space)
160+
end
161+
return hw_spaces_vec
85162
end
86163

87164

@@ -90,13 +167,13 @@ struct SumLieAlgebraAction <: AbstractLieAlgebraAction
90167
actions::Vector{AbstractLieAlgebraAction}
91168
end
92169

93-
algebra(g::SumLieAlgebraAction) = g.alg
94-
actions(g::SumLieAlgebraAction) = g.actions
95-
nsummands(g::SumLieAlgebraAction) = length(actions(g))
96-
Base.getindex(g::SumLieAlgebraAction, i::Int) = actions(g)[i]
170+
algebra(a::SumLieAlgebraAction) = a.alg
171+
actions(a::SumLieAlgebraAction) = a.actions
172+
nsummands(a::SumLieAlgebraAction) = length(actions(a))
173+
Base.getindex(a::SumLieAlgebraAction, i::Int) = actions(a)[i]
97174

98-
function Base.show(io::IO, g::SumLieAlgebraAction)
99-
println(io, "SumLieAlgebraAction of $(name(algebra(g)))")
175+
function Base.show(io::IO, a::SumLieAlgebraAction)
176+
println(io, "SumLieAlgebraAction of $(name(algebra(a)))")
100177
# for (i, a) in enumerate(actions(g))
101178
# print(io, " action of $(name(algebra(a))): [")
102179
# print(io, join([join(vars, ", ") for vars in var_groups(a)], "], ["), "]")
@@ -106,36 +183,45 @@ function Base.show(io::IO, g::SumLieAlgebraAction)
106183
end
107184

108185
# TODO
109-
function are_commutative(g::AbstractLieAlgebraAction, g::AbstractLieAlgebraAction)
186+
function are_commutative(a::AbstractLieAlgebraAction, a::AbstractLieAlgebraAction)
110187
return true
111188
end
112189

113-
function (g₁::AbstractLieAlgebraAction, g₂::AbstractLieAlgebraAction)
114-
@assert are_commutative(g₁, g₂)
115-
alg = algebra(g₁) algebra(g₂)
116-
return SumLieAlgebraAction(alg, [g₁, g₂])
117-
end
118-
119-
function (g₁::SumLieAlgebraAction, g₂::AbstractLieAlgebraAction)
120-
@assert are_commutative(g₁, g₂)
121-
alg = algebra(g₁) algebra(g₂)
122-
return SumLieAlgebraAction(alg, [actions(g₁)..., g₂])
123-
end
124-
125-
function act(elem::LieAlgebraElem{LieAlgebra}, f::Union{Expression, Monomial}, action::LieAlgebraAction)
126-
X = as_matrix(elem)
127-
return expand(sum([dot(differentiate(f, vars), -X*vars) for vars in var_groups(action)]))
190+
function (a₁::AbstractLieAlgebraAction, a₂::AbstractLieAlgebraAction)
191+
@assert are_commutative(a₁, a₂)
192+
alg = algebra(a₁) algebra(a₂)
193+
return SumLieAlgebraAction(alg, [a₁, a₂])
128194
end
129195

130-
function act(elem::LieAlgebraElem{ScalingLieAlgebra}, f::Union{Expression, Monomial}, action::ScalingLieAction)
131-
X = as_matrix(elem)
132-
return expand(dot(differentiate(f, variables(action)), -X*variables(action)))
196+
function (a₁::SumLieAlgebraAction, a₂::AbstractLieAlgebraAction)
197+
@assert are_commutative(a₁, a₂)
198+
alg = algebra(a₁) algebra(a₂)
199+
return SumLieAlgebraAction(alg, [actions(a₁)..., a₂])
133200
end
134201

135202
function act(elem::SumLieAlgebraElem, f::Union{Expression, Monomial}, action::SumLieAlgebraAction)
136203
return expand(sum([act(elem[i], f, action[i]) for i in 1:nsummands(action)]))
137204
end
138205

206+
hw_spaces(
207+
a::SumLieAlgebraAction,
208+
vars::Vector{Variable}
209+
) = ([hw_spaces(action, vars) for action in actions(a)])
210+
211+
function weight_structure(a::AbstractLieAlgebraAction, vars::Vector{Variable})
212+
hws = hw_spaces(a, vars)
213+
mons = MonomialBasis{Int8,Int16}(vars, degree=1, upto=false)
214+
ws = WeightStructure()
215+
for hw_space in hws
216+
for hwv in hw_space
217+
wexpr = WeightExpression(hwv, mons)
218+
orb = orbit(wexpr, a)
219+
[push!(ws, WeightVector(we)) for we in orb]
220+
end
221+
end
222+
return ws
223+
end
224+
139225
function as_matrix(elem::AbstractLieAlgebraElem, B::MonomialBasis, action::AbstractLieAlgebraAction)
140226
@assert algebra(elem) == algebra(action)
141227
M = zeros(ComplexF64, length(B), length(B))

src/on_varieties/lie-symmetries/lie-algebras/algebras.jl

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ export AbstractLieAlgebra,
22
ScalingLieAlgebra,
33
name,
44
dim,
5+
exponents,
56
rank,
67
LieAlgebra,
78
basis,
89
cartan_subalgebra,
9-
positive_roots,
10-
negative_roots,
11-
set_chevalley_basis!,
12-
set_cartan_subalgebra!,
13-
set_positive_roots!,
14-
set_negative_roots!,
10+
positive_root_elements,
11+
negative_root_elements,
1512
weight_structure,
1613
weights,
1714
nweights,
@@ -29,15 +26,16 @@ struct ScalingLieAlgebra <: AbstractLieAlgebra
2926
end
3027

3128
function ScalingLieAlgebra(exps::Matrix{Int})
32-
name = size(exps, 1) == 1 ? "ℂˣ" : "(ℂˣ)$(superscript(size(exps, 1)))"
29+
name = size(exps, 1) == 1 ? "" : "$(superscript(size(exps, 1)))"
3330
return ScalingLieAlgebra(name, sparse(exps))
3431
end
3532

36-
ScalingLieAlgebra(size::Int) = ScalingLieAlgebra("ℂˣ", sparse(ones(Int, 1, size)))
33+
ScalingLieAlgebra(size::Int) = ScalingLieAlgebra("", sparse(ones(Int, 1, size)))
3734

3835
name(alg::ScalingLieAlgebra) = alg.name
3936
dim(alg::ScalingLieAlgebra) = size(alg.exps, 1)
40-
LinearAlgebra.rank(alg::ScalingLieAlgebra) = dim(alg)
37+
exponents(alg::ScalingLieAlgebra) = alg.exps
38+
MultivariateInterpolation.rank(alg::ScalingLieAlgebra) = dim(alg)
4139
Base.size(alg::ScalingLieAlgebra) = size(alg.exps, 2)
4240

4341
function basis(alg::ScalingLieAlgebra; as_matrices::Bool=false)
@@ -64,6 +62,7 @@ mutable struct LieAlgebra <: AbstractLieAlgebra
6462
name::String
6563
basis::ChevalleyBasis
6664
weight_structure::WeightStructure
65+
hw_spaces::Vector{WeightSpace}
6766
end
6867

6968
function Base.show(io::IO, alg::LieAlgebra)
@@ -83,7 +82,8 @@ function so3_lie_algebra()
8382
neg_roots = [[-1]]
8483
ch_basis = ChevalleyBasis([X₁, X₂, X₃], cartan, positive, negative, pos_roots, neg_roots)
8584
ws = WeightStructure([-1, 0, 1], [[1, -im, 0], [0, 0, 1], [1, im, 0]])
86-
return LieAlgebra("𝖘𝖔(3,ℂ)", ch_basis, ws)
85+
hw_spaces = [WeightSpace([1], [1, im, 0])]
86+
return LieAlgebra("𝖘𝖔(3,ℂ)", ch_basis, ws, hw_spaces)
8787
end
8888

8989
# TODO
@@ -97,7 +97,7 @@ end
9797

9898
name(alg::LieAlgebra) = alg.name
9999
dim(alg::LieAlgebra) = length(alg.basis.std_basis)
100-
LinearAlgebra.rank(alg::LieAlgebra) = length(alg.basis.cartan)
100+
MultivariateInterpolation.rank(alg::LieAlgebra) = length(alg.basis.cartan)
101101
Base.size(alg::LieAlgebra) = size(alg.basis.std_basis[1], 1)
102102

103103
function basis(alg::LieAlgebra; as_matrices::Bool=false)
@@ -109,35 +109,19 @@ function basis(alg::LieAlgebra; as_matrices::Bool=false)
109109
end
110110

111111
cartan_subalgebra(alg::LieAlgebra) = [LieAlgebraElem(alg, coeffs) for coeffs in alg.basis.cartan]
112-
positive_root_elements(alg::LieAlgebra) = [LieAlgebraElem(alg, coeffs, root) for (coeffs, root) in zip(alg.basis.positive, alg.basis.positive_roots)]
113-
negative_root_elements(alg::LieAlgebra) = [LieAlgebraElem(alg, coeffs, root) for (coeffs, root) in zip(alg.basis.negative, alg.basis.negative_roots)]
114-
115-
# set_chevalley_basis!(
116-
# alg::LieAlgebra,
117-
# B::NTuple{3, Vector{Vector{T}}} where T <: Number
118-
# ) = alg.chevalley_basis = B
119-
120-
# set_cartan_subalgebra!(
121-
# alg::LieAlgebra,
122-
# B::Vector{Vector{T}} where T <: Number
123-
# ) = alg.chevalley_basis[1] = B
124-
125-
# set_positive_roots!(
126-
# alg::LieAlgebra,
127-
# B::Vector{Vector{T}} where T <: Number
128-
# ) = alg.chevalley_basis[2] = B
129-
130-
# set_negative_roots!(
131-
# alg::LieAlgebra,
132-
# B::Vector{Vector{T}} where T <: Number
133-
# ) = alg.chevalley_basis[3] = B
134-
112+
positive_root_elements(
113+
alg::LieAlgebra
114+
) = [LieAlgebraElem(alg, coeffs, root) for (coeffs, root) in zip(alg.basis.positive, alg.basis.positive_roots)]
115+
negative_root_elements(
116+
alg::LieAlgebra
117+
) = [LieAlgebraElem(alg, coeffs, root) for (coeffs, root) in zip(alg.basis.negative, alg.basis.negative_roots)]
135118
weight_structure(alg::LieAlgebra) = alg.weight_structure
136119
weights(alg::LieAlgebra) = alg.weight_structure.weights
137120
weights(alg::LieAlgebra, inds...) = getindex(alg.weight_structure.weights, inds...)
138121
nweights(alg::LieAlgebra) = nweights(alg.weight_structure)
139122
weight_spaces(alg::LieAlgebra) = alg.weight_structure.weight_spaces
140123
weight_spaces(alg::LieAlgebra, inds...) = getindex(alg.weight_structure.weight_spaces, inds...)
124+
hw_spaces(alg::LieAlgebra) = alg.hw_spaces
141125

142126

143127
struct SumLieAlgebra <: AbstractLieAlgebra
@@ -148,7 +132,7 @@ end
148132
name(g::SumLieAlgebra) = g.name
149133
algebras(g::SumLieAlgebra) = g.algs
150134
dim(g::SumLieAlgebra) = sum([dim(alg) for alg in algebras(g)])
151-
LinearAlgebra.rank(g::SumLieAlgebra) = sum([rank(alg) for alg in algebras(g)])
135+
MultivariateInterpolation.rank(g::SumLieAlgebra) = sum([rank(alg) for alg in algebras(g)])
152136

153137
(
154138
alg₁::AbstractLieAlgebra,

0 commit comments

Comments
 (0)