diff --git a/NDTensors/src/lib/Sectors/src/abstractcategory.jl b/NDTensors/src/lib/Sectors/src/abstractcategory.jl index b6e86685e6..87d36959be 100644 --- a/NDTensors/src/lib/Sectors/src/abstractcategory.jl +++ b/NDTensors/src/lib/Sectors/src/abstractcategory.jl @@ -43,7 +43,7 @@ function quantum_dimension(::SymmetryStyle, c::AbstractCategory) end quantum_dimension(::AbelianGroup, ::AbstractCategory) = 1 -quantum_dimension(::EmptyCategory, ::AbstractCategory) = 1 +quantum_dimension(::EmptyCategoryStyle, ::AbstractCategory) = 1 quantum_dimension(::SymmetryStyle, g::AbstractUnitRange) = sum(block_dimensions(g)) quantum_dimension(::AbelianGroup, g::AbstractUnitRange) = length(g) @@ -64,7 +64,7 @@ function fusion_rule(::AbelianGroup, c1::C, c2::C) where {C<:AbstractCategory} return C(label_fusion_rule(C, category_label(c1), category_label(c2))) end -function fusion_rule(::EmptyCategory, l1::LabelledInteger, l2::LabelledInteger) +function fusion_rule(::EmptyCategoryStyle, l1::LabelledInteger, l2::LabelledInteger) return labelled(l1 * l2, sector()) end @@ -97,7 +97,7 @@ function GradedAxes.fuse_blocklengths( end function GradedAxes.fuse_blocklengths( - ::EmptyCategory, l1::LabelledInteger, l2::LabelledInteger + ::EmptyCategoryStyle, l1::LabelledInteger, l2::LabelledInteger ) return labelled(l1 * l2, sector()) end diff --git a/NDTensors/src/lib/Sectors/src/category_product.jl b/NDTensors/src/lib/Sectors/src/category_product.jl index 55bbdebec6..42dd006c34 100644 --- a/NDTensors/src/lib/Sectors/src/category_product.jl +++ b/NDTensors/src/lib/Sectors/src/category_product.jl @@ -15,11 +15,13 @@ CategoryProduct(c::CategoryProduct) = _CategoryProduct(categories(c)) categories(s::CategoryProduct) = s.cats -const EmptyCategoryProduct = CategoryProduct{Tuple{}} +const EmptyCategory = CategoryProduct{Tuple{}} # ================================= Sectors interface ==================================== function SymmetryStyle(c::CategoryProduct) - return reduce(combine_styles, map(SymmetryStyle, categories(c)); init=EmptyCategory()) + return reduce( + combine_styles, map(SymmetryStyle, categories(c)); init=EmptyCategoryStyle() + ) end function quantum_dimension(::NonAbelianGroup, s::CategoryProduct) @@ -151,6 +153,13 @@ end # ==================================== Fusion rules ====================================== # generic case: fusion returns a GradedAxes, even for fusion with Empty +function fusion_rule(style::SymmetryStyle, c1::CategoryProduct, c2::AbstractCategory) + return fusion_rule(style, c1, CategoryProduct(c2)) +end +function fusion_rule(style::SymmetryStyle, c1::AbstractCategory, c2::CategoryProduct) + return fusion_rule(style, CategoryProduct(c1), c2) +end + function fusion_rule(::SymmetryStyle, s1::CategoryProduct, s2::CategoryProduct) return to_gradedrange(categories_fusion_rule(categories(s1), categories(s2))) end @@ -161,29 +170,29 @@ function fusion_rule(::AbelianGroup, s1::CategoryProduct, s2::CategoryProduct) end # Empty case -function fusion_rule(::EmptyCategory, ::EmptyCategoryProduct, ::EmptyCategoryProduct) +function fusion_rule(::EmptyCategoryStyle, ::EmptyCategory, ::EmptyCategory) return sector() end -# EmptyCategory acts as trivial on any AbstractCategory, not just CategoryProduct -function fusion_rule(::SymmetryStyle, ::EmptyCategoryProduct, c::AbstractCategory) +# EmptyCategoryStyle acts as trivial on any AbstractCategory, not just CategoryProduct +function fusion_rule(::SymmetryStyle, ::EmptyCategory, c::AbstractCategory) return to_gradedrange(c) end -function fusion_rule(::SymmetryStyle, ::EmptyCategoryProduct, c::CategoryProduct) +function fusion_rule(::SymmetryStyle, c::AbstractCategory, ::EmptyCategory) return to_gradedrange(c) end -function fusion_rule(::SymmetryStyle, c::AbstractCategory, ::EmptyCategoryProduct) +function fusion_rule(::SymmetryStyle, ::EmptyCategory, c::CategoryProduct) return to_gradedrange(c) end -function fusion_rule(::SymmetryStyle, c::CategoryProduct, ::EmptyCategoryProduct) +function fusion_rule(::SymmetryStyle, c::CategoryProduct, ::EmptyCategory) return to_gradedrange(c) end # abelian case: return Category -fusion_rule(::AbelianGroup, ::EmptyCategoryProduct, c::AbstractCategory) = c -fusion_rule(::AbelianGroup, ::EmptyCategoryProduct, c::CategoryProduct) = c -fusion_rule(::AbelianGroup, c::AbstractCategory, ::EmptyCategoryProduct) = c -fusion_rule(::AbelianGroup, c::CategoryProduct, ::EmptyCategoryProduct) = c +fusion_rule(::AbelianGroup, c::AbstractCategory, ::EmptyCategory) = c +fusion_rule(::AbelianGroup, ::EmptyCategory, c::AbstractCategory) = c +fusion_rule(::AbelianGroup, c::CategoryProduct, ::EmptyCategory) = c +fusion_rule(::AbelianGroup, ::EmptyCategory, c::CategoryProduct) = c # =============================== Ordered implementation ================================= CategoryProduct(t::Tuple) = _CategoryProduct(t) @@ -217,7 +226,7 @@ end CategoryProduct(; kws...) = CategoryProduct((; kws...)) -# avoid having 2 different kinds of EmptyCategory: cast empty NamedTuple to Tuple{} +# avoid having 2 different kinds of EmptyCategoryStyle: cast empty NamedTuple to Tuple{} CategoryProduct(::NamedTuple{()}) = CategoryProduct(()) function CategoryProduct(pairs::Pair...) diff --git a/NDTensors/src/lib/Sectors/src/symmetry_style.jl b/NDTensors/src/lib/Sectors/src/symmetry_style.jl index 944fc0fe28..32ec4bbbe2 100644 --- a/NDTensors/src/lib/Sectors/src/symmetry_style.jl +++ b/NDTensors/src/lib/Sectors/src/symmetry_style.jl @@ -8,7 +8,7 @@ abstract type SymmetryStyle end struct AbelianGroup <: SymmetryStyle end struct NonAbelianGroup <: SymmetryStyle end struct NonGroupCategory <: SymmetryStyle end -struct EmptyCategory <: SymmetryStyle end # CategoryProduct with zero category inside +struct EmptyCategoryStyle <: SymmetryStyle end # CategoryProduct with zero category inside combine_styles(::AbelianGroup, ::AbelianGroup) = AbelianGroup() combine_styles(::AbelianGroup, ::NonAbelianGroup) = NonAbelianGroup() @@ -17,10 +17,10 @@ combine_styles(::NonAbelianGroup, ::AbelianGroup) = NonAbelianGroup() combine_styles(::NonAbelianGroup, ::NonAbelianGroup) = NonAbelianGroup() combine_styles(::NonAbelianGroup, ::NonGroupCategory) = NonGroupCategory() combine_styles(::NonGroupCategory, ::SymmetryStyle) = NonGroupCategory() -combine_styles(::NonGroupCategory, ::EmptyCategory) = NonGroupCategory() -combine_styles(::EmptyCategory, s::SymmetryStyle) = s -combine_styles(s::SymmetryStyle, ::EmptyCategory) = s -combine_styles(::EmptyCategory, ::EmptyCategory) = EmptyCategory() +combine_styles(::NonGroupCategory, ::EmptyCategoryStyle) = NonGroupCategory() +combine_styles(::EmptyCategoryStyle, s::SymmetryStyle) = s +combine_styles(s::SymmetryStyle, ::EmptyCategoryStyle) = s +combine_styles(::EmptyCategoryStyle, ::EmptyCategoryStyle) = EmptyCategoryStyle() SymmetryStyle(l::LabelledInteger) = SymmetryStyle(label(l))