-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathfusiontrees.jl
More file actions
271 lines (255 loc) · 9.51 KB
/
fusiontrees.jl
File metadata and controls
271 lines (255 loc) · 9.51 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# Fusion trees:
#==============================================================================#
"""
struct FusionTree{I, N, M, L}
Represents a fusion tree of sectors of type `I<:Sector`, fusing (or splitting) `N` uncoupled
sectors to a coupled sector. It actually represents a splitting tree, but fusion tree
is a more common term.
## Fields
- `uncoupled::NTuple{N,I}`: the uncoupled sectors coming out of the splitting tree, before
the possible 𝑍 isomorphism (see `isdual`).
- `coupled::I`: the coupled sector.
- `isdual::NTuple{N,Bool}`: indicates whether a 𝑍 isomorphism is present (`true`) or not
(`false`) for each uncoupled sector.
- `innerlines::NTuple{M,I}`: the labels of the `M=max(0, N-2)` inner lines of the splitting
tree.
- `vertices::NTuple{L,Int}`: the integer values of the `L=max(0, N-1)` vertices of the
splitting tree. If `FusionStyle(I) isa MultiplicityFreeFusion`, then `vertices` is simply
equal to the constant value `ntuple(n->1, L)`.
"""
struct FusionTree{I <: Sector, N, M, L}
uncoupled::NTuple{N, I}
coupled::I
isdual::NTuple{N, Bool}
innerlines::NTuple{M, I} # M = N-2
vertices::NTuple{L, Int} # L = N-1
function FusionTree{I, N, M, L}(
uncoupled::NTuple{N, I},
coupled::I,
isdual::NTuple{N, Bool},
innerlines::NTuple{M, I},
vertices::NTuple{L, Int}
) where
{I <: Sector, N, M, L}
# if N == 0
# @assert coupled == unit(coupled)
# elseif N == 1
# @assert coupled == uncoupled[1]
# elseif N == 2
# @assert coupled ∈ ⊗(uncoupled...)
# else
# @assert innerlines[1] ∈ ⊗(uncoupled[1], uncoupled[2])
# for n = 2:N-2
# @assert innerlines[n] ∈ ⊗(innerlines[n-1], uncoupled[n+1])
# end
# @assert coupled ∈ ⊗(innerlines[N-2], uncoupled[N])
# end
return new{I, N, M, L}(uncoupled, coupled, isdual, innerlines, vertices)
end
end
function FusionTree{I}(
uncoupled::NTuple{N, Any}, coupled,
isdual::NTuple{N, Bool}, innerlines,
vertices = ntuple(n -> 1, max(0, N - 1))
) where {I <: Sector, N}
return if FusionStyle(I) isa GenericFusion
fusiontreetype(I, N)(
map(s -> convert(I, s), uncoupled),
convert(I, coupled), isdual,
map(s -> convert(I, s), innerlines), vertices
)
else
if all(isone, vertices)
fusiontreetype(I, N)(
map(s -> convert(I, s), uncoupled),
convert(I, coupled), isdual,
map(s -> convert(I, s), innerlines), vertices
)
else
throw(ArgumentError("Incorrect fusion vertices"))
end
end
end
function FusionTree(
uncoupled::NTuple{N, I}, coupled::I,
isdual::NTuple{N, Bool}, innerlines,
vertices = ntuple(n -> 1, max(0, N - 1))
) where {I <: Sector, N}
return if FusionStyle(I) isa GenericFusion
fusiontreetype(I, N)(uncoupled, coupled, isdual, innerlines, vertices)
else
if all(isone, vertices)
fusiontreetype(I, N)(uncoupled, coupled, isdual, innerlines, vertices)
else
throw(ArgumentError("Incorrect fusion vertices"))
end
end
end
function FusionTree{I}(
uncoupled::NTuple{N}, coupled = unit(I), isdual = ntuple(Returns(false), N)
) where {I <: Sector, N}
FusionStyle(I) isa UniqueFusion ||
error("fusion tree requires inner lines if `FusionStyle(I) <: MultipleFusion`")
return FusionTree{I}(
map(s -> convert(I, s), uncoupled), convert(I, coupled), isdual,
_abelianinner(map(s -> convert(I, s), (uncoupled..., dual(coupled))))
)
end
function FusionTree(
uncoupled::NTuple{N, I}, coupled::I, isdual = ntuple(n -> false, length(uncoupled))
) where {N, I <: Sector}
return FusionTree{I}(uncoupled, coupled, isdual)
end
FusionTree(uncoupled::Tuple{I, Vararg{I}}) where {I <: Sector} = FusionTree(uncoupled, unit(I))
# Properties
sectortype(::Type{<:FusionTree{I}}) where {I <: Sector} = I
FusionStyle(::Type{<:FusionTree{I}}) where {I <: Sector} = FusionStyle(I)
BraidingStyle(::Type{<:FusionTree{I}}) where {I <: Sector} = BraidingStyle(I)
Base.length(::Type{<:FusionTree{<:Sector, N}}) where {N} = N
FusionStyle(f::FusionTree) = FusionStyle(typeof(f))
BraidingStyle(f::FusionTree) = BraidingStyle(typeof(f))
Base.length(f::FusionTree) = length(typeof(f))
# Hashing, important for using fusion trees as key in a dictionary
function Base.hash(f::FusionTree{I}, h::UInt) where {I}
h = hash(f.isdual, hash(f.coupled, hash(f.uncoupled, h)))
if FusionStyle(I) isa MultipleFusion
h = hash(f.innerlines, h)
end
if FusionStyle(I) isa GenericFusion
h = hash(f.vertices, h)
end
return h
end
function Base.:(==)(f₁::FusionTree{I, N}, f₂::FusionTree{I, N}) where {I <: Sector, N}
f₁.coupled == f₂.coupled || return false
@inbounds for i in 1:N
f₁.uncoupled[i] == f₂.uncoupled[i] || return false
f₁.isdual[i] == f₂.isdual[i] || return false
end
if FusionStyle(I) isa MultipleFusion
@inbounds for i in 1:(N - 2)
f₁.innerlines[i] == f₂.innerlines[i] || return false
end
end
if FusionStyle(I) isa GenericFusion
@inbounds for i in 1:(N - 1)
f₁.vertices[i] == f₂.vertices[i] || return false
end
end
return true
end
Base.:(==)(f₁::FusionTree, f₂::FusionTree) = false
# Facilitate getting correct fusion tree types
function fusiontreetype(::Type{I}, N::Int) where {I <: Sector}
return if N === 0
FusionTree{I, 0, 0, 0}
elseif N === 1
FusionTree{I, 1, 0, 0}
else
FusionTree{I, N, N - 2, N - 1}
end
end
# converting to actual array
function Base.convert(A::Type{<:AbstractArray}, f::FusionTree{I, 0}) where {I}
X = convert(A, fusiontensor(unit(I), unit(I), unit(I)))[1, 1, :]
return X
end
function Base.convert(A::Type{<:AbstractArray}, f::FusionTree{I, 1}) where {I}
c = f.coupled
if f.isdual[1]
sqrtdc = sqrtdim(c)
Zcbartranspose = sqrtdc * convert(A, fusiontensor(dual(c), c, unit(c)))[:, :, 1, 1]
X = conj!(Zcbartranspose) # we want Zcbar^†
else
X = convert(A, fusiontensor(c, unit(c), c))[:, 1, :, 1, 1]
end
return X
end
function Base.convert(A::Type{<:AbstractArray}, f::FusionTree{I, 2}) where {I}
a, b = f.uncoupled
isduala, isdualb = f.isdual
c = f.coupled
μ = (FusionStyle(I) isa GenericFusion) ? f.vertices[1] : 1
C = convert(A, fusiontensor(a, b, c))[:, :, :, μ]
X = C
if isduala
Za = convert(A, FusionTree((a,), a, (isduala,), ()))
@tensor X[a′, b, c] := Za[a′, a] * X[a, b, c]
end
if isdualb
Zb = convert(A, FusionTree((b,), b, (isdualb,), ()))
@tensor X[a, b′, c] := Zb[b′, b] * X[a, b, c]
end
return X
end
function Base.convert(A::Type{<:AbstractArray}, f::FusionTree{I, N}) where {I, N}
tailout = (f.innerlines[1], TupleTools.tail2(f.uncoupled)...)
isdualout = (false, TupleTools.tail2(f.isdual)...)
ftail = FusionTree(tailout, f.coupled, isdualout, Base.tail(f.innerlines), Base.tail(f.vertices))
Ctail = convert(A, ftail)
f₁ = FusionTree(
(f.uncoupled[1], f.uncoupled[2]), f.innerlines[1],
(f.isdual[1], f.isdual[2]), (), (f.vertices[1],)
)
C1 = convert(A, f₁)
dtail = size(Ctail)
d1 = size(C1)
X = similar(C1, (d1[1], d1[2], Base.tail(dtail)...))
trivialtuple = ntuple(identity, Val(N))
return TO.tensorcontract!(
X,
C1, ((1, 2), (3,)), false,
Ctail, ((1,), Base.tail(trivialtuple)), false,
((trivialtuple..., N + 1), ())
)
end
# TODO: is this piracy?
function Base.convert(
A::Type{<:AbstractArray}, (f₁, f₂)::Tuple{FusionTree{I}, FusionTree{I}}
) where {I}
F₁ = convert(A, f₁)
F₂ = convert(A, f₂)
sz1 = size(F₁)
sz2 = size(F₂)
d1 = TupleTools.front(sz1)
d2 = TupleTools.front(sz2)
return reshape(
reshape(F₁, TupleTools.prod(d1), sz1[end]) *
reshape(F₂, TupleTools.prod(d2), sz2[end])', (d1..., d2...)
)
end
# Show methods
function Base.show(io::IO, t::FusionTree{I}) where {I <: Sector}
if FusionStyle(I) isa GenericFusion
return print(
IOContext(io, :typeinfo => I), "FusionTree{", type_repr(I), "}(",
t.uncoupled, ", ", t.coupled, ", ", t.isdual, ", ", t.innerlines, ", ",
t.vertices, ")"
)
else
return print(
IOContext(io, :typeinfo => I), "FusionTree{", type_repr(I), "}(",
t.uncoupled, ", ", t.coupled, ", ", t.isdual, ", ", t.innerlines, ")"
)
end
end
# Manipulate fusion trees
include("manipulations.jl")
# Fusion tree iterators
include("iterator.jl")
# auxiliary routines
# _abelianinner: generate the inner indices for given outer indices in the abelian case
_abelianinner(outer::Tuple{}) = ()
function _abelianinner(outer::Tuple{I}) where {I <: Sector}
return isunit(outer[1]) ? () : throw(SectorMismatch())
end
function _abelianinner(outer::Tuple{I, I}) where {I <: Sector}
return outer[1] == dual(outer[2]) ? () : throw(SectorMismatch())
end
function _abelianinner(outer::Tuple{I, I, I}) where {I <: Sector}
return isunit(first(⊗(outer...))) ? () : throw(SectorMismatch())
end
function _abelianinner(outer::Tuple{I, I, I, I, Vararg{I}}) where {I <: Sector}
c = first(outer[1] ⊗ outer[2])
return (c, _abelianinner((c, TupleTools.tail2(outer)...))...)
end