Skip to content

Commit fcf5907

Browse files
committed
switch to using HalfIntegers
1 parent b9e0bae commit fcf5907

2 files changed

Lines changed: 26 additions & 27 deletions

File tree

src/TensorKit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ using Strided
6565
import TensorOperations
6666
import TensorOperations: @tensor, @tensoropt
6767

68+
using HalfIntegers
6869
using WignerSymbols
69-
using WignerSymbols: HalfInteger
7070

7171
using Base: @boundscheck, @propagate_inbounds, OneTo, tail,
7272
tuple_type_head, tuple_type_tail, tuple_type_cons,

src/sectors/irreps.jl

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@ Base.show(io::IO, c::ZNIrrep{N}) where {N} =
4949

5050
# U1Irrep: irreps of U1 are labelled by integers
5151
struct U1Irrep <: AbelianIrrep
52-
charge::HalfInteger
52+
charge::HalfInt
5353
end
5454
Base.one(::Type{U1Irrep}) = U1Irrep(0)
5555
Base.conj(c::U1Irrep) = U1Irrep(-c.charge)
5656
(c1::U1Irrep, c2::U1Irrep) = (U1Irrep(c1.charge+c2.charge),)
5757

58-
U1Irrep(j::Real) = convert(U1Irrep, j)
59-
Base.convert(::Type{U1Irrep}, c::Real) = U1Irrep(convert(HalfInteger, c))
58+
Base.convert(::Type{U1Irrep}, c::Real) = U1Irrep(c)
6059

6160
const U₁ = U1Irrep
6261
Base.show(io::IO, ::Type{U1Irrep}) = print(io, "U₁")
@@ -67,8 +66,8 @@ Base.show(io::IO, c::U1Irrep) =
6766
Base.hash(c::ZNIrrep{N}, h::UInt) where {N} = hash(c.n, h)
6867
Base.isless(c1::ZNIrrep{N}, c2::ZNIrrep{N}) where {N} = isless(c1.n, c2.n)
6968
Base.hash(c::U1Irrep, h::UInt) = hash(c.charge, h)
70-
Base.isless(c1::U1Irrep, c2::U1Irrep) where {N} =
71-
isless(abs(c1.charge), abs(c2.charge)) || zero(HalfInteger) < c1.charge == -c2.charge
69+
@inline Base.isless(c1::U1Irrep, c2::U1Irrep) where {N} =
70+
isless(abs(c1.charge), abs(c2.charge)) || zero(HalfInt) < c1.charge == -c2.charge
7271

7372
# Nob-abelian groups
7473
#------------------------------------------------------------------------------#
@@ -78,22 +77,22 @@ Base.show(io::IO, ::SU2IrrepException) =
7877
print(io, "Irreps of (bosonic or fermionic) `SU₂` should be labelled by non-negative half integers, i.e. elements of `Rational{Int}` with denominator 1 or 2")
7978

8079
struct SU2Irrep <: Sector
81-
j::HalfInteger
82-
function SU2Irrep(j::HalfInteger)
83-
j >= 0 || error("Not a valid SU₂ irrep")
80+
j::HalfInt
81+
function SU2Irrep(j)
82+
j >= zero(j) || error("Not a valid SU₂ irrep")
8483
new(j)
8584
end
8685
end
8786

88-
Base.one(::Type{SU2Irrep}) = SU2Irrep(zero(HalfInteger))
87+
Base.one(::Type{SU2Irrep}) = SU2Irrep(zero(HalfInt))
8988
Base.conj(s::SU2Irrep) = s
9089
(s1::SU2Irrep, s2::SU2Irrep) =
9190
SectorSet{SU2Irrep}(abs(s1.j-s2.j):(s1.j+s2.j))
9291

93-
SU2Irrep(j::Real) = convert(SU2Irrep, j)
94-
Base.convert(::Type{SU2Irrep}, j::Real) = SU2Irrep(convert(HalfInteger, j))
92+
# SU2Irrep(j::Real) = convert(SU2Irrep, j)
93+
Base.convert(::Type{SU2Irrep}, j::Real) = SU2Irrep(j)
9594

96-
dim(s::SU2Irrep) = s.j.numerator+1
95+
dim(s::SU2Irrep) = twice(s.j)+1
9796

9897
Base.@pure FusionStyle(::Type{SU2Irrep}) = SimpleNonAbelian()
9998
Base.@pure BraidingStyle(::Type{SU2Irrep}) = Bosonic()
@@ -127,13 +126,13 @@ Base.isless(s1::SU2Irrep, s2::SU2Irrep) = isless(s1.j, s2.j)
127126

