Skip to content

Commit b13913f

Browse files
committed
improve new lie algebras model
1 parent fdc5b03 commit b13913f

File tree

4 files changed

+160
-43
lines changed

4 files changed

+160
-43
lines changed

src/MultivariateInterpolation.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ include("on_varieties/sampling.jl")
3030
include("on_varieties/expression_map.jl")
3131
include("on_varieties/varieties/map_graph.jl")
3232

33+
include("on_varieties/lie-symmetries/weights.jl")
3334
include("on_varieties/lie-symmetries/lie-algebras.jl")
35+
include("on_varieties/lie-symmetries/lie-reprs.jl")
3436
include("on_varieties/lie-symmetries/scalings.jl")
37+
3538
include("on_varieties/interpolation.jl")
3639

3740
end

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

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
export AbstractLieAlgebra,
2+
ScalingLieAlgebra,
3+
name,
4+
dim,
5+
LieAlgebra,
6+
basis,
7+
cartan_subalgebra,
8+
positive_roots,
9+
negative_roots,
10+
set_chevalley_basis!,
11+
set_cartan_subalgebra!,
12+
set_positive_roots!,
13+
set_negative_roots!,
14+
weight_structure,
15+
weights,
16+
nweights,
17+
weight_spaces,
18+
SumLieAlgebra,
19+
,
20+
AbstractLieAlgebraElem,
21+
LieAlgebraElem,
22+
as_matrix,
23+
act,
24+
SumLieAlgebraElem,
25+
AbstractLieAlgebraAction,
26+
LieAlgebraAction,
27+
ScalingLieAction,
28+
SumLieAlgebraAction
29+
30+
131
abstract type AbstractLieAlgebra end
232

333
struct ScalingLieAlgebra <: AbstractLieAlgebra
@@ -9,7 +39,7 @@ name(alg::ScalingLieAlgebra) = alg.name
939
dim(alg::ScalingLieAlgebra) = alg.dim
1040

1141
# Implements basic matrix Lie algebra
12-
struct LieAlgebra <: AbstractLieAlgebra
42+
mutable struct LieAlgebra <: AbstractLieAlgebra
1343
name::String
1444
basis::Vector{Matrix{ComplexF64}}
1545
chevalley_basis::Vector{Vector{Vector{ComplexF64}}} # given by coefficients in basis; [cartan, positive, negative]
@@ -96,6 +126,13 @@ struct SumLieAlgebra <: AbstractLieAlgebra
96126
algs::Vector{AbstractLieAlgebra}
97127
end
98128

129+
algebras(g::SumLieAlgebra) = g.algs
130+
name(g::SumLieAlgebra) = join([name(alg) for alg in algebras(g)], "")
131+
132+
(
133+
alg₁::LieAlgebra,
134+
alg₂::LieAlgebra
135+
) = SumLieAlgebra([alg₁, alg₂])
99136

100137
abstract type AbstractLieAlgebraElem end
101138

@@ -191,6 +228,35 @@ struct LieAlgebraAction <: AbstractLieAlgebraAction
191228
vars::Vector{Vector{Variable}}
192229
end
193230

231+
LieAlgebraAction(
232+
alg::LieAlgebra,
233+
vars::AbstractVecOrMat{Variable}
234+
) = LieAlgebraAction(alg, M2VV(hcat(vars)))
235+
236+
LieAlgebraAction(
237+
alg::LieAlgebra,
238+
vars::AbstractArray
239+
) = LieAlgebraAction(alg, M2VV(hcat(vars...)))
240+
241+
algebra(g::LieAlgebraAction) = g.alg
242+
action(g::LieAlgebraAction) = g.vars
243+
244+
function Base.show(io::IO, g::LieAlgebraAction)
245+
println(io, "LieAlgebraAction of $(name(algebra(g)))")
246+
print(io, " action: [", join([join(vars, ", ") for vars in action(g)], "], ["), "]")
247+
end
248+
249+
# TODO
250+
function are_commutative(g₁::LieAlgebraAction, g₂::LieAlgebraAction)
251+
return true
252+
end
253+
254+
function (g₁::LieAlgebraAction, g₂::LieAlgebraAction)
255+
@assert are_commutative(g₁, g₂)
256+
alg = algebra(g₁) algebra(g₂)
257+
return SumLieAlgebraAction(alg, [g₁, g₂])
258+
end
259+
194260
struct ScalingLieAction{T<:AbstractMatrix{<:Integer}} <: AbstractLieAlgebraAction
195261
alg::ScalingLieAlgebra
196262
vars::Vector{Variable}
@@ -201,3 +267,16 @@ struct SumLieAlgebraAction <: AbstractLieAlgebraAction
201267
alg::SumLieAlgebra
202268
actions::Vector{AbstractLieAlgebraAction}
203269
end
270+
271+
algebra(g::SumLieAlgebraAction) = g.alg
272+
actions(g::SumLieAlgebraAction) = g.actions
273+
nsummands(g::SumLieAlgebraAction) = length(actions(g))
274+
275+
function Base.show(io::IO, g::SumLieAlgebraAction)
276+
println(io, "SumLieAlgebraAction of $(name(algebra(g)))")
277+
for (i, a) in enumerate(actions(g))
278+
print(io, " action of $(name(algebra(a))): [")
279+
print(io, join([join(vars, ", ") for vars in action(a)], "], ["), "]")
280+
i < nsummands(g) && print(io, "\n")
281+
end
282+
end

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

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
export AbstractLieAlgebraRepresentation,
2+
IrreducibleRepresentation,
3+
space_basis,
4+
to_expressions,
5+
IsotypicComponent,
6+
mul,
7+
irreducible_components,
8+
PolynomialVectorSpace,
9+
is_upto,
10+
LieAlgebraRepresentation,
11+
space,
12+
isotypic_components
13+
114
abstract type AbstractLieAlgebraRepresentation end
215

