Skip to content

Commit 4ebd7f5

Browse files
committed
fix arg order braid
1 parent e3f68ad commit 4ebd7f5

File tree

4 files changed

+37
-38
lines changed

4 files changed

+37
-38
lines changed

src/fusiontrees/manipulations.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ end
936936

937937
# braid fusion tree
938938
"""
939-
braid(f::FusionTree{<:Sector, N}, levels::NTuple{N, Int}, p::NTuple{N, Int})
939+
braid(f::FusionTree{<:Sector, N}, p::NTuple{N, Int}, levels::NTuple{N, Int})
940940
-> <:AbstractDict{typeof(t), <:Number}
941941
942942
Perform a braiding of the uncoupled indices of the fusion tree `f` and return the result as
@@ -949,7 +949,7 @@ that if `i` and `j` cross, ``τ_{i,j}`` is applied if `levels[i] < levels[j]` an
949949
``τ_{j,i}^{-1}`` if `levels[i] > levels[j]`. This does not allow to encode the most general
950950
braid, but a general braid can be obtained by combining such operations.
951951
"""
952-
function braid(f::FusionTree{I,N}, levels::NTuple{N,Int}, p::NTuple{N,Int}) where {I,N}
952+
function braid(f::FusionTree{I,N}, p::NTuple{N,Int}, levels::NTuple{N,Int}) where {I,N}
953953
TupleTools.isperm(p) || throw(ArgumentError("not a valid permutation: $p"))
954954
if FusionStyle(I) isa UniqueFusion && BraidingStyle(I) isa SymmetricBraiding
955955
coeff = one(sectorscalartype(I))
@@ -998,13 +998,13 @@ as a `<:AbstractDict` of output trees and corresponding coefficients; this requi
998998
"""
999999
function permute(f::FusionTree{I,N}, p::NTuple{N,Int}) where {I,N}
10001000
@assert BraidingStyle(I) isa SymmetricBraiding
1001-
return braid(f, ntuple(identity, Val(N)), p)
1001+
return braid(f, p, ntuple(identity, Val(N)))
10021002
end
10031003

10041004
# braid double fusion tree
10051005
"""
1006-
braid((f₁, f₂)::FusionTreePair{I}, (levels1, levels2)::Index2Tuple,
1007-
(p1, p2)::Index2Tuple{N₁, N₂}) where {I, N₁, N₂}
1006+
braid((f₁, f₂)::FusionTreePair{I}, (p1, p2)::Index2Tuple{N₁,N₂},
1007+
(levels1, levels2)::Index2Tuple) where {I,N₁,N₂}
10081008
-> <:AbstractDict{<:FusionTreePair{I, N₁, N₂}}, <:Number}
10091009
10101010
Input is a fusion-splitting tree pair that describes the fusion of a set of incoming
@@ -1019,22 +1019,22 @@ respectively, which determines how indices braid. In particular, if `i` and `j`
10191019
levels[j]`. This does not allow to encode the most general braid, but a general braid can
10201020
be obtained by combining such operations.
10211021
"""
1022-
function braid((f₁, f₂)::FusionTreePair{I}, (levels1, levels2)::Index2Tuple,
1023-
(p1, p2)::Index2Tuple{N₁,N₂}) where {I,N₁,N₂}
1022+
function braid((f₁, f₂)::FusionTreePair{I}, (p1, p2)::Index2Tuple{N₁,N₂},
1023+
(levels1, levels2)::Index2Tuple) where {I,N₁,N₂}
10241024
@assert length(f₁) + length(f₂) == N₁ + N₂
10251025
@assert length(f₁) == length(levels1) && length(f₂) == length(levels2)
10261026
@assert TupleTools.isperm((p1..., p2...))
1027-
return fsbraid(((f₁, f₂), (levels1, levels2), (p1, p2)))
1027+
return fsbraid(((f₁, f₂), (p1, p2), (levels1, levels2)))
10281028
end
1029-
const FSBraidKey{I,N₁,N₂} = Tuple{<:FusionTreePair{I},Index2Tuple,Index2Tuple{N₁,N₂}}
1029+
const FSBraidKey{I,N₁,N₂} = Tuple{<:FusionTreePair{I},Index2Tuple{N₁,N₂},Index2Tuple}
10301030

10311031
@cached function fsbraid(key::FSBraidKey{I,N₁,N₂})::_fsdicttype(I, N₁, N₂) where {I,N₁,N₂}
1032-
((f₁, f₂), (l1, l2), (p1, p2)) = key
1032+
((f₁, f₂), (p1, p2), (l1, l2)) = key
10331033
p = linearizepermutation(p1, p2, length(f₁), length(f₂))
10341034
levels = (l1..., reverse(l2)...)
10351035
local newtrees
10361036
for ((f, f0), coeff1) in repartition((f₁, f₂), N₁ + N₂)
1037-
for (f′, coeff2) in braid(f, levels, p)
1037+
for (f′, coeff2) in braid(f, p, levels)
10381038
for ((f₁′, f₂′), coeff3) in repartition((f′, f0), N₁)
10391039
if @isdefined newtrees
10401040
newtrees[(f₁′, f₂′)] = get(newtrees, (f₁′, f₂′), zero(coeff3)) +
@@ -1067,9 +1067,9 @@ outgoing (`t1`) and incoming sectors (`t2`) respectively (with identical coupled
10671067
repartitioning and permuting the tree such that sectors `p1` become outgoing and sectors
10681068
`p2` become incoming.
10691069
"""
1070-
function permute((f₁, f₂)::FusionTreePair{I}, (p1, p2)::Index2Tuple{N₁, N₂}) where {I, N₁, N₂}
1070+
function permute((f₁, f₂)::FusionTreePair{I}, (p1, p2)::Index2Tuple{N₁,N₂}) where {I,N₁,N₂}
10711071
@assert BraidingStyle(I) isa SymmetricBraiding
10721072
levels1 = ntuple(identity, length(f₁))
10731073
levels2 = length(f₁) .+ ntuple(identity, length(f₂))
1074-
return braid((f₁, f₂), (levels1, levels2), (p1, p2))
1074+
return braid((f₁, f₂), (p1, p2), (levels1, levels2))
10751075
end

src/fusiontrees/uncouplediterator.jl

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function fusiontrees(iter::OuterTreeIterator{I,N₁,N₂}) where {I,N₁,N₂}
1919
trees = Vector{Tuple{F₁,F₂}}(undef, 0)
2020
for c in blocksectors(iter), f₁ in fusiontrees(iter.uncoupled[1], c, iter.isdual[1]),
2121
f₂ in fusiontrees(iter.uncoupled[2], c, iter.isdual[2])
22-
2322
push!(trees, (f₁, f₂))
2423
end
2524
return trees
@@ -211,10 +210,10 @@ end
211210
const _FSTransposeKey{I,N₁,N₂} = Tuple{<:OuterTreeIterator{I},Index2Tuple{N₁,N₂}}
212211

213212
@cached function _fstranspose(key::_FSTransposeKey{I,N₁,N₂})::Tuple{OuterTreeIterator{I,N₁,
214-
N₂},
215-
Matrix{sectorscalartype(I)}} where {I,
216-
N₁,
217-
N₂}
213+
N₂},
214+
Matrix{sectorscalartype(I)}} where {I,
215+
N₁,
216+
N₂}
218217
fs_src, (p1, p2) = key
219218

220219
N = N₁ + N₂
@@ -277,8 +276,8 @@ function artin_braid(fs_src::OuterTreeIterator{I,N,0}, i; inv::Bool=false) where
277276
return fs_dst, U
278277
end
279278

280-
function braid(fs_src::OuterTreeIterator{I,N,0}, levels::NTuple{N,Int},
281-
p::NTuple{N,Int}) where {I,N}
279+
function braid(fs_src::OuterTreeIterator{I,N,0}, p::NTuple{N,Int},
280+
levels::NTuple{N,Int}) where {I,N}
282281
TupleTools.isperm(p) || throw(ArgumentError("not a valid permutation: $p"))
283282

284283
if FusionStyle(I) isa UniqueFusion && BraidingStyle(I) isa SymmetricBraiding
@@ -292,7 +291,7 @@ function braid(fs_src::OuterTreeIterator{I,N,0}, levels::NTuple{N,Int},
292291
U = zeros(sectorscalartype(I), length(trees_dst), length(trees_src))
293292

294293
for (col, (f₁, f₂)) in enumerate(trees_src)
295-
for (f₁′, c) in braid(f₁, levels, p)
294+
for (f₁′, c) in braid(f₁, p, levels)
296295
row = indexmap[(f₁′, f₂)]
297296
U[row, col] = c
298297
end
@@ -310,27 +309,27 @@ function braid(fs_src::OuterTreeIterator{I,N,0}, levels::NTuple{N,Int},
310309
return fs_dst, U
311310
end
312311

313-
function braid(fs_src::OuterTreeIterator{I}, levels::Index2Tuple,
314-
p::Index2Tuple{N₁,N₂}) where {I,N₁,N₂}
312+
function braid(fs_src::OuterTreeIterator{I}, p::Index2Tuple{N₁,N₂},
313+
levels::Index2Tuple) where {I,N₁,N₂}
315314
@assert numind(fs_src) == N₁ + N₂
316315
@assert numout(fs_src) == length(levels[1]) && numin(fs_src) == length(levels[2])
317316
@assert TupleTools.isperm((p[1]..., p[2]...))
318-
return _fsbraid((fs_src, levels, p))
317+
return _fsbraid((fs_src, p, levels))
319318
end
320319

321-
const _FSBraidKey{I,N₁,N₂} = Tuple{<:OuterTreeIterator{I},Index2Tuple,Index2Tuple{N₁,N₂}}
320+
const _FSBraidKey{I,N₁,N₂} = Tuple{<:OuterTreeIterator{I},Index2Tuple{N₁,N₂},Index2Tuple}
322321

323322
@cached function _fsbraid(key::_FSBraidKey{I,N₁,N₂})::Tuple{OuterTreeIterator{I,N₁,N₂},
324-
Matrix{sectorscalartype(I)}} where {I,
325-
N₁,
326-
N₂}
327-
fs_src, (l1, l2), (p1, p2) = key
323+
Matrix{sectorscalartype(I)}} where {I,
324+
N₁,
325+
N₂}
326+
fs_src, (p1, p2), (l1, l2) = key
328327

329328
p = linearizepermutation(p1, p2, numout(fs_src), numin(fs_src))
330329
levels = (l1..., reverse(l2)...)
331330

332331
fs_dst, U = repartition(fs_src, numind(fs_src))
333-
fs_dst, U_tmp = braid(fs_dst, levels, p)
332+
fs_dst, U_tmp = braid(fs_dst, p, levels)
334333
U = U_tmp * U
335334
fs_dst, U_tmp = repartition(fs_dst, N₁)
336335
U = U_tmp * U
@@ -349,5 +348,5 @@ function permute(fs_src::OuterTreeIterator{I}, p::Index2Tuple) where {I}
349348
@assert BraidingStyle(I) isa SymmetricBraiding
350349
levels1 = ntuple(identity, numout(fs_src))
351350
levels2 = numout(fs_src) .+ ntuple(identity, numin(fs_src))
352-
return braid(fs_src, (levels1, levels2), p)
351+
return braid(fs_src, p, (levels1, levels2))
353352
end

src/tensors/treetransformers.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ end
153153

154154
# braid is special because it has levels
155155
function treebraider(::AbstractTensorMap, ::AbstractTensorMap, p::Index2Tuple, levels)
156-
return fusiontreetransform(f) = braid(f, levels, p)
156+
return fusiontreetransform(f) = braid(f, p, levels)
157157
end
158158
function treebraider(tdst::TensorMap, tsrc::TensorMap, p::Index2Tuple, levels)
159159
return treebraider(space(tdst), space(tsrc), p, levels)
160160
end
161161
@cached function treebraider(Vdst::TensorMapSpace, Vsrc::TensorMapSpace, p::Index2Tuple,
162162
levels)::treetransformertype(Vdst, Vsrc)
163-
fusiontreebraider(f) = braid(f, levels, p)
163+
fusiontreebraider(f) = braid(f, p, levels)
164164
return TreeTransformer(fusiontreebraider, p, Vdst, Vsrc)
165165
end
166166

test/fusiontrees.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ ti = time()
8989
@test c′ == one(c′)
9090
return t′
9191
end
92-
braid_i_to_1 = braid(f1, levels, (i, (1:(i - 1))..., ((i + 1):N)...))
92+
braid_i_to_1 = braid(f1, (i, (1:(i - 1))..., ((i + 1):N)...), levels)
9393
trees2 = Dict(_reinsert_partial_tree(t, f2) => c for (t, c) in braid_i_to_1)
9494
trees3 = empty(trees2)
9595
p = (((N + 1):(N + i - 1))..., (1:N)..., ((N + i):(2N - 1))...)
9696
levels = ((i:(N + i - 1))..., (1:(i - 1))..., ((i + N):(2N - 1))...)
9797
for (t, coeff) in trees2
98-
for (t′, coeff′) in braid(t, levels, p)
98+
for (t′, coeff′) in braid(t, p, levels)
9999
trees3[t′] = get(trees3, t′, zero(coeff′)) + coeff * coeff′
100100
end
101101
end
@@ -273,11 +273,11 @@ ti = time()
273273
ip = invperm(p)
274274

275275
levels = ntuple(identity, N)
276-
d = @constinferred braid(f, levels, p)
276+
d = @constinferred braid(f, p, levels)
277277
d2 = Dict{typeof(f),valtype(d)}()
278278
levels2 = p
279279
for (f2, coeff) in d
280-
for (f1, coeff2) in braid(f2, levels2, ip)
280+
for (f1, coeff2) in braid(f2, ip, levels2)
281281
d2[f1] = get(d2, f1, zero(coeff)) + coeff2 * coeff
282282
end
283283
end
@@ -334,7 +334,7 @@ ti = time()
334334
perm = ((N .+ (1:N))..., (1:N)...)
335335
levels = ntuple(identity, 2 * N)
336336
for (t, coeff) in trees1
337-
for (t′, coeff′) in braid(t, levels, perm)
337+
for (t′, coeff′) in braid(t, perm, levels)
338338
trees3[t′] = get(trees3, t′, zero(valtype(trees3))) + coeff * coeff′
339339
end
340340
end

0 commit comments

Comments
 (0)