128127
# U₁ ⋉ C (U₁ and charge conjugation)
129128
struct CU1Irrep <: Sector
130-
j::HalfInteger # value of the U1 charge
129+
j::HalfInt # value of the U1 charge
131130
s::Int # rep of charge conjugation:
132131
# if j == 0, s = 0 (trivial) or s = 1 (non-trivial),
133132
# else s = 2 (two-dimensional representation)
134133
# Let constructor take the actual half integer value j
135-
function CU1Irrep(j::HalfInteger, s::Int = ifelse(j>0, 2, 0))
136-
if ((j > 0 && s == 2) || (j == 0 && (s == 0 || s == 1)))
134+
function CU1Irrep(j::Real, s::Int = ifelse(j>zero(j), 2, 0))
135+
if ((j > zero(j) && s == 2) || (j == zero(j) && (s == 0 || s == 1)))
137136
new(j, s)
138137
else
139138
error("Not a valid CU₁ irrep")
@@ -142,14 +141,14 @@ struct CU1Irrep <: Sector
142141
end
143142
Base.hash(c::CU1Irrep, h::UInt) = hash(c.s, hash(c.j, h))
144143
Base.isless(c1::CU1Irrep, c2::CU1Irrep) =
145-
isless(c1.j, c2.j) || (c1.j == c2.j == 0 && c1.s < c2.s)
144+
isless(c1.j, c2.j) || (c1.j == c2.j == zero(HalfInt) && c1.s < c2.s)
146145

147-
CU1Irrep(j::Real, s::Int = ifelse(j>0, 2, 0)) = CU1Irrep(convert(HalfInteger, j), s)
146+
# CU1Irrep(j::Real, s::Int = ifelse(j>0, 2, 0)) = CU1Irrep(convert(HalfInteger, j), s)
148147

149148
Base.convert(::Type{CU1Irrep}, j::Real) = CU1Irrep(j)
150149
Base.convert(::Type{CU1Irrep}, js::Tuple{Real,Int}) = CU1Irrep(js...)
151150

152-
Base.one(::Type{CU1Irrep}) = CU1Irrep(zero(HalfInteger), 0)
151+
Base.one(::Type{CU1Irrep}) = CU1Irrep(zero(HalfInt), 0)
153152
Base.conj(c::CU1Irrep) = c
154153

155154
struct CU1ProdIterator
@@ -158,27 +157,27 @@ struct CU1ProdIterator
158157
end
159158
function Base.iterate(p::CU1ProdIterator, s::Int = 1)
160159
if s == 1
161-
if p.a.j == p.b.j == zero(HalfInteger)
162-
return CU1Irrep(zero(HalfInteger), xor(p.a.s, p.b.s)), 4
163-
elseif p.a.j == zero(HalfInteger)
160+
if p.a.j == p.b.j == zero(HalfInt)
161+
return CU1Irrep(zero(HalfInt), xor(p.a.s, p.b.s)), 4
162+
elseif p.a.j == zero(HalfInt)
164163
return p.b, 4
165-
elseif p.b.j == zero(HalfInteger)
164+
elseif p.b.j == zero(HalfInt)
166165
return p.a, 4
167166
elseif p.a == p.b # != zero
168167
return one(CU1Irrep), 2
169168
else
170169
return CU1Irrep(abs(p.a.j - p.b.j)), 3
171170
end
172171
elseif s == 2
173-
return CU1Irrep(zero(HalfInteger), 1), 3
172+
return CU1Irrep(zero(HalfInt), 1), 3
174173
elseif s == 3
175174
CU1Irrep(p.a.j + p.b.j), 4
176175
else
177176
return nothing
178177
end
179178
end
180179
function Base.length(p::CU1ProdIterator)
181-
if p.a.j == zero(HalfInteger) || p.b.j == zero(HalfInteger)
180+
if p.a.j == zero(HalfInt) || p.b.j == zero(HalfInt)
182181
return 1
183182
elseif p.a == p.b
184183
return 3
@@ -189,7 +188,7 @@ end
189188

190189
(a::CU1Irrep, b::CU1Irrep) = CU1ProdIterator(a, b)
191190

192-
dim(c::CU1Irrep) = ifelse(c.j == zero(HalfInteger), 1, 2)
191+
dim(c::CU1Irrep) = ifelse(c.j == zero(HalfInt), 1, 2)
193192

194193
Base.@pure FusionStyle(::Type{CU1Irrep}) = SimpleNonAbelian()
195194
Base.@pure BraidingStyle(::Type{CU1Irrep}) = Bosonic()
@@ -218,7 +217,7 @@ function Fsymbol(a::CU1Irrep, b::CU1Irrep, c::CU1Irrep,
218217
return 1.
219218
end
220219
if a == om
221-
if d.j == zero(HalfInteger)
220+
if d.j == zero(HalfInt)
222221
return 1.
223222
else
224223
return (d.j == c.j - b.j) ? -1. : 1.

0 commit comments

Comments
 (0)