Skip to content

Commit a2da4f3

Browse files
lkdvosclaude
andcommitted
Move the product sector fusion tree code to its own file, and handle the UniqueFusion factors in one step
Construct the UniqueFusion part of a mixed product block first, such that fusionblocks skips the non-abelian construction for blocks with mismatching abelian charges. Construct and manipulate blocks of UniqueFusion products, which hold a single tree pair, directly instead of recursing over their factors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 832ec10 commit a2da4f3

4 files changed

Lines changed: 160 additions & 147 deletions

File tree

‎src/fusiontrees/braiding_manipulations.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function braid(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple, leve
287287
return fsbraid((src, p, levels))
288288
end
289289
function braid(src::ProductSectorBlock, p::Index2Tuple, levels::Index2Tuple)
290-
isempty(src) && return fsbraid((src, p, levels))
290+
(isempty(src) || FusionStyle(src) isa UniqueFusion) && return fsbraid((src, p, levels))
291291
return product_transform(sectorscalartype(sectortype(src)), src) do x
292292
return braid(x, p, levels)
293293
end

‎src/fusiontrees/duality_manipulations.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ function Base.transpose(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tu
527527
return fstranspose((src, p))
528528
end
529529
function Base.transpose(src::ProductSectorBlock, p::Index2Tuple)
530-
isempty(src) && return fstranspose((src, p))
530+
(isempty(src) || FusionStyle(src) isa UniqueFusion) && return fstranspose((src, p))
531531
return product_transform(fusionscalartype(sectortype(src)), src) do x
532532
return transpose(x, p)
533533
end

‎src/fusiontrees/fusiontrees.jl‎

Lines changed: 10 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ function FusionTreeBlock{I}(
127127
isdual::Tuple{NTuple{N₁, Bool}, NTuple{N₂, Bool}};
128128
sizehint::Int = 0
129129
) where {I <: Sector, N₁, N₂}
130+
return fusiontreeblock(I, uncoupled, isdual; sizehint)
131+
end
132+
# construct the block by enumerating its coupled sectors and fusion trees
133+
function fusiontreeblock(
134+
::Type{I}, uncoupled::Tuple{NTuple{N₁, I}, NTuple{N₂, I}},
135+
isdual::Tuple{NTuple{N₁, Bool}, NTuple{N₂, Bool}}; sizehint::Int = 0
136+
) where {I <: Sector, N₁, N₂}
130137
F = fusiontreetype(I, N₁, N₂)
131138
trees = Vector{F}(undef, 0)
132139
sizehint > 0 && sizehint!(trees, sizehint)
@@ -360,159 +367,17 @@ function Base.show(io::IO, t::FusionTree{I}) where {I <: Sector}
360367
end
361368
end
362369

363-
# blocks of products of at least two sectors, see `product_transform`
364-
const ProductSectorBlock = FusionTreeBlock{<:ProductSector{<:Tuple{Sector, Sector, Vararg{Sector}}}}
365-
366370
# Fusion tree iterators
367371
include("iterator.jl")
368372

373+
# Fusion trees of product sectors
374+
include("producttrees.jl")
375+
369376
# Manipulate fusion trees
370377
include("basic_manipulations.jl")
371378
include("duality_manipulations.jl")
372379
include("braiding_manipulations.jl")
373380

374-
# Product sectors
375-
# ---------------
376-
# The fusion trees of a `ProductSector` are pairs of fusion trees of two parts of the product (head
377-
# and tail), such that the manipulations of a block are the Kronecker products of the manipulations
378-
# of the head and tail blocks. A product with both `UniqueFusion` and other factors is split into
379-
# its other factors and its `UniqueFusion` factors, which have a single tree pair; any other product
380-
# is split into its first and its remaining factors.
381-
382-
firstfactor(s::ProductSector) = first(s.sectors)
383-
otherfactors(s::ProductSector{<:Tuple{Sector, Sector}}) = last(s.sectors)
384-
otherfactors(s::ProductSector) = ProductSector(Base.tail(s.sectors))
385-
firstfactortype(::Type{ProductSector{T}}) where {T} = fieldtype(T, 1)
386-
otherfactorstype(::Type{ProductSector{Tuple{H, T}}}) where {H <: Sector, T <: Sector} = T
387-
otherfactorstype(::Type{ProductSector{T}}) where {T} = ProductSector{Base.tuple_type_tail(T)}
388-
389-
Base.@assume_effects :foldable function ismixedproduct(::Type{I}) where {I <: ProductSector}
390-
isunique = map(S -> FusionStyle(S) isa UniqueFusion, TensorKitSectors._sectors(I))
391-
return any(isunique) && !all(isunique)
392-
end
393-
394-
# the non-`UniqueFusion` and the `UniqueFusion` factors, with `Trivial` for no factors
395-
partitionfactors(s::Sector) = FusionStyle(s) isa UniqueFusion ? (Trivial(), s) : (s, Trivial())
396-
function partitionfactors(s::ProductSector)
397-
g, a = partitionfactors(otherfactors(s))
398-
f = firstfactor(s)
399-
return FusionStyle(f) isa UniqueFusion ? (g, f ⊠ a) : (f ⊠ g, a)
400-
end
401-
partitionfactortypes(::Type{I}) where {I <: Sector} =
402-
FusionStyle(I) isa UniqueFusion ? (Trivial, I) : (I, Trivial)
403-
function partitionfactortypes(::Type{I}) where {I <: ProductSector}
404-
G, A = partitionfactortypes(otherfactorstype(I))
405-
F = firstfactortype(I)
406-
return FusionStyle(F) isa UniqueFusion ? (G, F ⊠ A) : (F ⊠ G, A)
407-
end
408-
# the inverse of `partitionfactors` for the factors of `I`
409-
popfactor(s::ProductSector) = firstfactor(s), otherfactors(s)
410-
popfactor(s::Sector) = s, Trivial()
411-
unpartition(::Type{I}, g, a) where {I <: Sector} = FusionStyle(I) isa UniqueFusion ? a : g
412-
function unpartition(::Type{I}, g, a) where {I <: ProductSector}
413-
if FusionStyle(firstfactortype(I)) isa UniqueFusion
414-
f, a′ = popfactor(a)
415-
return f ⊠ unpartition(otherfactorstype(I), g, a′)
416-
else
417-
f, g′ = popfactor(g)
418-
return f ⊠ unpartition(otherfactorstype(I), g′, a)
419-
end
420-
end
421-
422-
headsector(s::ProductSector) =
423-
ismixedproduct(typeof(s)) ? first(partitionfactors(s)) : firstfactor(s)
424-
tailsector(s::ProductSector) =
425-
ismixedproduct(typeof(s)) ? last(partitionfactors(s)) : otherfactors(s)
426-
headsectortype(::Type{I}) where {I <: ProductSector} =
427-
ismixedproduct(I) ? first(partitionfactortypes(I)) : firstfactortype(I)
428-
tailsectortype(::Type{I}) where {I <: ProductSector} =
429-
ismixedproduct(I) ? last(partitionfactortypes(I)) : otherfactorstype(I)
430-
joinsectors(::Type{I}, h, t) where {I <: ProductSector} =
431-
ismixedproduct(I) ? unpartition(I, h, t) : h ⊠ t
432-
433-
# the vertex labels of a product are the linear indices of the head and tail labels, tail first
434-
vertexlines(f::FusionTree) = (f.uncoupled[1], f.innerlines..., f.coupled)
435-
vertexmultiplicities(f::FusionTree) =
436-
ntuple(i -> Nsymbol(vertexlines(f)[i], f.uncoupled[i + 1], vertexlines(f)[i + 1]), length(f) - 1)
437-
438-
maptree(proj, f::FusionTree, vertices) = FusionTree(
439-
map(proj, f.uncoupled), proj(f.coupled), f.isdual, map(proj, f.innerlines), vertices
440-
)
441-
function headtail(f::FusionTree)
442-
vertices_h = vertices_t = f.vertices
443-
if FusionStyle(f) isa GenericFusion && length(f) > 1
444-
ns = vertexmultiplicities(maptree(tailsector, f, map(Returns(1), f.vertices)))
445-
vertices_h = map((μ, n) -> div(μ - 1, n) + 1, f.vertices, ns)
446-
vertices_t = map((μ, n) -> mod(μ - 1, n) + 1, f.vertices, ns)
447-
end
448-
return maptree(headsector, f, vertices_h), maptree(tailsector, f, vertices_t)
449-
end
450-
function jointree(::Type{I}, h::FusionTree, t::FusionTree) where {I}
451-
vertices = h.vertices
452-
if FusionStyle(I) isa GenericFusion && length(h) > 1
453-
vertices = map((μ, ν, n) -> ν + (μ - 1) * n, h.vertices, t.vertices, vertexmultiplicities(t))
454-
end
455-
lift(a, b) = joinsectors(I, a, b)
456-
return fusiontreetype(I, length(h))(
457-
map(lift, h.uncoupled, t.uncoupled), lift(h.coupled, t.coupled), h.isdual,
458-
map(lift, h.innerlines, t.innerlines), vertices
459-
)
460-
end
461-
462-
# the canonical order of a product block is that of the Kronecker product of the head and tail
463-
# blocks, with the head running fastest
464-
productblock(::Type{I}, head::FusionTreeBlock, tail::FusionTreeBlock) where {I} = FusionTreeBlock(
465-
vec(
466-
[
467-
(jointree(I, h₁, t₁), jointree(I, h₂, t₂))
468-
for (h₁, h₂) in fusiontrees(head), (t₁, t₂) in fusiontrees(tail)
469-
]
470-
)
471-
)
472-
function FusionTreeBlock{I}(
473-
uncoupled::Tuple{NTuple{N₁, I}, NTuple{N₂, I}},
474-
isdual::Tuple{NTuple{N₁, Bool}, NTuple{N₂, Bool}};
475-
sizehint::Int = 0
476-
) where {I <: ProductSector{<:Tuple{Sector, Sector, Vararg{Sector}}}, N₁, N₂}
477-
head = FusionTreeBlock{headsectortype(I)}(map.(headsector, uncoupled), isdual)
478-
isempty(head) && return FusionTreeBlock(Vector{fusiontreetype(I, N₁, N₂)}())
479-
tail = FusionTreeBlock{tailsectortype(I)}(map.(tailsector, uncoupled), isdual)
480-
return productblock(I, head, tail)
481-
end
482-
483-
# the distinct tree pairs of one factor, and the position of every tree pair among them
484-
function distincttrees(trees, othertrees)
485-
FusionStyle(first(trees[1])) isa UniqueFusion && return trees[1:1], fill(1, length(trees))
486-
FusionStyle(first(othertrees[1])) isa UniqueFusion && return trees, eachindex(trees)
487-
distinct = unique(trees)
488-
return distinct, indexin(trees, distinct)
489-
end
490-
491-
# apply `transform` to the block `src` through its head and tail, with the recoupling
492-
# matrix with scalar type `T`
493-
function product_transform(transform::F, ::Type{T}, src::FusionTreeBlock{I}) where {F, T, I}
494-
trees = map(fusiontrees(src)) do (f₁, f₂)
495-
h₁, t₁ = headtail(f₁)
496-
h₂, t₂ = headtail(f₂)
497-
return (h₁, h₂), (t₁, t₂)
498-
end
499-
trees_h, trees_t = map(first, trees), map(last, trees)
500-
src_h, cols_h = distincttrees(trees_h, trees_t)
501-
src_t, cols_t = distincttrees(trees_t, trees_h)
502-
dst_h, U_h = transform(FusionTreeBlock(src_h))
503-
dst_t, U_t = transform(FusionTreeBlock(src_t))
504-
505-
dst = productblock(I, dst_h, dst_t)
506-
U = Matrix{T}(undef, length(dst), length(src))
507-
for (col, i, j) in zip(axes(U, 2), cols_h, cols_t)
508-
row = 0
509-
for jt in axes(U_t, 1), jh in axes(U_h, 1)
510-
U[row += 1, col] = U_h[jh, i] * U_t[jt, j]
511-
end
512-
end
513-
return dst => U
514-
end
515-
516381
# auxiliary routines
517382
# _abelianinner: generate the inner indices for given outer indices in the abelian case
518383
_abelianinner(outer::Tuple{}) = ()

‎src/fusiontrees/producttrees.jl‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Product sectors
2+
# ---------------
3+
# The fusion trees of a `ProductSector` are pairs of fusion trees of two parts of the product (head
4+
# and tail), such that the manipulations of a block are the Kronecker products of the manipulations
5+
# of the head and tail blocks. A product with both `UniqueFusion` and other factors is split into
6+
# its other factors and its `UniqueFusion` factors, which have a single tree pair; any other product
7+
# is split into its first and its remaining factors.
8+
9+
# blocks of products of at least two sectors
10+
const ProductSectorBlock = FusionTreeBlock{<:ProductSector{<:Tuple{Sector, Sector, Vararg{Sector}}}}
11+
12+
firstfactor(s::ProductSector) = first(s.sectors)
13+
otherfactors(s::ProductSector{<:Tuple{Sector, Sector}}) = last(s.sectors)
14+
otherfactors(s::ProductSector) = ProductSector(Base.tail(s.sectors))
15+
firstfactortype(::Type{ProductSector{T}}) where {T} = fieldtype(T, 1)
16+
otherfactorstype(::Type{ProductSector{Tuple{H, T}}}) where {H <: Sector, T <: Sector} = T
17+
otherfactorstype(::Type{ProductSector{T}}) where {T} = ProductSector{Base.tuple_type_tail(T)}
18+
19+
Base.@assume_effects :foldable function ismixedproduct(::Type{I}) where {I <: ProductSector}
20+
isunique = map(S -> FusionStyle(S) isa UniqueFusion, TensorKitSectors._sectors(I))
21+
return any(isunique) && !all(isunique)
22+
end
23+
24+
# the non-`UniqueFusion` and the `UniqueFusion` factors, with `Trivial` for no factors
25+
partitionfactors(s::Sector) = FusionStyle(s) isa UniqueFusion ? (Trivial(), s) : (s, Trivial())
26+
function partitionfactors(s::ProductSector)
27+
g, a = partitionfactors(otherfactors(s))
28+
f = firstfactor(s)
29+
return FusionStyle(f) isa UniqueFusion ? (g, f ⊠ a) : (f ⊠ g, a)
30+
end
31+
partitionfactortypes(::Type{I}) where {I <: Sector} =
32+
FusionStyle(I) isa UniqueFusion ? (Trivial, I) : (I, Trivial)
33+
function partitionfactortypes(::Type{I}) where {I <: ProductSector}
34+
G, A = partitionfactortypes(otherfactorstype(I))
35+
F = firstfactortype(I)
36+
return FusionStyle(F) isa UniqueFusion ? (G, F ⊠ A) : (F ⊠ G, A)
37+
end
38+
# the inverse of `partitionfactors` for the factors of `I`
39+
factortuple(s::ProductSector) = s.sectors
40+
factortuple(::Trivial) = ()
41+
factortuple(s::Sector) = (s,)
42+
interleave(::Type{Tuple{}}, gs, as) = ()
43+
function interleave(::Type{T}, gs, as) where {T <: Tuple}
44+
return if FusionStyle(fieldtype(T, 1)) isa UniqueFusion
45+
(first(as), interleave(Base.tuple_type_tail(T), gs, Base.tail(as))...)
46+
else
47+
(first(gs), interleave(Base.tuple_type_tail(T), Base.tail(gs), as)...)
48+
end
49+
end
50+
unpartition(::Type{ProductSector{T}}, g, a) where {T} =
51+
ProductSector{T}(interleave(T, factortuple(g), factortuple(a)))
52+
53+
headsector(s::ProductSector) =
54+
ismixedproduct(typeof(s)) ? first(partitionfactors(s)) : firstfactor(s)
55+
tailsector(s::ProductSector) =
56+
ismixedproduct(typeof(s)) ? last(partitionfactors(s)) : otherfactors(s)
57+
headsectortype(::Type{I}) where {I <: ProductSector} =
58+
ismixedproduct(I) ? first(partitionfactortypes(I)) : firstfactortype(I)
59+
tailsectortype(::Type{I}) where {I <: ProductSector} =
60+
ismixedproduct(I) ? last(partitionfactortypes(I)) : otherfactorstype(I)
61+
joinsectors(::Type{I}, h, t) where {I <: ProductSector} =
62+
ismixedproduct(I) ? unpartition(I, h, t) : h ⊠ t
63+
64+
# the vertex labels of a product are the linear indices of the head and tail labels, tail first
65+
vertexlines(f::FusionTree) = (f.uncoupled[1], f.innerlines..., f.coupled)
66+
vertexmultiplicities(f::FusionTree) =
67+
ntuple(i -> Nsymbol(vertexlines(f)[i], f.uncoupled[i + 1], vertexlines(f)[i + 1]), length(f) - 1)
68+
69+
maptree(proj, f::FusionTree, vertices) = FusionTree(
70+
map(proj, f.uncoupled), proj(f.coupled), f.isdual, map(proj, f.innerlines), vertices
71+
)
72+
function headtail(f::FusionTree)
73+
vertices_h = vertices_t = f.vertices
74+
if FusionStyle(f) isa GenericFusion && length(f) > 1
75+
ns = vertexmultiplicities(maptree(tailsector, f, map(Returns(1), f.vertices)))
76+
vertices_h = map((μ, n) -> div(μ - 1, n) + 1, f.vertices, ns)
77+
vertices_t = map((μ, n) -> mod(μ - 1, n) + 1, f.vertices, ns)
78+
end
79+
return maptree(headsector, f, vertices_h), maptree(tailsector, f, vertices_t)
80+
end
81+
function jointree(::Type{I}, h::FusionTree, t::FusionTree) where {I}
82+
vertices = h.vertices
83+
if FusionStyle(I) isa GenericFusion && length(h) > 1
84+
vertices = map((μ, ν, n) -> ν + (μ - 1) * n, h.vertices, t.vertices, vertexmultiplicities(t))
85+
end
86+
lift(a, b) = joinsectors(I, a, b)
87+
return fusiontreetype(I, length(h))(
88+
map(lift, h.uncoupled, t.uncoupled), lift(h.coupled, t.coupled), h.isdual,
89+
map(lift, h.innerlines, t.innerlines), vertices
90+
)
91+
end
92+
93+
# the canonical order of a product block is that of the Kronecker product of the head and tail
94+
# blocks, with the head running fastest
95+
productblock(::Type{I}, head::FusionTreeBlock, tail::FusionTreeBlock) where {I} = FusionTreeBlock(
96+
vec(
97+
[
98+
(jointree(I, h₁, t₁), jointree(I, h₂, t₂))
99+
for (h₁, h₂) in fusiontrees(head), (t₁, t₂) in fusiontrees(tail)
100+
]
101+
)
102+
)
103+
function FusionTreeBlock{I}(
104+
uncoupled::Tuple{NTuple{N₁, I}, NTuple{N₂, I}},
105+
isdual::Tuple{NTuple{N₁, Bool}, NTuple{N₂, Bool}};
106+
sizehint::Int = 0
107+
) where {I <: ProductSector{<:Tuple{Sector, Sector, Vararg{Sector}}}, N₁, N₂}
108+
# a block of `UniqueFusion` sectors has a single tree pair, in any order
109+
FusionStyle(I) isa UniqueFusion && return fusiontreeblock(I, uncoupled, isdual; sizehint)
110+
# the tail holds the `UniqueFusion` factors of a mixed product, which are cheaper to construct
111+
tail = FusionTreeBlock{tailsectortype(I)}(map.(tailsector, uncoupled), isdual)
112+
isempty(tail) && return FusionTreeBlock(Vector{fusiontreetype(I, N₁, N₂)}())
113+
head = FusionTreeBlock{headsectortype(I)}(map.(headsector, uncoupled), isdual)
114+
return productblock(I, head, tail)
115+
end
116+
117+
# the distinct tree pairs of one factor, and the position of every tree pair among them
118+
function distincttrees(trees, othertrees)
119+
FusionStyle(first(trees[1])) isa UniqueFusion && return trees[1:1], fill(1, length(trees))
120+
FusionStyle(first(othertrees[1])) isa UniqueFusion && return trees, eachindex(trees)
121+
distinct = unique(trees)
122+
return distinct, indexin(trees, distinct)
123+
end
124+
125+
# apply `transform` to the block `src` through its head and tail, with the recoupling
126+
# matrix with scalar type `T`
127+
function product_transform(transform::F, ::Type{T}, src::FusionTreeBlock{I}) where {F, T, I}
128+
trees = map(fusiontrees(src)) do (f₁, f₂)
129+
h₁, t₁ = headtail(f₁)
130+
h₂, t₂ = headtail(f₂)
131+
return (h₁, h₂), (t₁, t₂)
132+
end
133+
trees_h, trees_t = map(first, trees), map(last, trees)
134+
src_h, cols_h = distincttrees(trees_h, trees_t)
135+
src_t, cols_t = distincttrees(trees_t, trees_h)
136+
dst_h, U_h = transform(FusionTreeBlock(src_h))
137+
dst_t, U_t = transform(FusionTreeBlock(src_t))
138+
139+
dst = productblock(I, dst_h, dst_t)
140+
U = Matrix{T}(undef, length(dst), length(src))
141+
for (col, i, j) in zip(axes(U, 2), cols_h, cols_t)
142+
row = 0
143+
for jt in axes(U_t, 1), jh in axes(U_h, 1)
144+
U[row += 1, col] = U_h[jh, i] * U_t[jt, j]
145+
end
146+
end
147+
return dst => U
148+
end

0 commit comments

Comments
 (0)