Skip to content

Commit

Permalink
the same for similar functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Feb 16, 2024
1 parent 75d299d commit 5b69bca
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 104 deletions.
11 changes: 0 additions & 11 deletions experimental/LieAlgebras/docs/src/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,3 @@ tensor_power(::LieAlgebraModule{C}, ::Int) where {C<:FieldElem}
abstract_module(::LieAlgebra{C}, ::Int, ::Vector{<:MatElem{C}}, ::Vector{<:VarName}; ::Bool) where {C<:FieldElem}
abstract_module(::LieAlgebra{C}, ::Int, ::Matrix{SRow{C}}, ::Vector{<:VarName}; ::Bool) where {C<:FieldElem}
```

# Type-dependent getters

```@docs
is_standard_module(::LieAlgebraModule)
is_dual(::LieAlgebraModule)
is_direct_sum(::LieAlgebraModule)
is_tensor_product(::LieAlgebraModule)
is_symmetric_power(::LieAlgebraModule)
is_tensor_power(::LieAlgebraModule)
```
88 changes: 44 additions & 44 deletions experimental/LieAlgebras/src/LieAlgebraModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ function Base.show(io::IO, ::MIME"text/plain", V::LieAlgebraModule)
io = pretty(io)
println(io, _module_type_to_string(V))
println(io, Indent(), "of dimension $(dim(V))")
if is_dual(V)[1] ||
is_direct_sum(V)[1] ||
is_tensor_product(V)[1] ||
if _is_dual(V)[1] ||
_is_direct_sum(V)[1] ||
_is_tensor_product(V)[1] ||
_is_exterior_power(V)[1] ||
is_symmetric_power(V)[1] ||
is_tensor_power(V)[1]
_is_symmetric_power(V)[1] ||
_is_tensor_power(V)[1]
_show_inner(io, V)
end
print(io, Dedent())
Expand All @@ -169,21 +169,21 @@ function Base.show(io::IO, ::MIME"text/plain", V::LieAlgebraModule)
end

function _show_inner(io::IO, V::LieAlgebraModule)
if is_standard_module(V)
if _is_standard_module(V)
println(io, "standard module")
elseif ((fl, W) = is_dual(V); fl)
elseif ((fl, W) = _is_dual(V); fl)
println(io, "dual of ", Lowercase())
print(io, Indent())
_show_inner(io, W)
print(io, Dedent())
elseif ((fl, Ws) = is_direct_sum(V); fl)
elseif ((fl, Ws) = _is_direct_sum(V); fl)
println(io, "direct sum with direct summands")
print(io, Indent())
for W in Ws
_show_inner(io, W)
end
print(io, Dedent())
elseif ((fl, Ws) = is_tensor_product(V); fl)
elseif ((fl, Ws) = _is_tensor_product(V); fl)
println(io, "tensor product with tensor factors")
print(io, Indent())
for W in Ws
Expand All @@ -195,12 +195,12 @@ function _show_inner(io::IO, V::LieAlgebraModule)
print(io, Indent())
_show_inner(io, W)
print(io, Dedent())
elseif ((fl, W, k) = is_symmetric_power(V); fl)
elseif ((fl, W, k) = _is_symmetric_power(V); fl)
println(io, "$(ordinal_number_string(k)) symmetric power of")
print(io, Indent())
_show_inner(io, W)
print(io, Dedent())
elseif ((fl, W, k) = is_tensor_power(V); fl)
elseif ((fl, W, k) = _is_tensor_power(V); fl)
println(io, "$(ordinal_number_string(k)) tensor power of")
print(io, Indent())
_show_inner(io, W)
Expand All @@ -221,19 +221,19 @@ function Base.show(io::IO, V::LieAlgebraModule)
end

function _module_type_to_string(V::LieAlgebraModule)
if is_standard_module(V)
if _is_standard_module(V)
return "Standard module"
elseif is_dual(V)[1]
elseif _is_dual(V)[1]
return "Dual module"
elseif is_direct_sum(V)[1]
elseif _is_direct_sum(V)[1]
return "Direct sum module"
elseif is_tensor_product(V)[1]
elseif _is_tensor_product(V)[1]
return "Tensor product module"
elseif _is_exterior_power(V)[1]
return "Exterior power module"
elseif is_symmetric_power(V)[1]
elseif _is_symmetric_power(V)[1]
return "Symmetric power module"
elseif is_tensor_power(V)[1]
elseif _is_tensor_power(V)[1]
return "Tensor power module"
else
return "Abstract Lie algebra module"
Expand Down Expand Up @@ -354,24 +354,24 @@ function (V::LieAlgebraModule{C})(
) where {C<:FieldElem}
if length(a) == 1 && V === parent(a[1])
return a[1]
elseif ((fl, W) = is_dual(V); fl)
elseif ((fl, W) = _is_dual(V); fl)
@req length(a) == 1 "Invalid input length."
@req W === parent(v) "Incompatible modules."
return V(coefficients(v))
elseif ((fl, Vs) = is_direct_sum(V); fl)
elseif ((fl, Vs) = _is_direct_sum(V); fl)
@req length(a) == length(Vs) "Invalid input length."
@req all(i -> parent(a[i]) === Vs[i], 1:length(a)) "Incompatible modules."
return sum(inji(ai) for (ai, inji) in zip(a, canonical_injections(V)); init=zero(V))
elseif is_tensor_product(V)[1]
elseif _is_tensor_product(V)[1]
pure = get_attribute(V, :tensor_pure_function)
return pure(a)::elem_type(V)
elseif _is_exterior_power(V)[1]
pure = get_attribute(V, :wedge_pure_function)
return pure(a)::elem_type(V)
elseif is_symmetric_power(V)[1]
elseif _is_symmetric_power(V)[1]
pure = get_attribute(V, :mult_pure_function)
return pure(a)::elem_type(V)
elseif is_tensor_power(V)[1]
elseif _is_tensor_power(V)[1]
pure = get_attribute(V, :tensor_pure_function)
return pure(a)::elem_type(V)
else
Expand All @@ -384,15 +384,15 @@ function (V::LieAlgebraModule{C})(a::LieAlgebraModuleElem{C}...) where {C<:Field
end

function _is_allowed_input_length(V::LieAlgebraModule, a::Int)
if ((fl, Vs) = is_direct_sum(V); fl)
if ((fl, Vs) = _is_direct_sum(V); fl)
return a == length(Vs)
elseif ((fl, Vs) = is_tensor_product(V); fl)
elseif ((fl, Vs) = _is_tensor_product(V); fl)
return a == length(Vs)
elseif ((fl, W, k) = _is_exterior_power(V); fl)
return a == k
elseif ((fl, W, k) = is_symmetric_power(V); fl)
elseif ((fl, W, k) = _is_symmetric_power(V); fl)
return a == k
elseif ((fl, W, k) = is_tensor_power(V); fl)
elseif ((fl, W, k) = _is_tensor_power(V); fl)
return a == k
else
throw(ArgumentError("Invalid input."))
Expand Down Expand Up @@ -518,11 +518,11 @@ end
###############################################################################

@doc raw"""
is_standard_module(V::LieAlgebraModule{C}) -> Bool
_is_standard_module(V::LieAlgebraModule{C}) -> Bool
Check whether `V` has been constructed as a standard module.
"""
function is_standard_module(V::LieAlgebraModule)
function _is_standard_module(V::LieAlgebraModule)
if has_attribute(V, :is_standard_module)
@assert get_attribute(V, :is_standard_module)::Bool === true
return true
Expand All @@ -531,13 +531,13 @@ function is_standard_module(V::LieAlgebraModule)
end

@doc raw"""
is_dual(V::LieAlgebraModule{C}) -> Bool, LieAlgebraModule{C}
_is_dual(V::LieAlgebraModule{C}) -> Bool, LieAlgebraModule{C}
Check whether `V` has been constructed as a dual module.
If it has, return `true` and the base module.
If not, return `false` as the first return value, and an arbitrary value for the second.
"""
function is_dual(V::LieAlgebraModule)
function _is_dual(V::LieAlgebraModule)
if has_attribute(V, :is_dual)
W = get_attribute(V, :is_dual)::typeof(V)
return (true, W)
Expand All @@ -546,13 +546,13 @@ function is_dual(V::LieAlgebraModule)
end

@doc raw"""
is_direct_sum(V::LieAlgebraModule{C}) -> Bool, Vector{LieAlgebraModule{C}}
_is_direct_sum(V::LieAlgebraModule{C}) -> Bool, Vector{LieAlgebraModule{C}}
Check whether `V` has been constructed as a direct sum of modules.
If it has, return `true` and the summands.
If not, return `false` as the first return value, and an empty vector for the second.
"""
function is_direct_sum(V::LieAlgebraModule)
function _is_direct_sum(V::LieAlgebraModule)
if has_attribute(V, :is_direct_sum)
summands = get_attribute(V, :is_direct_sum)::Vector{typeof(V)}
return (true, summands)
Expand All @@ -561,13 +561,13 @@ function is_direct_sum(V::LieAlgebraModule)
end

@doc raw"""
is_tensor_product(V::LieAlgebraModule{C}) -> Bool, Vector{LieAlgebraModule{C}}
_is_tensor_product(V::LieAlgebraModule{C}) -> Bool, Vector{LieAlgebraModule{C}}
Check whether `V` has been constructed as a tensor product of modules.
If it has, return `true` and the tensor factors.
If not, return `false` as the first return value, and an empty vector for the second.
"""
function is_tensor_product(V::LieAlgebraModule)
function _is_tensor_product(V::LieAlgebraModule)
if has_attribute(V, :is_tensor_product)
factors = get_attribute(V, :is_tensor_product)::Vector{typeof(V)}
return (true, factors)
Expand All @@ -591,13 +591,13 @@ function _is_exterior_power(V::LieAlgebraModule)
end

@doc raw"""
is_symmetric_power(V::LieAlgebraModule{C}) -> Bool, LieAlgebraModule{C}, Int
_is_symmetric_power(V::LieAlgebraModule{C}) -> Bool, LieAlgebraModule{C}, Int
Check whether `V` has been constructed as an symmetric power of a module.
If it has, return `true`, the base module, and the power.
If not, return `false` as the first return value, and arbitrary values for the other two.
"""
function is_symmetric_power(V::LieAlgebraModule)
function _is_symmetric_power(V::LieAlgebraModule)
if has_attribute(V, :is_symmetric_power)
W, k = get_attribute(V, :is_symmetric_power)::Tuple{typeof(V),Int}
return (true, W, k)
Expand All @@ -606,13 +606,13 @@ function is_symmetric_power(V::LieAlgebraModule)
end

@doc raw"""
is_tensor_power(V::LieAlgebraModule{C}) -> Bool, LieAlgebraModule{C}, Int
_is_tensor_power(V::LieAlgebraModule{C}) -> Bool, LieAlgebraModule{C}, Int
Check whether `V` has been constructed as a tensor power of a module.
If it has, return `true`, the base module, and the power.
If not, return `false` as the first return value, and arbitrary values for the other two.
"""
function is_tensor_power(V::LieAlgebraModule)
function _is_tensor_power(V::LieAlgebraModule)
if has_attribute(V, :is_tensor_power)
W, k = get_attribute(V, :is_tensor_power)::Tuple{typeof(V),Int}
return (true, W, k)
Expand Down Expand Up @@ -797,7 +797,7 @@ function dual(V::LieAlgebraModule{C}; cached::Bool=true) where {C<:FieldElem}
-transpose(transformation_matrix(V, i))
end

s = if is_standard_module(V)
s = if _is_standard_module(V)
[Symbol("$(s)*") for s in symbols(V)]
else
[Symbol("($(s))*") for s in symbols(V)]
Expand Down Expand Up @@ -855,7 +855,7 @@ function direct_sum(V::LieAlgebraModule{C}, Vs::LieAlgebraModule{C}...) where {C
else
[
Symbol("$s^($j)") for (j, Vj) in enumerate(Vs) for
s in (is_standard_module(Vj) ? symbols(Vj) : (x -> "($x)").(symbols(Vj)))
s in (_is_standard_module(Vj) ? symbols(Vj) : (x -> "($x)").(symbols(Vj)))
]
end

Expand Down Expand Up @@ -926,7 +926,7 @@ function tensor_product(
Symbol(join(s, (is_unicode_allowed() ? "" : "(x)"))) for s in
reverse.(
ProductIterator([
is_standard_module(Vi) ? symbols(Vi) : (x -> "($x)").(symbols(Vi)) for
_is_standard_module(Vi) ? symbols(Vi) : (x -> "($x)").(symbols(Vi)) for
Vi in reverse(Vs)
])
)
Expand Down Expand Up @@ -1049,7 +1049,7 @@ function exterior_power(
[Symbol("1")]
elseif k == 1
symbols(V)
elseif is_standard_module(V)
elseif _is_standard_module(V)
[Symbol(join(s, (is_unicode_allowed() ? "" : "^"))) for s in combinations(symbols(V), k)]
else
[
Expand Down Expand Up @@ -1185,7 +1185,7 @@ function symmetric_power(
[Symbol("1")]
elseif k == 1
symbols(V)
elseif is_standard_module(V)
elseif _is_standard_module(V)
[
Symbol(
join(
Expand Down Expand Up @@ -1336,7 +1336,7 @@ function tensor_power(
[Symbol("1")]
elseif k == 1
symbols(V)
elseif is_standard_module(V)
elseif _is_standard_module(V)
[
Symbol(join(s, (is_unicode_allowed() ? "" : "(x)"))) for
s in reverse.(ProductIterator(symbols(V), k))
Expand Down
Loading

0 comments on commit 5b69bca

Please sign in to comment.