From de95045032234a24ca1eca69db07d3ae5932e7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Thu, 25 Apr 2024 14:51:05 -0400 Subject: [PATCH] SU2 as a concrete type --- .../lib/Sectors/src/category_definitions/su.jl | 6 +++--- .../lib/Sectors/test/test_simple_categories.jl | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/NDTensors/src/lib/Sectors/src/category_definitions/su.jl b/NDTensors/src/lib/Sectors/src/category_definitions/su.jl index fce50e2520..a384be5975 100644 --- a/NDTensors/src/lib/Sectors/src/category_definitions/su.jl +++ b/NDTensors/src/lib/Sectors/src/category_definitions/su.jl @@ -95,12 +95,12 @@ function label_fusion_rule(::Type{<:SU{2}}, s1, s2) end # define angular momentum-like interface using half-integers -# SU2 is an alias for SU{2} -const SU2 = SU{2} +const SU2 = SU{2,1} # intuitive alias # specific constructor for SU{2} with a half-integer # note that SU{2}(1) = spin 1 while SU{2}((1,)) = spin 1/2 -SU{2}(h::Number) = SU{2}((HalfIntegers.twice(HalfIntegers.HalfInteger(h)),)) +SU{2}(h::Number) = SU{2,1}(h) +SU{2,1}(h::Number) = SU{2,1}((HalfIntegers.twice(HalfIntegers.HalfInteger(h)),)) # display SU2 using half-integers function Base.show(io::IO, s::SU{2}) diff --git a/NDTensors/src/lib/Sectors/test/test_simple_categories.jl b/NDTensors/src/lib/Sectors/test/test_simple_categories.jl index 001ac83ecd..ce75136e45 100644 --- a/NDTensors/src/lib/Sectors/test/test_simple_categories.jl +++ b/NDTensors/src/lib/Sectors/test/test_simple_categories.jl @@ -42,15 +42,18 @@ using Test: @inferred, @test, @testset @testset "SU2" begin j1 = SU2(0) - j2 = SU2(1//2) + j2 = SU2(1//2) # Rational will be cast to HalfInteger j3 = SU2(1) j4 = SU2(3//2) - # alternative tuple constructor - @test j1 == SU{2}((0,)) - @test j2 == SU{2}((1,)) - @test j3 == SU{2}((2,)) - @test j4 == SU((3,)) # infer N from tuple length + # alternative constructors + @test j2 == SU{2}((1,)) # tuple SU(N)-like constructor + @test j2 == SU{2,1}((1,)) # tuple constructor with explicit {N,N-1} + @test j2 == SU{2}(1//2) # half-integer constructor without N-1 + @test j2 == SU((1,)) # infer N from tuple length + @test j2 == SU{2}((Int8(1),)) # any Integer type accepted + @test j2 == SU{2}((UInt32(1),)) # any Integer type accepted + @test j2 == SU2(1 / 2) # Float will be cast to HalfInteger @test trivial(SU2) == SU2(0) @test istrivial(SU2(0))