@@ -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
361368end
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
367371include (" iterator.jl" )
368372
373+ # Fusion trees of product sectors
374+ include (" producttrees.jl" )
375+
369376# Manipulate fusion trees
370377include (" basic_manipulations.jl" )
371378include (" duality_manipulations.jl" )
372379include (" 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{} ) = ()
0 commit comments