316
struct IrreducibleRepresentation{T<:AbstractLieAlgebraAction} <: AbstractLieAlgebraRepresentation
@@ -52,10 +65,10 @@ struct PolynomialVectorSpace
5265
end
5366

5467
PolynomialVectorSpace(;
55-
variables::Vector{Variable},
68+
variables::AbstractArray,
5669
degree::Int,
5770
upto::Bool=true
58-
) = PolynomialVectorSpace(variables, degree, upto)
71+
) = PolynomialVectorSpace(Variable.(collect(flatten(variables))), degree, upto)
5972

6073
variables(V::PolynomialVectorSpace) = V.vars
6174
nvariables(V::PolynomialVectorSpace) = length(V.vars)
@@ -75,7 +88,9 @@ Base.:(==)(
7588

7689
function Base.show(io::IO, V::PolynomialVectorSpace)
7790
println(io, "PolynomialVectorSpace of dimension $(dim(V))")
78-
print(io, " variables: $(variables(V))")
91+
println(io, " $(nvariables(V)) variables: ", join(variables(V), ", "))
92+
println(io, " degree of polynomials: $(degree(V))")
93+
print(io, " homogeneous: $(!is_upto(V))")
7994
end
8095

8196

@@ -85,6 +100,11 @@ struct LieAlgebraRepresentation{T<:AbstractLieAlgebraAction} <: AbstractLieAlgeb
85100
isotypic::Vector{IsotypicComponent{T}}
86101
end
87102

103+
LieAlgebraRepresentation(
104+
action::T,
105+
V::PolynomialVectorSpace
106+
) where {T<:AbstractLieAlgebraAction} = LieAlgebraRepresentation{T}(action, V, [])
107+
88108
function LieAlgebraRepresentation(
89109
alg::LieAlgebra,
90110
V::PolynomialVectorSpace,
@@ -104,20 +124,21 @@ function LieAlgebraRepresentation(
104124
return LieAlgebraRepresentation(alg, V, var_groups, iso_comps)
105125
end
106126

107-
algebra::LieAlgebraRepresentation) = π.alg
127+
action::LieAlgebraRepresentation) = π.action
128+
algebra::LieAlgebraRepresentation) = algebra.action)
108129
space::LieAlgebraRepresentation) = π.V
109130
isotypic_components::LieAlgebraRepresentation) = π.isotypic
110131
irreducible_components::LieAlgebraRepresentation) = vcat([irreducible_components(iso) for iso in π.isotypic]...)
111-
dim::LieAlgebraRepresentation) = sum([dim(ic) for ic in isotypic_components(π)])
132+
dim::LieAlgebraRepresentation) = dim(space(π))
112133

113134
# called by Shift+Enter
114135
function Base.show(io::IO, mime::MIME"text/plain", π::LieAlgebraRepresentation)
115136
println(
116137
io,
117-
"LieAlgebraRepresentation of $(name(π.alg)) ",
138+
"LieAlgebraRepresentation of $(name(algebra(π))) ",
118139
"on the $(dim(π))-dimensional vector space:"
119140
)
120-
show(io, mime, π.var_groups)
141+
show(io, mime, action(π))
121142
# print(io, " action on variables: $(π.var_groups)")
122143
end
123144

