Skip to content

Commit

Permalink
SU2 as a concrete type
Browse files Browse the repository at this point in the history
  • Loading branch information
ogauthe committed Apr 25, 2024
1 parent 60a5410 commit de95045
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions NDTensors/src/lib/Sectors/src/category_definitions/su.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
15 changes: 9 additions & 6 deletions NDTensors/src/lib/Sectors/test/test_simple_categories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit de95045

Please sign in to comment.