-
Notifications
You must be signed in to change notification settings - Fork 4
/
prettyprinting.jl
174 lines (151 loc) · 4.87 KB
/
prettyprinting.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Utility
# -------
function subscript(i::Integer)
return i < 0 ? error("$i is negative") :
string(Iterators.reverse('₀' + d for d in digits(i))...)
end
function superscript(i::Integer)
if i < 0
throw(ArgumentError("$i is negative"))
else
# for some reason superscript two and three are not in the logical spots of the table
return string(map(Iterators.reverse(digits(i))) do x
return x == 2 ? '²' : x == 3 ? '³' : '⁰' + x
end...)
end
end
"""
macro objectnames(category, names)
Defines a category name and its objects, along with pretty printing functionality.
# Examples
```julia
@objectnames PMFC{2,1,0,1,0,0} 0 1 # without category name
@objectnames Fib = UFC{2,1,0,2,0} I τ # with category name
"""
macro objectnames(categoryname, names...)
if Meta.isexpr(categoryname, :(=), 2)
name = categoryname.args[1]
category = categoryname.args[2]
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
category = categoryname
constex = :()
end
ex = quote
$constex
function Object{$name}(a::Symbol)
id = findfirst(==(a), $names)
isnothing(id) && throw(ArgumentError("Unknown $($name_str) object $a."))
return Object{$name}(id)
end
function Base.show(io::IO, ::MIME"text/plain", ψ::Object{$name})
symbol = $names[ψ.id]
if get(io, :typeinfo, Any) !== Object{$name}
print(io, symbol, " ∈ 𝒪($(string($name)))")
else
print(io, symbol)
end
end
end
return esc(ex)
end
# Show and friends
# ----------------
function Base.show(io::IO, ::MIME"text/plain", ::Type{FR{R,M,N,I}}) where {R,M,N,I}
if get(io, :compact, true)
if M == 1
print(io, "FR$(superscript(R)) $(superscript(N))$(subscript(I))")
else
print(io,
"FR$(superscript(R)) $(superscript(M)) $(superscript(N))$(subscript(I))")
end
else
show(io, FR{R,M,N,I})
end
end
function Base.show(io::IO, ::MIME"text/plain", ::Type{UFC{R,M,N,I,D}}) where {R,M,N,I,D}
if get(io, :compact, true)
if M == 1
print(io,
"UFC$(superscript(R)) $(superscript(N))$(subscript(I)) $(subscript(D))")
else
print(io,
"UFC$(superscript(R)) $(superscript(M)) $(superscript(N))$(subscript(I)) $(subscript(D))")
end
else
show(io, UFC{R,M,N,I,D})
end
end
function Base.show(io::IO, ::MIME"text/plain",
::Type{PMFC{R,M,N,I,D₁,D₂}}) where {R,M,N,I,D₁,D₂}
if get(io, :compact, true)
if M == 1
print(io,
"PMFC$(superscript(R)) $(superscript(N))$(subscript(I)) $(subscript(D₁)) $(subscript(D₂))")
else
print(io,
"PMFC$(superscript(R)) $(superscript(M)) $(superscript(N))$(subscript(I)) $(subscript(D₁)) $(subscript(D₂))")
end
else
show(io, PMFC{R,M,N,I,D₁,D₂})
end
end
function Base.show(io::IO, ::MIME"text/plain", ψ::Object{FR}) where {FR<:FusionRing}
if get(io, :typeinfo, Any) !== Object{FR}
print(io, ψ.id, " ∈ 𝒪(", FR, ")")
else
print(io, ψ.id)
end
end
# Grouplike things
# ----------------
abstract type D{N} <: TensorKit.Group end
const D₃ = D{3}
const D₄ = D{4}
const D₅ = D{5}
const D₆ = D{6}
abstract type S{N} <: TensorKit.Group end
const S₃ = S{3} # == D₃
const S₄ = S{4}
function Base.getindex(::TensorKit.IrrepTable, G::Type{D{N}}) where {N}
𝒞 = N == 3 ? RepD3 :
N == 4 ? RepD4 :
N == 5 ? RepD5 :
N == 6 ? RepD7 :
throw(ArgumentError("Rep[D{$N}] not implemented."))
return Object{𝒞}
end
function Base.getindex(::TensorKit.IrrepTable, G::Type{S{N}}) where {N}
𝒞 = N == 3 ? RepS3 :
N == 4 ? RepS4 :
throw(ArgumentError("Rep[S{$N}] not implemented."))
return Object{𝒞}
end
# Centers
# -------
struct CenterTable end
"""
const Ƶ
A constant of singleton type used as `Ƶ[C]` with `C<:FusionCategory` to construct or obtain
the concrete type of the center of the category `C`.
"""
const Ƶ = CenterTable()