@@ -133,6 +154,38 @@ function nullspace_as_weight_vectors(
133154
return wvs
134155
end
135156

157+
function sym_weight_structure(alg::LieAlgebra, d::Integer, mexps::Vector{<:SparseVector})
158+
d = Int(d)
159+
d == 0 && return WeightStructure([0], [[1;;]])
160+
d == 1 && return weight_structure(alg)
161+
combs = multiexponents(; degree=d, nvars=nweights(alg))
162+
new_weights_dict = Dict{Vector{Int}, Vector{typeof(combs[1])}}()
163+
for comb in combs
164+
w = sum([comb.nzval[i]*weights(alg, comb.nzind[i]) for i in 1:length(comb.nzind)])
165+
val = get(new_weights_dict, w, nothing)
166+
if isnothing(val)
167+
new_weights_dict[w] = [comb]
168+
else
169+
push!(new_weights_dict[w], comb)
170+
end
171+
end
172+
new_weights = [zeros(Int, 0) for _ in 1:length(new_weights_dict)]
173+
new_weight_spaces = [zeros(ComplexF64, 0, 0) for _ in 1:length(new_weights_dict)]
174+
for (i, (weight, combs)) in enumerate(new_weights_dict)
175+
new_weights[i] = weight
176+
Ms = [(weight_spaces(alg, comb.nzind), comb.nzval, mexps) for comb in combs]
177+
new_weight_spaces[i] = hcat(Ms...)
178+
end
179+
return WeightStructure(new_weights, new_weight_spaces)
180+
end
181+
182+
tensor_weight_structure(
183+
alg::LieAlgebra,
184+
ds::AbstractVector{<:Integer},
185+
v_mexps::Vector{<:Vector{<:SparseVector}},
186+
tensor_basis # TODO: add type
187+
) = tensor_weight_structure([sym_weight_structure(alg, d, mexps) for (d, mexps) in zip(ds, v_mexps)], tensor_basis)
188+
136189
function weight_module(
137190
alg::LieAlgebra,
138191
variables::Vector{Vector{Variable}},
@@ -159,9 +212,8 @@ end
159212

160213
# TODO: supposes that all the vars in V occur in var_groups
161214
function LieAlgebraRepresentation(
162-
alg::LieAlgebra,
163-
V::PolynomialVectorSpace;
164-
action::Vector{Vector{Variable}}
215+
action::LieAlgebraAction,
216+
V::PolynomialVectorSpace
165217
)
166218
@assert issetequal(vcat(action...), variables(V))
167219
groups_mexps = multiexponents(degree=degree(V), nvars=length(action), upto=is_upto(V))

src/on_varieties/lie-symmetries/weights.jl

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
export WeightStructure,
2+
weights,
3+
nweights,
4+
weight_spaces,
5+
WeightVector,
6+
weight,
7+
vector,
8+
WeightModule,
9+
basis,
10+
weight_structure,
11+
HighestWeightModule,
12+
highest_weight,
13+
highest_weight_vector
14+
15+
116
struct WeightStructure
217
weights::Vector{Vector{Int}}
318
weight_spaces::Vector{Matrix{ComplexF64}}
@@ -48,31 +63,6 @@ basis(hwm::HighestWeightModule) = hwm.basis
4863
highest_weight(hwm::HighestWeightModule) = weight(hwm.hw_vector)
4964
highest_weight_vector(hwm::HighestWeightModule) = hwm.hw_vector
5065

51-
function sym_weight_structure(alg::LieAlgebra, d::Integer, mexps::Vector{<:SparseVector})
52-
d = Int(d)
53-
d == 0 && return WeightStructure([0], [[1;;]])
54-
d == 1 && return weight_structure(alg)
55-
combs = multiexponents(; degree=d, nvars=nweights(alg))
56-
new_weights_dict = Dict{Vector{Int}, Vector{typeof(combs[1])}}()
57-
for comb in combs
58-
w = sum([comb.nzval[i]*weights(alg, comb.nzind[i]) for i in 1:length(comb.nzind)])
59-
val = get(new_weights_dict, w, nothing)
60-
if isnothing(val)
61-
new_weights_dict[w] = [comb]
62-
else
63-
push!(new_weights_dict[w], comb)
64-
end
65-
end
66-
new_weights = [zeros(Int, 0) for _ in 1:length(new_weights_dict)]
67-
new_weight_spaces = [zeros(ComplexF64, 0, 0) for _ in 1:length(new_weights_dict)]
68-
for (i, (weight, combs)) in enumerate(new_weights_dict)
69-
new_weights[i] = weight
70-
Ms = [(weight_spaces(alg, comb.nzind), comb.nzval, mexps) for comb in combs]
71-
new_weight_spaces[i] = hcat(Ms...)
72-
end
73-
return WeightStructure(new_weights, new_weight_spaces)
74-
end
75-
7666
function tensor_weight_structure(
7767
v_ws::Vector{WeightStructure},
7868
tensor_basis # TODO: add type
@@ -98,10 +88,3 @@ function tensor_weight_structure(
9888
end
9989
return WeightStructure(new_weights, new_weight_spaces)
10090
end
101-
102-
tensor_weight_structure(
103-
alg::LieAlgebra,
104-
ds::AbstractVector{<:Integer},
105-
v_mexps::Vector{<:Vector{<:SparseVector}},
106-
tensor_basis # TODO: add type
107-
) = tensor_weight_structure([sym_weight_structure(alg, d, mexps) for (d, mexps) in zip(ds, v_mexps)], tensor_basis)

0 commit comments

Comments
 (0)