Skip to content

Commit

Permalink
Update printing and @objectnames
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Oct 4, 2023
1 parent 1f2480f commit 5336aed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/CategoryData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ using SparseArrayKit

export FusionRing, FusionCategory, BraidedCategory
export FR, UFC, PMFC
export RepA4, E6
export RepA4, E6, Fib, Ising
export Object
export multiplicity, rank
export multiplicity, rank, algebraic_structure, selfduality

include("categories.jl")
include("objects.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/aliases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ const Z6 = PMFC{6,1,4,1,0,0}
const H2 = UFC{6,1,2,8,2}
const H3 = UFC{6,1,2,8,3}

@objectnames Fib = UFC{2,1,0,2,0} I τ
@objectnames Fib = PMFC{2,1,0,2,0,0} I τ
@objectnames Ising = PMFC{3,1,0,1,1,3} I σ ψ
@objectnames H1 = UFC{4,2,0,1,0} I μ η ν
4 changes: 4 additions & 0 deletions src/objects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ struct Object{F} <: Sector where {F<:FusionRing}
end
end

function algebraic_structure(::Union{Type{Object{F}}, Object{F}}) where {F}
return F
end

Base.isless(a::Object{F}, b::Object{F}) where {F} = isless(a.id, b.id)
Base.hash(a::Object{F}, h::UInt) where {F} = hash(a.id, h)
Base.convert(::Type{F}, d::Integer) where {F<:Object} = F(d)
Expand Down
25 changes: 20 additions & 5 deletions src/prettyprinting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
"""
macro objectnames(category, names)
Defines a category name and its objects, along with an export statement.
Defines a category name and its objects, along with pretty printing functionality.
# Examples
Expand All @@ -31,9 +31,24 @@ macro objectnames(categoryname, names...)
if Meta.isexpr(categoryname, :(=), 2)
name = categoryname.args[1]
category = categoryname.args[2]
constex = quote
const $name = $category
export $name
name_str = string(name)
constex = if __module__ == CategoryData
quote
const $name = $category
function Base.show(io::IO, ::MIME"text/plain", ::Type{$name})
return print(io, $name_str)
end
end
else
quote
const $name = $category
function Base.show(io::IO, ::Type{$name})
return print(io, $name_str)
end
function Base.show(io::IO, ::MIME"text/plain", ::Type{$name})
return print(io, $name_str)
end
end
end
else
name = categoryname
Expand All @@ -45,7 +60,7 @@ macro objectnames(categoryname, names...)
$constex
function Object{$name}(a::Symbol)
id = findfirst(==(a), $names)
isnothing(id) && throw(ArgumentError("Unknown $(string($name)) object $a."))
isnothing(id) && throw(ArgumentError("Unknown $($name_str) object $a."))
return Object{$name}(id)
end

Expand Down

0 comments on commit 5336aed

Please sign in to comment.