diff --git a/src/mstructures.jl b/src/mstructures.jl index d299a75..53c638f 100644 --- a/src/mstructures.jl +++ b/src/mstructures.jl @@ -14,19 +14,19 @@ function Base.showerror(io::IO, ex::ProductNotWellDefined) end """ - MultiplicativeStructure{I} + MultiplicativeStructure{T} Structure representing multiplication w.r.t its basis. Implements -* `basis(ms::MultiplicativeStructure{I}) → AbstractBasis{T,I}` -* `Basis.getindex(ms::MultiplicativeStructure{I}, i::I, j::I) → +* `basis(ms::MultiplicativeStructure{T}) → AbstractBasis{T}` +* `Basis.getindex(ms::MultiplicativeStructure{T}, i::T, j::T) → Union{AbstractCoefficients, AbstractVector}` the product of `i` and `j` represented by coefficients in `basis(ms)`. When the product is not representable faithfully, `ProductNotWellDefined` exception should be thrown. """ -abstract type MultiplicativeStructure{I} end +abstract type MultiplicativeStructure{T} end function mul!( ms::MultiplicativeStructure, @@ -44,24 +44,17 @@ function mul!( return res end -struct LazyMStructure{I,B<:AbstractBasis} <: MultiplicativeStructure{I} +struct LazyMStructure{T,B<:AbstractBasis{T}} <: MultiplicativeStructure{T} basis::B end -LazyMStructure(basis::AbstractBasis{T,I}) where {T,I} = - LazyMStructure{I,typeof(basis)}(basis) +LazyMStructure(basis::AbstractBasis{T}) where {T} = + LazyMStructure{T,typeof(basis)}(basis) basis(mstr::LazyMStructure) = mstr.basis -Base.@propagate_inbounds function Base.getindex( - mstr::LazyMStructure{I}, - g::I, - h::I, -) where {I} + +function Base.getindex(::LazyMStructure{<:DiracBasis{T}}, x::T, y::T) where {T} gh = g * h - gh in basis(mstr) || throw(ProductNotWellDefined(i, j, "$g · $h = $gh")) + gh in basis(mstr) || throw(ProductNotWellDefined(g, h, "$g · $h = $gh")) return DiracDelta(gh) end - -Base.@propagate_inbounds function Base.getindex(::LazyMStructure{I,<:DiracBasis{T}}, x::T, y::T) where {I,T} - return StarAlgebras.DiracDelta(x * y) -end diff --git a/src/mtables.jl b/src/mtables.jl index 37fbc52..e7da0d1 100644 --- a/src/mtables.jl +++ b/src/mtables.jl @@ -1,9 +1,18 @@ -function _star_of(basis::AbstractBasis, len::Integer) - return [basis[star(basis[i])] for i in 1:len] +function _star_of(basis::AbstractBasis, condition) + star_keys = Vector{keytype(basis)}() + k = iterate(basis) + while !isnothing(k) + elt, st = k + condition(elts, elt) || break + push!(star_keys, basis[star(elt)]) + k = iterate(basis, st) + end + return star_keys + # return [basis[star(elt)] for i in 1:len] end """ - MTable{I} + MTable{T, I} <: MultiplicativeStructure{T} Multiplicative table, stored explicitly as an AbstractMatrix{I}. Requires integer keys in `basis(mt)`. @@ -16,14 +25,20 @@ Requires integer keys in `basis(mt)`. mt[-i, j] == b[star(b[i])*b[j]] ``` """ -struct MTable{I,M<:AbstractMatrix{I},B<:AbstractBasis{I}} <: MultiplicativeStructure{I} - table::M - star_of::Vector{I} +struct MTable{ + T, + I, + B<:AbstractBasis{T,I}, + M<:AbstractMatrix{I}, + V<:AbstractVector{I}, +} <: MultiplicativeStructure{I} basis::B + table::M + star_of::V end -function MTable(basis::AbstractBasis{V,K}; size::Tuple{Int,Int}) where {V,K<:Integer} - return MTable(zeros(K, size), _star_of(basis, max(size...)), basis) +function MTable(basis::DiracBasis{T,I}; size::Tuple{Int,Int}) where {V,K<:Integer} + return MTable(zeros(K, size), _star_of(basis, (x -> x[1] < max(size...))), basis) end basis(mt::MTable) = mt.basis