From 000a28adc47ff5f0977268815854f79b92ca1f2b Mon Sep 17 00:00:00 2001 From: Boris De Vos Date: Tue, 31 Mar 2026 17:19:53 +0200 Subject: [PATCH 1/5] printing of `ZNElement` --- src/groupelements.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/groupelements.jl b/src/groupelements.jl index 2657b01d..50904e06 100644 --- a/src/groupelements.jl +++ b/src/groupelements.jl @@ -118,13 +118,17 @@ 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} +type_repr(::Type{ZNElement{N, p}}) where {N, p} = "ℤ$(N)Element[$p]" +type_repr(::Type{ZNElement{N}}) where {N} = "ℤ$(N)Element[0]" +type_repr(::Type{Z2Element{p}}) where {p} = "ℤ₂Element[$p]" +type_repr(::Type{Z3Element{p}}) where {p} = "ℤ₃Element[$p]" +type_repr(::Type{Z4Element{p}}) where {p} = "ℤ₄Element[$p]" + 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} = From 8cff5096288307b9eea7efe97718e3982b097c14 Mon Sep 17 00:00:00 2001 From: Boris De Vos Date: Wed, 1 Apr 2026 15:49:32 +0200 Subject: [PATCH 2/5] missing exports --- src/TensorKitSectors.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TensorKitSectors.jl b/src/TensorKitSectors.jl index 0743cb18..98d513d4 100644 --- a/src/TensorKitSectors.jl +++ b/src/TensorKitSectors.jl @@ -24,6 +24,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 From 35cda9881e846175ac83df932b390fdca4390ce8 Mon Sep 17 00:00:00 2001 From: Boris De Vos Date: Wed, 1 Apr 2026 16:30:45 +0200 Subject: [PATCH 3/5] parsing is hard --- src/auxiliary.jl | 6 ++++++ src/groupelements.jl | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/auxiliary.jl b/src/auxiliary.jl index 4b2f6a6b..47ac2819 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 \ No newline at end of file diff --git a/src/groupelements.jl b/src/groupelements.jl index 50904e06..5110a99c 100644 --- a/src/groupelements.jl +++ b/src/groupelements.jl @@ -123,11 +123,14 @@ const Z2Element{p} = ZNElement{2, p} const Z3Element{p} = ZNElement{3, p} const Z4Element{p} = ZNElement{4, p} -type_repr(::Type{ZNElement{N, p}}) where {N, p} = "ℤ$(N)Element[$p]" -type_repr(::Type{ZNElement{N}}) where {N} = "ℤ$(N)Element[0]" -type_repr(::Type{Z2Element{p}}) where {p} = "ℤ₂Element[$p]" -type_repr(::Type{Z3Element{p}}) where {p} = "ℤ₃Element[$p]" -type_repr(::Type{Z4Element{p}}) where {p} = "ℤ₄Element[$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) From 366b0cf09a942008fa06c4b1db627f87ff04604c Mon Sep 17 00:00:00 2001 From: Boris De Vos Date: Wed, 1 Apr 2026 16:31:14 +0200 Subject: [PATCH 4/5] aliases in tests --- test/runtests.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index f3d3b61a..0b725180 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,10 +19,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, @@ -33,9 +33,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}, From e2b3b6423f01acc5f496785ab1e26a6119f27bbc Mon Sep 17 00:00:00 2001 From: Boris De Vos Date: Wed, 1 Apr 2026 16:33:41 +0200 Subject: [PATCH 5/5] format --- src/auxiliary.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auxiliary.jl b/src/auxiliary.jl index 47ac2819..d1a1448a 100644 --- a/src/auxiliary.jl +++ b/src/auxiliary.jl @@ -93,4 +93,4 @@ end function subscript(i::Integer) return i < 0 ? error("$i is negative") : string(Iterators.reverse('₀' + d for d in digits(i))...) -end \ No newline at end of file +end