Skip to content

Commit 1a5823a

Browse files
committed
add colored info output
1 parent c675fec commit 1a5823a

File tree

17 files changed

+301
-227
lines changed

17 files changed

+301
-227
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "1.0.0-DEV"
55

66
[deps]
77
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
8+
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
89
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
910
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1011
LinearAlgebraX = "9b3f67b0-2d00-526e-9884-9e4938f8fb88"

src/DecomposingRepresentations.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export @polyvar, Variable, Monomial, Polynomial, Commutative, CreationOrder, Gra
1111
using Combinatorics: partitions, multiset_permutations, combinations, with_replacement_combinations
1212

1313
using Base.Iterators: product, flatten
14+
using Crayons
1415

1516
include("utils/basic.jl")
1617
include("utils/Gauss-Jordan.jl")

src/decompositions/irred-decomp.jl

Lines changed: 102 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ function ws_nullspace(
44
X::AbstractLieAlgebraElem,
55
a::AbstractGroupAction{Lie},
66
ws::WeightSpace;
7-
tol::Real=1e-5
7+
tol::Real=1e-5,
8+
logging::Bool=true
89
)
910
B = basis(space(ws))
1011
Bₐ = [act(X, a, f) for f in B]
12+
13+
logging && print(crayon"#f4d03f", "Applied 'act' method $(dim(space(ws))) times\n")
14+
1115
if all(f -> isapprox(f, zero(f), atol=tol), Bₐ)
1216
return ws
1317
end
@@ -16,28 +20,43 @@ function ws_nullspace(
1620
isempty(Cs) && return nothing
1721
return WeightSpace(
1822
weight(ws),
19-
PolySpace{field_type(ws)}([sum(c .* B) for c in Cs])
23+
PolySpace{field_type(ws)}([div_by_smallest_coeff(sum(c .* B)) for c in Cs])
2024
)
2125
end
2226

2327
function common_nullspace_as_weight_vectors(
2428
Xs::Vector{<:AbstractLieAlgebraElem},
2529
a::AbstractGroupAction{Lie},
26-
ws::WeightSpace
30+
ws::WeightSpace,
31+
nhwv::Int;
32+
logging::Bool=true
2733
)
34+
dim(ws) == 1 && return [WeightVector(weight(ws), v) for v in basis(space(ws))]
35+
36+
logging && printstyled("Looking for the highest weight vectors in $(str_irr("W", weight(ws))) of dimension $(dim(ws))...\n", color=:green)
2837
wsₙ = ws
2938
for X in Xs
3039
wsₙ = ws_nullspace(X, a, wsₙ)
3140
isnothing(wsₙ) && return WeightVector[]
3241
end
33-
return [WeightVector(weight(wsₙ), div_by_smallest_coeff(v)) for v in basis(space(wsₙ))]
42+
43+
@assert dim(wsₙ) == nhwv
44+
logging && printstyled("Found: ", color=:green)
45+
logging && printstyled("$(join(map(repr, basis(space(wsₙ))), ", "))\n", color=:green)
46+
47+
return [WeightVector(weight(wsₙ), div_by_smallest_coeff(v)) for v in basis(space(wsₙ))] # TODO: remove div_by_smallest_coeff
3448
end
3549

36-
common_nullspace_as_weight_vectors(
50+
function common_nullspace_as_weight_vectors(
3751
Xs::Vector{<:AbstractLieAlgebraElem},
3852
a::AbstractGroupAction{Lie},
39-
ws::WeightStructure
40-
) = vcat([common_nullspace_as_weight_vectors(Xs, a, w) for w in ws]...)
53+
ws::WeightStructure,
54+
cg_decomp::Dict{<:Weight, Int}
55+
)
56+
return vcat([begin
57+
common_nullspace_as_weight_vectors(Xs, a, ws[w], cg_decomp[w])
58+
end for w in weights(ws)]...)
59+
end
4160

4261
function irreducibles(
4362
ρ::GroupRepresentation{A, T}
@@ -50,135 +69,111 @@ function irreducibles(
5069
end
5170

5271
function irreducibles(
53-
ρ::GroupRepresentation{A, S}
72+
ρ::GroupRepresentation{A, S};
73+
logging::Bool=true
5474
) where {A<:AbstractGroupAction{Lie}, S<:VariableSpace}
55-
ws = weight_structure(action(ρ), space(ρ))
56-
Xs = positive_root_elements(algebra(action(ρ)))
57-
hw_vectors = common_nullspace_as_weight_vectors(Xs, action(ρ), ws)
75+
logging && printstyled("Decomposing the space of variables $(to_string(space(ρ))) into irreducibles...\n", color=:red)
76+
77+
hws = hw_spaces(action(ρ), space(ρ))
78+
hw_vectors = [hwv for ws in hws for hwv in ws]
79+
80+
logging && printstyled("$(join(map(repr, basis(space(ρ))), ", "))⟩ = ", color=:red)
81+
logging && printstyled(join([str_irr("V", weight(hwv)) for hwv in hw_vectors], ""), "\n", color=:red)
82+
logging && printstyled("$(length(hw_vectors)) irreducibles\n", color=:red)
83+
5884
return [IrreducibleRepresentation(action(ρ), hwv) for hwv in hw_vectors]
5985
end
6086

61-
# function irreducibles_old(
62-
# ρ::GroupRepresentation{A, S}
63-
# ) where {T, F, A<:AbstractGroupAction{Lie}, S<:SymmetricPower{T, F, <:HighestWeightModule}}
64-
# V = space(ρ)
65-
# power(V) == 1 && return [IrreducibleRepresentation(action(ρ), base_space(V))]
66-
# ws = weight_structure(base_space(V))
67-
# sym_ws = sym(ws, power(V))
68-
# println("old nweights: ", nweights(sym_ws))
69-
# println("old sum of dims: ", sum([dim(space(sym_ws[w])) for w in weights(sym_ws)]))
70-
# Xs = positive_root_elements(algebra(action(ρ)))
71-
# hw_vectors = common_nullspace_as_weight_vectors(Xs, action(ρ), sym_ws)
72-
# return [IrreducibleRepresentation(action(ρ), hwv) for hwv in hw_vectors]
73-
# end
74-
75-
# function irreducibles_old(
76-
# ρ::GroupRepresentation{A, T}
77-
# ) where {A<:AbstractGroupAction{Lie}, T<:SymmetricPower}
78-
# V = space(ρ)
79-
# ρ_base = GroupRepresentation(action(ρ), base_space(V))
80-
# irreds_base = irreducibles(ρ_base)
81-
# if length(irreds_base) == 1
82-
# V = SymmetricPower(space(first(irreds_base)), power(V))
83-
# ρᵢ = GroupRepresentation(action(ρ), V)
84-
# return irreducibles_old(ρᵢ)
85-
# end
86-
# mexps = multiexponents(degree=power(V), nvars=length(irreds_base))
87-
# irreds = IrreducibleRepresentation{A}[]
88-
# for mexp in mexps
89-
# Vᵢ = TensorProduct([SymmetricPower(space(irreds_base[idx]), val) for (val, idx) in zip(mexp.nzval, mexp.nzind)])
90-
# ρᵢ = GroupRepresentation(action(ρ), Vᵢ)
91-
# append!(irreds, irreducibles(ρᵢ))
92-
# end
93-
# return irreds
94-
# end
95-
9687
function irreducibles(
97-
ρ::GroupRepresentation{A, S}
88+
ρ::GroupRepresentation{A, S};
89+
logging::Bool=true
9890
) where {T, F, A<:AbstractGroupAction{Lie}, S<:SymmetricPower{T, F, <:HighestWeightModule}}
9991
V = space(ρ)
92+
logging && printstyled("Decomposing $(to_string(V)) into irreducibles...\n", color=:blue)
93+
10094
Vb = base_space(V)
10195
power(V) == 1 && return [IrreducibleRepresentation(action(ρ), Vb)]
10296
ws = weight_structure(Vb)
103-
sym_ws = sym_weight_struct(highest_weight(Vb), algebra(action(ρ)), power(V), ws)
97+
98+
logging && printstyled("Applying Clebsch-Gordan to decompose $(to_string(V)) into irreducibles...\n", color=:blue)
99+
sym_ws, cg_decomp = sym_weight_struct(highest_weight(Vb), algebra(action(ρ)), power(V), ws)
100+
logging && printstyled(to_string(V), " = ", str_irr_decomp("V", cg_decomp), "\n", color=:blue)
101+
104102
Xs = positive_root_elements(algebra(action(ρ)))
105-
hw_vectors = common_nullspace_as_weight_vectors(Xs, action(ρ), sym_ws)
103+
hw_vectors = common_nullspace_as_weight_vectors(Xs, action(ρ), sym_ws, cg_decomp)
106104
return [IrreducibleRepresentation(action(ρ), hwv) for hwv in hw_vectors]
107105
end
108106

109107
function irreducibles(
110-
ρ::GroupRepresentation{A, T}
108+
ρ::GroupRepresentation{A, T};
109+
logging::Bool=true
111110
) where {A<:AbstractGroupAction{Lie}, T<:SymmetricPower}
112111
V = space(ρ)
112+
logging && printstyled("Decomposing $(to_string(V)) into irreducibles...\n", color=:magenta)
113+
113114
ρ_base = GroupRepresentation(action(ρ), base_space(V))
114115
irreds_base = irreducibles(ρ_base)
115116
if length(irreds_base) == 1
117+
logging && printstyled("$(to_string(base_space(V))) is already irreducible, decomposing its symmetric power directly...\n", color=:magenta)
116118
V = SymmetricPower(space(first(irreds_base)), power(V))
117119
ρᵢ = GroupRepresentation(action(ρ), V)
118120
return irreducibles(ρᵢ)
119121
end
120122
mexps = multiexponents(degree=power(V), nvars=length(irreds_base))
123+
124+
Vs = [TensorProduct([SymmetricPower(space(irreds_base[idx]), val) for (val, idx) in zip(mexp.nzval, mexp.nzind)]) for mexp in mexps]
125+
if logging
126+
printstyled("Sym$(superscript(power(V)))(", color=:magenta)
127+
printstyled(join([to_string(space(irr)) for irr in irreds_base], ""), ") = ", color=:magenta)
128+
printstyled(join(["(" * to_string(V) * ")" for V in Vs], ""), color=:magenta)
129+
println()
130+
end
131+
121132
irreds = IrreducibleRepresentation{A}[]
122-
for mexp in mexps
123-
Vᵢ = TensorProduct([SymmetricPower(space(irreds_base[idx]), val) for (val, idx) in zip(mexp.nzval, mexp.nzind)])
133+
for Vᵢ in Vs
124134
ρᵢ = GroupRepresentation(action(ρ), Vᵢ)
125135
append!(irreds, irreducibles(ρᵢ))
126136
end
127137
return irreds
128138
end
129139

130140
function irreducibles(
131-
ρ::GroupRepresentation{A, S}
132-
) where {T, F, A<:AbstractGroupAction{Lie}, S<:TensorProduct{T, F, <:HighestWeightModule}}
141+
ρ::GroupRepresentation{A, S};
142+
logging::Bool=true
143+
) where {T, F, A<:AbstractGroupAction{Lie}, S<:TensorProduct{T, F, <:HighestWeightModule, <:HighestWeightModule}}
144+
logging && printstyled("Decomposing $(to_string(V)) into irreducibles...\n", color=:blue)
133145
V = space(ρ)
134-
if nfactors(V) == 2
135-
ws₁, ws₂ = weight_structure(factor(V, 1)), weight_structure(factor(V, 2)) # TODO: save once computed
136-
# println("nweights 1: ", nweights(ws₁))
137-
# println("nweights 2: ", nweights(ws₂))
138-
tensor_ws = tensor(ws₁, ws₂)
139-
# println("nweights 1 ⊗ 2: ", nweights(tensor_ws))
140-
Xs = positive_root_elements(algebra(action(ρ)))
141-
hw_vectors = common_nullspace_as_weight_vectors(Xs, action(ρ), tensor_ws)
142-
return [IrreducibleRepresentation(action(ρ), hwv) for hwv in hw_vectors]
143-
end
144-
W = TensorProduct(factors(V, [1,2]))
145-
ρW = GroupRepresentation(action(ρ), W)
146-
irrs = irreducibles(ρW)
147-
irreds = IrreducibleRepresentation{A}[]
148-
for irr in irrs
149-
Vᵣ = TensorProduct(space(irr), factors(V, 3:nfactors(V)))
150-
ρᵣ = GroupRepresentation(action(ρ), Vᵣ)
151-
append!(irreds, irreducibles(ρᵣ))
152-
end
153-
return irreds
146+
hw₁, hw₂ = highest_weight(first(V)), highest_weight(second(V))
147+
148+
logging && printstyled("Applying Clebsch-Gordan to decompose $(to_string(V)) into irreducibles...\n", color=:blue)
149+
ws₁, ws₂ = weight_structure(first(V)), weight_structure(second(V)) # TODO: save once computed
150+
tensor_ws, cg_decomp = tensor_weight_struct(hw₁, hw₂, algebra(action(ρ)), ws₁, ws₂)
151+
logging && printstyled(to_string(V), " = ", join([str_irr("V", w) for w in weights(tensor_ws)], ""), "\n", color=:blue)
152+
153+
Xs = positive_root_elements(algebra(action(ρ)))
154+
hw_vectors = common_nullspace_as_weight_vectors(Xs, action(ρ), tensor_ws, cg_decomp)
155+
return [IrreducibleRepresentation(action(ρ), hwv) for hwv in hw_vectors]
154156
end
155157

156158
function irreducibles(
157-
ρ::GroupRepresentation{A, S}
159+
ρ::GroupRepresentation{A, S};
160+
logging::Bool=true
158161
) where {A<:AbstractGroupAction{Lie}, S<:TensorProduct}
159-
if nfactors(space(ρ)) == 2
160-
irrs₁ = irreducibles(GroupRepresentation(action(ρ), factor(space(ρ), 1)))
161-
irrs₂ = irreducibles(GroupRepresentation(action(ρ), factor(space(ρ), 2)))
162-
irreds = IrreducibleRepresentation{A}[]
163-
for irr₁ in irrs₁, irr₂ in irrs₂
164-
V = TensorProduct([space(irr₁), space(irr₂)])
165-
ρV = GroupRepresentation(action(ρ), V)
166-
append!(irreds, irreducibles(ρV))
167-
end
168-
return irreds
169-
end
170-
V = TensorProduct(factors(space(ρ), 2:nfactors(space(ρ))))
171-
ρV = GroupRepresentation(action(ρ), V)
172-
irrs = irreducibles(ρV)
162+
V = space(ρ)
163+
logging && printstyled("Decomposing $(to_string(V)) into irreducibles...\n", color=:magenta)
164+
irrs₁ = irreducibles(GroupRepresentation(action(ρ), first(space(ρ))))
165+
irrs₂ = irreducibles(GroupRepresentation(action(ρ), second(space(ρ))))
166+
167+
logging && printstyled("Decomposing tensor product knowing irreducibles of the factors...\n", color=:magenta)
168+
logging && printstyled("($(join([to_string(space(irr)) for irr in irrs₁], ""))) ⊗ ", color=:magenta)
169+
logging && printstyled("($(join([to_string(space(irr)) for irr in irrs₂], ""))) = ", color=:magenta)
170+
logging && printstyled(join(["($(to_string(space(irr₁)))$(to_string(space(irr₂))))" for (irr₁, irr₂) in product(irrs₁, irrs₂)], ""), "\n", color=:magenta)
171+
173172
irreds = IrreducibleRepresentation{A}[]
174-
for irr in irrs
175-
ρ₁ = GroupRepresentation(action(ρ), factor(space(ρ), 1))
176-
irrs₁ = irreducibles(ρ₁)
177-
for irr₁ in irrs₁
178-
W = TensorProduct([space(irr₁), space(irr)])
179-
ρW = GroupRepresentation(action(ρ), W)
180-
append!(irreds, irreducibles(ρW))
181-
end
173+
for irr₁ in irrs₁, irr₂ in irrs₂
174+
V = TensorProduct([space(irr₁), space(irr₂)])
175+
ρV = GroupRepresentation(action(ρ), V)
176+
append!(irreds, irreducibles(ρV))
182177
end
183178
return irreds
184179
end
@@ -201,14 +196,19 @@ end
201196
struct IrreducibleDecomposition{A<:AbstractGroupAction{Lie}, T<:GroupRepresentation{A}, Ir<:IrreducibleRepresentation{A}}
202197
ρ::T
203198
irreds::Vector{Ir}
199+
200+
function IrreducibleDecomposition(
201+
ρ::T,
202+
irreds::Vector{Ir}
203+
) where {A<:AbstractGroupAction{Lie}, T<:GroupRepresentation{A}, Ir<:IrreducibleRepresentation{A}}
204+
@assert dim(space(ρ)) == sum([dim(space(irr)) for irr in irreds])
205+
new{A, T, Ir}(ρ, irreds)
206+
end
204207
end
205208

206-
function IrreducibleDecomposition(
209+
IrreducibleDecomposition(
207210
ρ::GroupRepresentation
208-
)
209-
irreds = irreducibles(ρ)
210-
return IrreducibleDecomposition(ρ, irreds)
211-
end
211+
) = IrreducibleDecomposition(ρ, irreducibles(ρ))
212212

213213
representation(ID::IrreducibleDecomposition) = ID.ρ
214214
action(ID::IrreducibleDecomposition) = action(ID.ρ)

src/decompositions/isotypic-decomp.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ struct IsotypicDecomposition{A<:AbstractGroupAction{Lie}, T<:GroupRepresentation
66
iso_dict::Dict{W, Ic}
77
end
88

9+
function IsotypicDecomposition(
10+
irreds::Vector{T},
11+
ρ::GroupRepresentation{A}
12+
) where {A<:AbstractGroupAction{Lie}, T<:IrreducibleRepresentation{A}}
13+
a = action(first(irreds))
14+
W = weight_type(algebra(a))
15+
iso_dict = Dict{W, IsotypicComponent}()
16+
for irr in irreds
17+
hw = highest_weight(irr)
18+
if haskey(iso_dict, hw)
19+
push!(iso_dict[hw], irr)
20+
else
21+
iso_dict[hw] = IsotypicComponent(a, hw, [irr])
22+
end
23+
end
24+
return IsotypicDecomposition(ρ, iso_dict)
25+
end
26+
927
function IsotypicDecomposition(
1028
irr_decomp::IrreducibleDecomposition{A, T, Ir}
1129
) where {A, T, Ir}
@@ -37,6 +55,9 @@ isotypic_components(ID::IsotypicDecomposition) = values(ID.iso_dict)
3755
nisotypic(ID::IsotypicDecomposition) = length(ID.iso_dict)
3856
dim(ID::IsotypicDecomposition) = dim(ID.ρ)
3957
Base.getindex(ID::IsotypicDecomposition, w::Weight) = ID.iso_dict[w]
58+
Base.length(ID::IsotypicDecomposition) = length(ID.iso_dict)
59+
Base.iterate(ID::IsotypicDecomposition) = iterate(isotypic_components(ID))
60+
Base.iterate(ID::IsotypicDecomposition, state) = iterate(isotypic_components(ID), state)
4061

4162
function Base.show(io::IO, iso::IsotypicDecomposition)
4263
println(io, "IsotypicDecomposition of $(name(group(iso)))-action on $(dim(iso))-dimensional vector space")

0 commit comments

Comments
 (0)