@@ -5,22 +5,22 @@ A `ProductSpace` is a tensor product space of `N` vector spaces of type
55`S<:ElementarySpace`. Only tensor products between [`ElementarySpace`](@ref) objects of the
66same type are allowed.
77"""
8- struct ProductSpace{S<: ElementarySpace ,N} <: CompositeSpace{S}
9- spaces:: NTuple{N,S}
10- ProductSpace {S,N} (spaces:: NTuple{N,S} ) where {S<: ElementarySpace ,N} = new {S,N} (spaces)
8+ struct ProductSpace{S <: ElementarySpace , N} <: CompositeSpace{S}
9+ spaces:: NTuple{N, S}
10+ ProductSpace {S, N} (spaces:: NTuple{N, S} ) where {S <: ElementarySpace , N} = new {S, N} (spaces)
1111end
1212
13- function ProductSpace {S,N} (spaces:: Vararg{S,N} ) where {S<: ElementarySpace ,N}
14- return ProductSpace {S,N} (spaces)
13+ function ProductSpace {S, N} (spaces:: Vararg{S, N} ) where {S <: ElementarySpace , N}
14+ return ProductSpace {S, N} (spaces)
1515end
1616
17- function ProductSpace {S} (spaces:: Tuple{Vararg{S}} ) where {S<: ElementarySpace }
18- return ProductSpace {S,length(spaces)} (spaces)
17+ function ProductSpace {S} (spaces:: Tuple{Vararg{S}} ) where {S <: ElementarySpace }
18+ return ProductSpace {S, length(spaces)} (spaces)
1919end
20- ProductSpace {S} (spaces:: Vararg{S} ) where {S<: ElementarySpace } = ProductSpace {S} (spaces)
20+ ProductSpace {S} (spaces:: Vararg{S} ) where {S <: ElementarySpace } = ProductSpace {S} (spaces)
2121
22- function ProductSpace (spaces:: Tuple{S,Vararg{S}} ) where {S<: ElementarySpace }
23- return ProductSpace {S,length(spaces)} (spaces)
22+ function ProductSpace (spaces:: Tuple{S, Vararg{S}} ) where {S <: ElementarySpace }
23+ return ProductSpace {S, length(spaces)} (spaces)
2424end
2525function ProductSpace (space1:: ElementarySpace , rspaces:: Vararg{ElementarySpace} )
2626 return ProductSpace ((space1, rspaces... ))
2929ProductSpace (P:: ProductSpace ) = P
3030
3131# constructors with conversion behaviour
32- function ProductSpace {S,N} (V:: Vararg{ElementarySpace,N} ) where {S<: ElementarySpace ,N}
33- return ProductSpace {S,N} (V)
32+ function ProductSpace {S, N} (V:: Vararg{ElementarySpace, N} ) where {S <: ElementarySpace , N}
33+ return ProductSpace {S, N} (V)
3434end
35- function ProductSpace {S} (V:: Vararg{ElementarySpace} ) where {S<: ElementarySpace }
35+ function ProductSpace {S} (V:: Vararg{ElementarySpace} ) where {S <: ElementarySpace }
3636 return ProductSpace {S} (V)
3737end
3838
39- function ProductSpace {S,N} (V:: Tuple{Vararg{ElementarySpace,N}} ) where {S<: ElementarySpace ,N}
39+ function ProductSpace {S, N} (V:: Tuple{Vararg{ElementarySpace, N}} ) where {S <: ElementarySpace , N}
4040 return ProductSpace {S} (convert .(S, V))
4141end
42- function ProductSpace {S} (V:: Tuple{Vararg{ElementarySpace}} ) where {S<: ElementarySpace }
42+ function ProductSpace {S} (V:: Tuple{Vararg{ElementarySpace}} ) where {S <: ElementarySpace }
4343 return ProductSpace {S} (convert .(S, V))
4444end
45- function ProductSpace (V:: Tuple{ElementarySpace,Vararg{ElementarySpace}} )
45+ function ProductSpace (V:: Tuple{ElementarySpace, Vararg{ElementarySpace}} )
4646 return ProductSpace (promote (V... ))
4747end
4848
@@ -60,15 +60,15 @@ dim(P::ProductSpace) = prod(dims(P))
6060Base. axes (P:: ProductSpace ) = map (axes, P. spaces)
6161Base. axes (P:: ProductSpace , n:: Int ) = axes (P. spaces[n])
6262
63- dual (P:: ProductSpace{<:ElementarySpace,0} ) = P
63+ dual (P:: ProductSpace{<:ElementarySpace, 0} ) = P
6464dual (P:: ProductSpace ) = ProductSpace (map (dual, reverse (P. spaces)))
6565
6666# Base.conj(P::ProductSpace) = ProductSpace(map(conj, P.spaces))
6767
68- function Base. show (io:: IO , P:: ProductSpace{S} ) where {S<: ElementarySpace }
68+ function Base. show (io:: IO , P:: ProductSpace{S} ) where {S <: ElementarySpace }
6969 spaces = P. spaces
7070 if length (spaces) == 0
71- print (io, " ProductSpace{ " , S , " , 0} " )
71+ return print (io, " one( " , type_repr (S) , " ) " )
7272 end
7373 if length (spaces) == 1
7474 print (io, " ProductSpace" )
@@ -89,10 +89,10 @@ Return an iterator over all possible combinations of sectors (represented as an
8989`NTuple{N, sectortype(S)}`) that can appear within the tensor product space `P`.
9090"""
9191sectors (P:: ProductSpace ) = _sectors (P, sectortype (P))
92- function _sectors (P:: ProductSpace{<:ElementarySpace,N} , :: Type{Trivial} ) where {N}
92+ function _sectors (P:: ProductSpace{<:ElementarySpace, N} , :: Type{Trivial} ) where {N}
9393 return OneOrNoneIterator (dim (P) != 0 , ntuple (n -> Trivial (), N))
9494end
95- function _sectors (P:: ProductSpace{<:ElementarySpace,N} , :: Type{<:Sector} ) where {N}
95+ function _sectors (P:: ProductSpace{<:ElementarySpace, N} , :: Type{<:Sector} ) where {N}
9696 return product (map (sectors, P. spaces)... )
9797end
9898
103103Query whether `P` has a non-zero degeneracy of sector `s`, representing a combination of
104104sectors on the individual tensor indices.
105105"""
106- function hassector (V:: ProductSpace{<:ElementarySpace,N} , s:: NTuple{N} ) where {N}
107- return reduce (& , map (hassector, V. spaces, s); init= true )
106+ function hassector (V:: ProductSpace{<:ElementarySpace, N} , s:: NTuple{N} ) where {N}
107+ return reduce (& , map (hassector, V. spaces, s); init = true )
108108end
109109
110110"""
114114Return the degeneracy dimensions corresponding to a tuple of sectors `s` for each of the
115115spaces in the tensor product `P`.
116116"""
117- function dims (P:: ProductSpace{<:ElementarySpace,N} , sector:: NTuple{N,<:Sector} ) where {N}
117+ function dims (P:: ProductSpace{<:ElementarySpace, N} , sector:: NTuple{N, <:Sector} ) where {N}
118118 return map (dim, P. spaces, sector)
119119end
120120
@@ -125,12 +125,14 @@ end
125125Return the total degeneracy dimension corresponding to a tuple of sectors for each of the
126126spaces in the tensor product, obtained as `prod(dims(P, s))``.
127127"""
128- function dim (P:: ProductSpace{<:ElementarySpace,N} , sector:: NTuple{N,<:Sector} ) where {N}
129- return reduce (* , dims (P, sector); init= 1 )
128+ function dim (P:: ProductSpace{<:ElementarySpace, N} , sector:: NTuple{N, <:Sector} ) where {N}
129+ return reduce (* , dims (P, sector); init = 1 )
130130end
131131
132- function Base. axes (P:: ProductSpace{<:ElementarySpace,N} ,
133- sectors:: NTuple{N,<:Sector} ) where {N}
132+ function Base. axes (
133+ P:: ProductSpace{<:ElementarySpace, N} ,
134+ sectors:: NTuple{N, <:Sector}
135+ ) where {N}
134136 return map (axes, P. spaces, sectors)
135137end
136138
@@ -141,7 +143,7 @@ Return an iterator over the different unique coupled sector labels, i.e. the dif
141143fusion outputs that can be obtained by fusing the sectors present in the different spaces
142144that make up the `ProductSpace` instance.
143145"""
144- function blocksectors (P:: ProductSpace{S,N} ) where {S,N}
146+ function blocksectors (P:: ProductSpace{S, N} ) where {S, N}
145147 I = sectortype (S)
146148 if I == Trivial
147149 return OneOrNoneIterator (dim (P) != 0 , Trivial ())
@@ -172,7 +174,7 @@ Return an iterator over all fusion trees that can be formed by fusing the sector
172174in the different spaces that make up the `ProductSpace` instance into the coupled sector
173175`blocksector`.
174176"""
175- function fusiontrees (P:: ProductSpace{S,N} , blocksector:: I ) where {S,N, I}
177+ function fusiontrees (P:: ProductSpace{S, N} , blocksector:: I ) where {S, N, I}
176178 I == sectortype (S) || throw (SectorMismatch ())
177179 uncoupled = map (sectors, P. spaces)
178180 isdualflags = map (isdual, P. spaces)
@@ -207,8 +209,10 @@ function blockdim(P::ProductSpace, c::Sector)
207209 return d
208210end
209211
210- function Base.:(== )(P1:: ProductSpace{S,N} ,
211- P2:: ProductSpace{S,N} ) where {S<: ElementarySpace ,N}
212+ function Base.:(== )(
213+ P1:: ProductSpace{S, N} ,
214+ P2:: ProductSpace{S, N}
215+ ) where {S <: ElementarySpace , N}
212216 return (P1. spaces == P2. spaces)
213217end
214218Base.:(== )(P1:: ProductSpace , P2:: ProductSpace ) = false
@@ -220,7 +224,7 @@ Base.hash(P::ProductSpace{S}, h::UInt) where {S} = hash(P.spaces, hash(S, h))
220224# ---------------------------------------------
221225⊗ (V:: ElementarySpace , Vrest:: ElementarySpace... ) = ProductSpace (V, Vrest... )
222226⊗ (P:: ProductSpace ) = P
223- function ⊗ (P1:: ProductSpace{S} , P2:: ProductSpace{S} ) where {S<: ElementarySpace }
227+ function ⊗ (P1:: ProductSpace{S} , P2:: ProductSpace{S} ) where {S <: ElementarySpace }
224228 return ProductSpace {S} (tuple (P1. spaces... , P2. spaces... ))
225229end
226230
@@ -233,17 +237,17 @@ Return a tensor product of zero spaces of type `S`, i.e. this is the unit object
233237tensor product operation, such that `V ⊗ one(V) == V`.
234238"""
235239Base. one (V:: VectorSpace ) = one (typeof (V))
236- Base. one (:: Type{<:ProductSpace{S}} ) where {S<: ElementarySpace } = ProductSpace {S,0} (())
237- Base. one (:: Type{S} ) where {S<: ElementarySpace } = ProductSpace {S,0} (())
240+ Base. one (:: Type{<:ProductSpace{S}} ) where {S <: ElementarySpace } = ProductSpace {S, 0} (())
241+ Base. one (:: Type{S} ) where {S <: ElementarySpace } = ProductSpace {S, 0} (())
238242
239- Base.:^ (V:: ElementarySpace , N:: Int ) = ProductSpace {typeof(V),N} (ntuple (n -> V, N))
243+ Base.:^ (V:: ElementarySpace , N:: Int ) = ProductSpace {typeof(V), N} (ntuple (n -> V, N))
240244Base.:^ (V:: ProductSpace , N:: Int ) = ⊗ (ntuple (n -> V, N)... )
241245function Base. literal_pow (:: typeof (^ ), V:: ElementarySpace , p:: Val{N} ) where {N}
242- return ProductSpace {typeof(V),N} (ntuple (n -> V, p))
246+ return ProductSpace {typeof(V), N} (ntuple (n -> V, p))
243247end
244248
245- fuse (P:: ProductSpace{S,0} ) where {S<: ElementarySpace } = oneunit (S)
246- fuse (P:: ProductSpace{S} ) where {S<: ElementarySpace } = fuse (P. spaces... )
249+ fuse (P:: ProductSpace{S, 0} ) where {S <: ElementarySpace } = oneunit (S)
250+ fuse (P:: ProductSpace{S} ) where {S <: ElementarySpace } = fuse (P. spaces... )
247251
248252"""
249253 insertleftunit(P::ProductSpace, i::Int=length(P) + 1; conj=false, dual=false)
@@ -254,8 +258,10 @@ More specifically, adds a left monoidal unit or its dual.
254258
255259See also [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) where {i}), [`removeunit`](@ref removeunit(::ProductSpace, ::Val{i}) where {i}).
256260"""
257- function insertleftunit (P:: ProductSpace , :: Val{i} = Val (length (P) + 1 );
258- conj:: Bool = false , dual:: Bool = false ) where {i}
261+ function insertleftunit (
262+ P:: ProductSpace , :: Val{i} = Val (length (P) + 1 );
263+ conj:: Bool = false , dual:: Bool = false
264+ ) where {i}
259265 u = oneunit (spacetype (P))
260266 if dual
261267 u = TensorKit. dual (u)
@@ -275,8 +281,10 @@ More specifically, adds a right monoidal unit or its dual.
275281
276282See also [`insertleftunit`](@ref insertleftunit(::ProductSpace, ::Val{i}) where {i}), [`removeunit`](@ref removeunit(::ProductSpace, ::Val{i}) where {i}).
277283"""
278- function insertrightunit (P:: ProductSpace , :: Val{i} = Val (length (P));
279- conj:: Bool = false , dual:: Bool = false ) where {i}
284+ function insertrightunit (
285+ P:: ProductSpace , :: Val{i} = Val (length (P));
286+ conj:: Bool = false , dual:: Bool = false
287+ ) where {i}
280288 u = oneunit (spacetype (P))
281289 if dual
282290 u = TensorKit. dual (u)
@@ -311,7 +319,7 @@ Base.getindex(P::ProductSpace, n::Integer) = P.spaces[n]
311319Base. iterate (P:: ProductSpace , args... ) = Base. iterate (P. spaces, args... )
312320Base. indexed_iterate (P:: ProductSpace , args... ) = Base. indexed_iterate (P. spaces, args... )
313321
314- Base. eltype (:: Type{<:ProductSpace{S}} ) where {S<: ElementarySpace } = S
322+ Base. eltype (:: Type{<:ProductSpace{S}} ) where {S <: ElementarySpace } = S
315323Base. eltype (P:: ProductSpace ) = eltype (typeof (P))
316324
317325Base. IteratorEltype (:: Type{<:ProductSpace} ) = Base. HasEltype ()
@@ -321,13 +329,13 @@ Base.reverse(P::ProductSpace) = ProductSpace(reverse(P.spaces))
321329
322330# Promotion and conversion
323331# ------------------------
324- function Base. promote_rule (:: Type{S} , :: Type{<:ProductSpace{S}} ) where {S<: ElementarySpace }
332+ function Base. promote_rule (:: Type{S} , :: Type{<:ProductSpace{S}} ) where {S <: ElementarySpace }
325333 return ProductSpace{S}
326334end
327335
328336# ProductSpace to ElementarySpace
329- Base. convert (:: Type{S} , P:: ProductSpace{S,0} ) where {S<: ElementarySpace } = oneunit (S)
330- Base. convert (:: Type{S} , P:: ProductSpace{S} ) where {S<: ElementarySpace } = fuse (P. spaces... )
337+ Base. convert (:: Type{S} , P:: ProductSpace{S, 0} ) where {S <: ElementarySpace } = oneunit (S)
338+ Base. convert (:: Type{S} , P:: ProductSpace{S} ) where {S <: ElementarySpace } = fuse (P. spaces... )
331339
332340# ElementarySpace to ProductSpace
333- Base. convert (:: Type{<:ProductSpace} , V:: S ) where {S<: ElementarySpace } = ⊗ (V)
341+ Base. convert (:: Type{<:ProductSpace} , V:: S ) where {S <: ElementarySpace } = ⊗ (V)
0 commit comments