diff --git a/Project.toml b/Project.toml index 8dc81ea..62a2808 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SymmetrySectors" uuid = "f8a8ad64-adbc-4fce-92f7-ffe2bb36a86e" authors = ["ITensor developers and contributors"] -version = "0.1.8" +version = "0.1.9" [deps] BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" diff --git a/src/abstractsector.jl b/src/abstractsector.jl index 0ad804b..33402e5 100644 --- a/src/abstractsector.jl +++ b/src/abstractsector.jl @@ -52,6 +52,13 @@ to_gradedrange(c::AbstractSector) = to_gradedrange(labelled(1, c)) to_gradedrange(l::LabelledInteger) = gradedrange([l]) to_gradedrange(g::AbstractUnitRange) = g +function nsymbol(s1::AbstractSector, s2::AbstractSector, s3::AbstractSector) + full_space = to_gradedrange(s1 ⊗ s2) + i = findfirst(==(s3), blocklabels(full_space)) + isnothing(i) && return 0 + return unlabel(blocklengths(full_space)[i]) +end + # =============================== Fusion rule interface ================================== function fusion_rule(c1::AbstractSector, c2::AbstractSector) return fusion_rule(combine_styles(SymmetryStyle(c1), SymmetryStyle(c2)), c1, c2) diff --git a/test/test_fusion_rules.jl b/test/test_fusion_rules.jl index 5249f69..6276994 100644 --- a/test/test_fusion_rules.jl +++ b/test/test_fusion_rules.jl @@ -9,6 +9,7 @@ using SymmetrySectors: U1, Z, block_dimensions, + nsymbol, quantum_dimension, trivial using TensorProducts: ⊗, tensor_product @@ -29,6 +30,7 @@ using TestExtras: @constinferred @test (@constinferred q ⊗ q) == q @test (@constinferred q ⊗ z0) == z0 @test (@constinferred z1 ⊗ q) == z1 + @test nsymbol(q, q, q) == 1 # test different input number @test tensor_product(z0) == z0 @@ -46,6 +48,8 @@ using TestExtras: @constinferred @test q1 ⊗ q2 == U1(3) @test q2 ⊗ q1 == U1(3) @test (@constinferred q1 ⊗ q2) == q3 + @test nsymbol(q1, q2, q3) == 1 + @test nsymbol(q1, q1, q3) == 0 end @testset "O2 fusion rules" begin @@ -262,6 +266,8 @@ end @test space_isequal( tensor_product(dual(g5), dual(g6)), gradedrange([s1 => 2, f3 => 1, c3 => 1, ad8 => 1]) ) + + @test nsymbol(ad8, ad8, ad8) == 2 end @testset "Mixed GradedUnitRange - Sector fusion rules" begin