Skip to content

Commit

Permalink
give it a try with different parametrization of MStructures
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Dec 7, 2023
1 parent 77ac453 commit 00c977a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
27 changes: 10 additions & 17 deletions src/mstructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
31 changes: 23 additions & 8 deletions src/mtables.jl
Original file line number Diff line number Diff line change
@@ -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)`.
Expand All @@ -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
Expand Down

0 comments on commit 00c977a

Please sign in to comment.