diff --git a/src/TensorKitSectors.jl b/src/TensorKitSectors.jl index bceb3f8..d83980f 100644 --- a/src/TensorKitSectors.jl +++ b/src/TensorKitSectors.jl @@ -25,6 +25,7 @@ export D3Irrep, D4Irrep, DNIrrep, CU1Irrep export A4Irrep export SU2Irrep export ZNElement, Z2Element, Z3Element, Z4Element +export ℤNElement, ℤ₂Element, ℤ₃Element, ℤ₄Element export ProductSector, NamedSector, @NamedSector, TimeReversed export FermionParity, FermionNumber, FermionSpin export PlanarTrivial, FibonacciAnyon, IsingAnyon diff --git a/src/auxiliary.jl b/src/auxiliary.jl index 4b2f6a6..d1a1448 100644 --- a/src/auxiliary.jl +++ b/src/auxiliary.jl @@ -88,3 +88,9 @@ function manhattan_to_multidimensional_index(index::Int, sz::Dims{N}) where {N} index -= offset return invertlocaloffset(d, index - 1, sz) end + +# pretty printing of ZNElement up to N = 4 +function subscript(i::Integer) + return i < 0 ? error("$i is negative") : + string(Iterators.reverse('₀' + d for d in digits(i))...) +end diff --git a/src/groupelements.jl b/src/groupelements.jl index 2657b01..5110a99 100644 --- a/src/groupelements.jl +++ b/src/groupelements.jl @@ -118,13 +118,20 @@ struct ZNElement{N, p} <: AbstractGroupElement{ℤ{N}} end ZNElement{N}(n::Integer) where {N} = ZNElement{N, 0}(n) Base.getindex(::ElementTable, ::Type{ℤ{N}}, p::Int = 0) where {N} = ZNElement{N, mod(p, N)} -type_repr(::Type{ZNElement{N, p}}) where {N, p} = "GroupElement[ℤ{$N}, $p]" - Base.convert(T::Type{<:ZNElement}, n::Real) = T(n) const Z2Element{p} = ZNElement{2, p} const Z3Element{p} = ZNElement{3, p} const Z4Element{p} = ZNElement{4, p} +const ℤNElement{N, p} = ZNElement{N, p} +const ℤ₂Element{p} = ℤNElement{2, p} +const ℤ₃Element{p} = ℤNElement{3, p} +const ℤ₄Element{p} = ℤNElement{4, p} + +function type_repr(::Type{ZNElement{N, p}}) where {N, p} + return N < 5 ? "ℤ$(subscript(N))Element{$p}" : "ℤNElement{$N, $p}" +end + Base.one(::Type{Z}) where {Z <: ZNElement} = Z(0) Base.inv(c::ZNElement) = typeof(c)(-c.n) Base.:*(c1::ZNElement{N, p}, c2::ZNElement{N, p}) where {N, p} = diff --git a/test/runtests.jl b/test/runtests.jl index a596362..15996e4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -21,10 +21,10 @@ const sectorlist = ( NewSU2Irrep ⊠ SU2Irrep, FermionParity ⊠ SU2Irrep ⊠ NewSU2Irrep, FibonacciAnyon ⊠ FibonacciAnyon ⊠ Z2Irrep, A4Irrep ⊠ Z2Irrep, A4Irrep ⊠ SU2Irrep, - Z2Element{0}, Z2Element{1}, - Z3Element{0}, Z3Element{1}, Z3Element{2}, - Z4Element{0}, Z4Element{1}, Z4Element{2}, - ZNElement{6, 0}, ZNElement{6, 1}, ZNElement{6, 3}, + ℤ₂Element{0}, Z2Element{1}, + Z3Element{0}, Z3Element{1}, ℤ₃Element{2}, + Z4Element{0}, ℤ₄Element{1}, Z4Element{2}, + ZNElement{6, 0}, ℤNElement{6, 1}, ZNElement{6, 3}, Z3Element{1} ⊠ SU2Irrep, FibonacciAnyon ⊠ Z4Element{3}, IsingBimodule, IsingBimodule ⊠ IsingBimodule, IsingBimodule ⊠ Z2Irrep, @@ -35,9 +35,9 @@ const sectorlist = ( TimeReversed{FibonacciAnyon}, TimeReversed{IsingAnyon}, TimeReversed{FermionParity}, TimeReversed{FermionParity ⊠ FermionParity}, - TimeReversed{Z4Element{2}}, TimeReversed{ZNElement{6, 3}}, + TimeReversed{ℤ₄Element{2}}, TimeReversed{ZNElement{6, 3}}, ZNElement{6, 1} ⊠ TimeReversed{FibonacciAnyon}, - TimeReversed{ZNElement{6, 3} ⊠ FibonacciAnyon}, + TimeReversed{ℤNElement{6, 3} ⊠ FibonacciAnyon}, TimeReversed{Z2Irrep ⊠ Z3Irrep ⊠ Z4Irrep}, TimeReversed{Z2Irrep} ⊠ TimeReversed{Z3Irrep} ⊠ TimeReversed{Z4Irrep}, TimeReversed{NewSU2Irrep ⊠ NewSU2Irrep},