Skip to content

Commit 20e0f89

Browse files
committed
add pretty printing for SumLieAlgebraAction
1 parent 6cd4c8f commit 20e0f89

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

src/interpolation_bases/monomials.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ prodpow(
221221
e::AbstractSparseVector
222222
) = prod(view(M,e.nzind,:).^e.nzval; dims=1)
223223

224+
HC.evaluate(
225+
mons::MonomialBasis,
226+
sample::AbstractVector
227+
) = [prodpow(sample, mexp) for mexp in mons.mexps]
228+
224229
function HC.evaluate(
225230
mons::MonomialBasis,
226231
samples::AbstractMatrix{T}
@@ -233,9 +238,9 @@ function HC.evaluate(
233238
end
234239

235240
Base.getindex(
236-
mons::MonomialBasis{Tv,Ti} where {Tv<:Integer,Ti<:Integer},
241+
mons::MonomialBasis{Tv,Ti},
237242
inds...
238-
) = MonomialBasis{Tv,Ti}(getindex(mons.mexps, inds...), mons.vars)
243+
) where {Tv<:Integer,Ti<:Integer} = MonomialBasis{Tv,Ti}(getindex(mons.mexps, inds...), mons.vars)
239244
Base.getindex(mons::MonomialBasis, ind::Int) = Monomial(mons.mexps[ind], mons.vars)
240245

241246
Base.findfirst(

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

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ algebra(a::ScalingLieAction) = a.alg
3131
variables(a::ScalingLieAction) = a.vars
3232
exponents(a::ScalingLieAction) = a.alg.exps
3333

34-
function Base.show(io::IO, a::ScalingLieAction)
35-
println(io, "ScalingLieAction of $(name(algebra(a)))")
36-
print(io, " action:")
34+
function show_action(io::IO, a::ScalingLieAction; offset::Int=0, show_name::Bool=false)
35+
if show_name
36+
print(io, " "^offset, "scaling algebra $(name(algebra(a))): ")
37+
offset += 1
38+
end
3739
U = exponents(a)
3840
if size(U, 1) == 1
3941
@var λ
@@ -49,14 +51,20 @@ function Base.show(io::IO, a::ScalingLieAction)
4951
action[j] = collect(zip(vars[nzind], exprs))
5052
end
5153
for free_action in action
52-
print(io, "\n ")
54+
print(io, "\n", " "^offset)
5355
for (j, (var, expr)) in enumerate(free_action)
5456
print(io, var, "", expr)
5557
j < length(free_action) && print(io, ", ")
5658
end
5759
end
5860
end
5961

62+
function Base.show(io::IO, a::ScalingLieAction)
63+
println(io, "ScalingLieAction of $(name(algebra(a)))")
64+
print(io, " action:")
65+
show_action(io, a; offset=2)
66+
end
67+
6068
function act(elem::LieAlgebraElem{ScalingLieAlgebra}, f::Union{Expression, Monomial}, action::ScalingLieAction)
6169
X = as_matrix(elem)
6270
return expand(dot(differentiate(f, variables(action)), -X*variables(action)))
@@ -113,9 +121,19 @@ weights(a::LieAlgebraAction) = weights(a.alg)
113121
weights(a::LieAlgebraAction, inds...) = weights(a.alg, inds...)
114122
nweights(a::LieAlgebraAction) = nweights(a.alg)
115123

124+
function show_action(io::IO, a::LieAlgebraAction; offset::Int=0, show_name::Bool=false)
125+
if show_name
126+
print(io, " "^offset, "$(name(algebra(a))): ")
127+
print(io, "[", join([join(vars, ", ") for vars in var_groups(a)], "], ["), "]")
128+
else
129+
print(io, " "^offset, "[", join([join(vars, ", ") for vars in var_groups(a)], "], ["), "]")
130+
end
131+
end
132+
116133
function Base.show(io::IO, a::LieAlgebraAction)
117134
println(io, "LieAlgebraAction of $(name(algebra(a)))")
118-
print(io, " action: [", join([join(vars, ", ") for vars in var_groups(a)], "], ["), "]")
135+
print(io, " action: ")
136+
show_action(io, a; offset=0)
119137
end
120138

121139
function act(elem::LieAlgebraElem{LieAlgebra}, f::Union{Expression, Monomial}, action::LieAlgebraAction)
@@ -157,12 +175,11 @@ Base.getindex(a::SumLieAlgebraAction, i::Int) = actions(a)[i]
157175

158176
function Base.show(io::IO, a::SumLieAlgebraAction)
159177
println(io, "SumLieAlgebraAction of $(name(algebra(a)))")
160-
# for (i, a) in enumerate(actions(g))
161-
# print(io, " action of $(name(algebra(a))): [")
162-
# print(io, join([join(vars, ", ") for vars in var_groups(a)], "], ["), "]")
163-
# i < nsummands(g) && print(io, "\n")
164-
# end
165-
print(io, " action: ")
178+
print(io, " action:")
179+
for action in actions(a)
180+
println(io)
181+
show_action(io, action; offset=2, show_name=true)
182+
end
166183
end
167184

168185
# TODO

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function Base.show(io::IO, ::MIME"text/plain", ρ::LieAlgebraRepresentation)
4646
)
4747
println(io, " Lie algebra: ", name(algebra(ρ)))
4848
println(io, " number of isotypic components: ", nisotypic(ρ))
49-
print(io, " dimensions of isotypic components: ", join([dim(ic) for ic in isotypic_components(ρ)], ", "))
49+
println(io, " dimensions of isotypic components: ", join([dim(ic) for ic in isotypic_components(ρ)], ", "))
50+
print(io, " multiplicities of irreducible representations: ", join([nirreducible(ic) for ic in isotypic_components(ρ)], ", "))
5051
end
5152

5253
# called by print and inside vectors/matrices

src/on_varieties/lie-symmetries/weights.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export WeightStructure,
1515
sum_weight_structure
1616

1717

18+
# TODO: change to SparseVector
1819
struct WeightVector
1920
weight::Vector{Int}
2021
vector::Vector{ComplexF64}
@@ -24,6 +25,7 @@ weight(wv::WeightVector) = wv.weight
2425
vector(wv::WeightVector) = wv.vector
2526
Base.setindex!(wv::WeightVector, n::Number, i::Integer) = wv.vector[i] = n
2627

28+
# TODO: change to SparseMatrix
2729
mutable struct WeightSpace
2830
weight::Vector{Int}
2931
matrix::Matrix{ComplexF64}
@@ -172,16 +174,6 @@ end
172174

173175
Base.:(ws::Vector{WeightStructure}) = reduce(, ws)
174176

175-
# function sum_weight_structure(ws::WeightStructure, d::Integer)
176-
# new_weight_spaces = [zeros(ComplexF64, space_dim(ws)*d, size(M, 2)*d) for M in weight_spaces(ws)]
177-
# for (M, new_M) in zip(weight_spaces(ws), new_weight_spaces)
178-
# for j in 1:d
179-
# new_M[(1:space_dim(ws)) .+ (j-1)*space_dim(ws), (1:size(M,2)) .+ (j-1)*size(M,2)] = M
180-
# end
181-
# end
182-
# return WeightStructure(weights(ws), new_weight_spaces)
183-
# end
184-
185177
function sym_weight_structure(ws::WeightStructure, d::Integer, mexps::Vector{<:SparseVector})
186178
d = Int(d)
187179
d == 0 && return WeightStructure([zeros(Int, weight_size(ws))], [[1;;]])

0 commit comments

Comments
 (0)