Tutorial
Before discussing at length all aspects of this package, both its usage and implementation, we start with a short tutorial to sketch the main capabilities. Thereto, we start by loading TensorKit.jl
julia> using TensorKit
Cartesian tensors
The most important objects in TensorKit.jl are tensors, which we now create with random (normally distributed) entries in the following manner
julia> A = randn(ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4)
TensorMap((ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}()): [:, :, 1] = 0.26814943036016314 -0.2169061292400202 -1.0004442150718642 -2.7656365992898713 -1.526196119897884 -0.8989523957134242 [:, :, 2] = -0.5307998523589162 -0.493714726466143 1.0002959876817632 -0.6503891173322137 -0.8625198972463062 0.741031814855964 [:, :, 3] = 0.6386842361146164 0.8787872122341243 -0.47466191163443255 1.1777079333672194 -0.24481039500216692 -0.1632910008400414 [:, :, 4] = 1.8803375328404863 -0.07949775555433829 2.321652666836315 1.178660047986449 -0.04928484684616773 -0.81814622657931
Note that we entered the tensor size not as plain dimensions, by specifying the vector space associated with these tensor indices, in this case ℝ^n
, which can be obtained by typing \bbR+TAB
. The tensor then lives in the tensor product of the different spaces, which we can obtain by typing ⊗
(i.e. \otimes+TAB
), although for simplicity also the usual multiplication sign *
does the job. Note also that A
is printed as an instance of a parametric type TensorMap
, which we will discuss below and contains Tensor
.
Let us briefly sidetrack into the nature of ℝ^n
:
julia> V = ℝ^3
ℝ^3
julia> typeof(V)
CartesianSpace
julia> V == CartesianSpace(3)
true
julia> supertype(CartesianSpace)
ElementarySpace
julia> supertype(ElementarySpace)
VectorSpace
i.e. ℝ^n
can also be created without Unicode using the longer syntax CartesianSpace(n)
. It is subtype of ElementarySpace
, with a standard (Euclidean) inner product over the real numbers. Furthermore,
julia> W = ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4
(ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4)
julia> typeof(W)
ProductSpace{CartesianSpace, 3}
julia> supertype(ProductSpace)
CompositeSpace
julia> supertype(CompositeSpace)
VectorSpace
i.e. the tensor product of a number of CartesianSpace
s is some generic parametric ProductSpace
type, specifically ProductSpace{CartesianSpace,N}
for the tensor product of N
instances of CartesianSpace
.
Tensors are itself vectors (but not Vector
s or even AbstractArray
s), so we can compute linear combinations, provided they live in the same space.
julia> B = randn(ℝ^3 * ℝ^2 * ℝ^4);
julia> C = 0.5*A + 2.5*B
TensorMap((ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}()): [:, :, 1] = 0.4235986393296685 2.121130244906199 -5.345071186699393 -0.9655514739161513 -6.754529775273837 -0.14732089415228034 [:, :, 2] = -1.0199631428630251 4.302656178897484 2.5578711046422278 3.6826267935137267 1.8692996450420543 2.2099795549491823 [:, :, 3] = -1.9660931441905478 0.00892143422204994 2.4179215736849096 0.6916290384223623 -2.1267394602775336 -3.129782050919883 [:, :, 4] = -0.9110083351153406 0.8932803780021689 -0.10288760643427808 4.798237924229789 1.534294098006171 -2.08334420226691
Given that they are behave as vectors, they also have a scalar product and norm, which they inherit from the Euclidean inner product on the individual ℝ^n
spaces:
julia> scalarBA = dot(B,A)
2.768172129368274
julia> scalarAA = dot(A,A)
29.020318817807293
julia> normA² = norm(A)^2
29.020318817807293
More generally, our tensor objects implement the full interface layed out in VectorInterface.jl.
If two tensors live on different spaces, these operations have no meaning and are thus not allowed
julia> B′ = randn(ℝ^4 * ℝ^2 * ℝ^3);
julia> space(B′) == space(A)
false
julia> C′ = 0.5*A + 2.5*B′
ERROR: SpaceMismatch("(ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}() ≠ (ℝ^4 ⊗ ℝ^2 ⊗ ℝ^3) ← ProductSpace{CartesianSpace, 0}()")
julia> scalarBA′ = dot(B′,A)
ERROR: SpaceMismatch("(ℝ^4 ⊗ ℝ^2 ⊗ ℝ^3) ← ProductSpace{CartesianSpace, 0}() ≠ (ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}()")
However, in this particular case, we can reorder the indices of B′
to match space of A
, using the routine permute
(we deliberately choose not to overload permutedims
from Julia Base, for reasons that become clear below):
julia> space(permute(B′,(3,2,1))) == space(A)
true
We can contract two tensors using Einstein summation convention, which takes the interface from TensorOperations.jl. TensorKit.jl reexports the @tensor
macro
julia> @tensor D[a,b,c,d] := A[a,b,e]*B[d,c,e]
TensorMap((ℝ^3 ⊗ ℝ^2 ⊗ ℝ^2 ⊗ ℝ^3) ← ProductSpace{CartesianSpace, 0}()): [:, :, 1, 1] = -1.784940615705178 -0.6206029598920085 -1.7029681108849104 -2.073376794960712 0.3438755150808545 0.42732039862629456 [:, :, 2, 1] = -0.13501819338922363 -1.2728957164317853 1.8763140087977117 -3.4129669933974816 -2.9069709961608514 0.2695931544696385 [:, :, 1, 2] = -1.2286893850197274 0.9875254591123415 1.0844325302150724 5.479357619889011 2.012644506970184 2.5921803704770565 [:, :, 2, 2] = 2.3857388779512574 -0.9254037869076015 5.325757710008719 0.528503523371205 -1.7305009833658416 -0.3461856973361366 [:, :, 1, 3] = -0.4706182156588325 -0.6886228648817718 5.14640959827584 5.820319897327449 3.029468530844001 2.4570605841701862 [:, :, 2, 3] = -2.396142317215158 -1.4077089027582874 -0.3610092145161599 -3.038091977702826 -0.487596216488379 1.183603877074959
julia> @tensor d = A[a,b,c]*A[a,b,c]
29.02031881780729
julia> d ≈ scalarAA ≈ normA²
true
We hope that the index convention is clear. The :=
is to create a new tensor D
, without the :
the result would be written in an existing tensor D
, which in this case would yield an error as no tensor D
exists. If the contraction yields a scalar, regular assignment with =
can be used.
Finally, we can factorize a tensor, creating a bipartition of a subset of its indices and its complement. With a plain Julia Array
, one would apply permutedims
and reshape
to cast the array into a matrix before applying e.g. the singular value decomposition. With TensorKit.jl, one just specifies which indices go to the left (rows) and right (columns)
julia> U, S, Vd = tsvd(A, (1,3), (2,));
julia> @tensor A′[a,b,c] := U[a,c,d]*S[d,e]*Vd[e,b];
julia> A ≈ A′
true
julia> U
TensorMap((ℝ^3 ⊗ ℝ^4) ← ℝ^2): [:, :, 1] = -0.011621922807838449 0.1610509298097011 … -0.29707199280032925 0.5779822286577705 -0.06709500941525298 -0.5577411837466872 0.38520867677985987 0.03090131925904865 0.13045092196393462 [:, :, 2] = -0.11516618447547156 -0.00264934727681754 … -0.4474338656430911 -0.4634682576448208 -0.3899503438920429 -0.23344970837644421 0.12245138226933447 0.38126723598684226 -0.19319689965421052
Note that the tsvd
routine returns the decomposition of the linear map as three factors, U
, S
and Vd
, each of them a TensorMap
, such that Vd
is already what is commonly called V'
. Furthermore, observe that U
is printed differently then A
, i.e. as a TensorMap((ℝ^3 ⊗ ℝ^4) ← ProductSpace(ℝ^2))
. What this means is that tensors (or more appropriately, TensorMap
instances) in TensorKit.jl are always considered to be linear maps between two ProductSpace
instances, with
julia> codomain(U)
(ℝ^3 ⊗ ℝ^4)
julia> domain(U)
ProductSpace(ℝ^2)
julia> codomain(A)
(ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4)
julia> domain(A)
ProductSpace{CartesianSpace, 0}()
An instance of TensorMap
thus represents a linear map from its domain to its codomain, making it an element of the space of homomorphisms between these two spaces. That space is represented using its own type HomSpace
in TensorKit.jl, and which admits a direct constructor as well as a unicode alternative using the symbol →
(obtained as \to+TAB
or \rightarrow+TAB
) or ←
(obtained as \leftarrow+TAB
).
julia> P = space(U)
(ℝ^3 ⊗ ℝ^4) ← ℝ^2
julia> space(U) == HomSpace(ℝ^3 ⊗ ℝ^4, ℝ^2) == (ℝ^3 ⊗ ℝ^4 ← ℝ^2) == ℝ^2 → ℝ^3 ⊗ ℝ^4
ERROR: MethodError: no method matching HomSpace(::ProductSpace{CartesianSpace, 2}, ::CartesianSpace) The type `HomSpace` exists, but no method is defined for this combination of argument types when trying to construct it. Closest candidates are: HomSpace(::P1, ::P2) where {S<:ElementarySpace, P1<:CompositeSpace{S}, P2<:CompositeSpace{S}} @ TensorKit ~/work/TensorKit.jl/TensorKit.jl/src/spaces/homspace.jl:12
julia> (codomain(P), domain(P))
((ℝ^3 ⊗ ℝ^4), ProductSpace(ℝ^2))
Furthermore, a Tensor
instance such as A
is just a specific case of TensorMap
with an empty domain, i.e. a ProductSpace{CartesianSpace,0}
instance. Analogously, we can represent a vector v
and matrix m
as
julia> v = randn(ℝ^3)
TensorMap(ℝ^3 ← ProductSpace{CartesianSpace, 0}()): -0.24284811907482776 0.15165209047883543 -1.7612791829486796
julia> M₁ = randn(ℝ^4, ℝ^3)
TensorMap(ℝ^4 ← ℝ^3): 1.3347615595499385 1.2148941872083123 -0.3635603669635693 2.000024867796524 0.12442362079177063 -0.18310102601250977 -1.3968596400771263 0.45965515177076405 0.1829029835989369 0.019842961333780502 -0.34054271930183455 -0.17587425871044324
julia> M₂ = randn(ℝ^4 → ℝ^2) # alternative syntax for randn(ℝ^2, ℝ^4)
TensorMap(ℝ^2 ← ℝ^4): 0.28853337725769995 1.3246977136909457 … -0.7514556429216434 -0.10768594661372245 -0.2715315153938657 0.07112819501700204
julia> w = M₁ * v # matrix vector product
TensorMap(ℝ^4 ← ProductSpace{CartesianSpace, 0}()): 0.5004282151287575 -0.1443411495568709 0.08678918335766245 0.2533008295669806
julia> M₃ = M₂ * M₁ # matrix matrix product
TensorMap(ℝ^2 ← ℝ^3): 3.983220670294896 0.4541851572950044 -0.34146103725245736 0.9654326610483654 -0.7320603344814743 -0.1397986002302786
julia> space(M₃)
ℝ^2 ← ℝ^3
Note that for the construction of M₁
, in accordance with how one specifies the dimensions of a matrix (e.g. randn(4,3)
), the first space is the codomain and the second the domain. This is somewhat opposite to the general notation for a function f:domain→codomain
, so that we also support this more mathemical notation, as illustrated in the construction of M₂
. However, as this is confusing from the perspective of rows and columns, we also support the syntax codomain ← domain
and actually use this as the default way of printing HomSpace
instances.
The 'matrix vector' or 'matrix matrix' product can be computed between any two TensorMap
instances for which the domain of the first matches with the codomain of the second, e.g.
julia> v′ = v ⊗ v
TensorMap((ℝ^3 ⊗ ℝ^3) ← ProductSpace{CartesianSpace, 0}()): 0.05897520893818172 -0.03682842492655078 0.4277233367447363 -0.03682842492655078 0.022998356546600887 -0.2671016700110225 0.4277233367447363 -0.2671016700110225 3.1021043602883682
julia> M₁′ = M₁ ⊗ M₁
TensorMap((ℝ^4 ⊗ ℝ^4) ← (ℝ^3 ⊗ ℝ^3)): [:, :, 1, 1] = 1.781588420852184 2.669556311678748 … 0.02648562201596599 2.669556311678748 4.000099471804504 0.03968641611828589 -1.8644745516617107 -2.793754016975555 -0.027717831826768968 0.02648562201596599 0.03968641611828589 0.0003937431144939081 [:, :, 2, 1] = 1.621594060006322 2.4298185861580706 … 0.02410709838140923 0.16607586613287392 0.24885033572482593 0.0024689330963800723 0.6135300272327087 0.9193217341523137 0.009120919403460279 -0.4545433311086936 -0.6810939071507205 -0.00675737601160677 [:, :, 3, 1] = -0.48526640239884167 -0.7271297748723685 … -0.007214114304153156 -0.2443962110356514 -0.3662066053440778 -0.0036332665793417694 0.24413187163485384 0.3658105155920536 0.003629336831386794 -0.23475019984104056 -0.3517528910261659 -0.003489866115198634 [:, :, 1, 2] = 1.621594060006322 0.16607586613287392 … -0.4545433311086936 2.4298185861580706 0.24885033572482593 -0.6810939071507205 -1.697036657075596 -0.17380233415628557 0.47569038031484645 0.02410709838140923 0.0024689330963800723 -0.00675737601160677 [:, :, 2, 2] = 1.4759678861125458 0.15116153365133345 … -0.41372337017591077 0.15116153365133345 0.015481237410934337 -0.04237155816980985 0.5584323720066559 0.05719195829890932 -0.15653221532511347 -0.41372337017591077 -0.04237155816980985 0.11596934366948808 [:, :, 3, 2] = -0.4416873765233613 -0.045235497233992124 … 0.12380783599614674 -0.2224483721744761 -0.022782092627164647 0.06235372130525602 0.2222077715974057 0.022757451472997566 -0.06228627940320081 -0.21366861458688838 -0.021882912072821954 0.0598926983164487 [:, :, 1, 3] = -0.48526640239884167 -0.2443962110356514 … -0.23475019984104056 -0.7271297748723685 -0.3662066053440778 -0.3517528910261659 0.5078428033430393 0.25576643329358695 0.24567165372110114 -0.007214114304153156 -0.0036332665793417694 -0.003489866115198634 [:, :, 2, 3] = -0.4416873765233613 -0.2224483721744761 … -0.21366861458688838 -0.045235497233992124 -0.022782092627164647 -0.021882912072821954 -0.1671123956544741 -0.08416332990116279 -0.0808415090801194 0.12380783599614674 0.06235372130525602 0.0598926983164487 [:, :, 3, 3] = 0.13217614042668518 0.0665682762085141 … 0.06394091003621447 0.0665682762085141 0.03352598572683378 0.03220275721907174 -0.0664962758359612 -0.033489723957714594 -0.032167926656391385 0.06394091003621447 0.03220275721907174 0.03093175487694792
julia> w′ = M₁′ * v′
TensorMap((ℝ^4 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}()): 0.2504283984969539 -0.07223238384237796 … 0.12675888203083763 -0.07223238384237796 0.02083436745539896 -0.03656173292340702 0.04343175612015743 -0.012527250494947018 0.021983772141936683 0.12675888203083768 -0.036561732923406975 0.06416131025932054
julia> w′ ≈ w ⊗ w
true
Another example involves checking that U
from the singular value decomposition is a unitary, or at least a (left) isometric tensor
julia> codomain(U)
(ℝ^3 ⊗ ℝ^4)
julia> domain(U)
ProductSpace(ℝ^2)
julia> space(U)
(ℝ^3 ⊗ ℝ^4) ← ℝ^2
julia> U'*U # should be the identity on the corresponding domain = codomain
TensorMap(ℝ^2 ← ℝ^2): 0.9999999999999991 -4.457223631467284e-17 -4.457223631467284e-17 0.9999999999999992
julia> U'*U ≈ one(U'*U)
true
julia> P = U*U' # should be a projector
TensorMap((ℝ^3 ⊗ ℝ^4) ← (ℝ^3 ⊗ ℝ^4)): [:, :, 1, 1] = 0.0133983191363897 -0.0015666062571573973 … 0.05498179887992175 0.046658606012685774 0.04568886626115985 0.033367537164883054 -0.018579123986151785 -0.04426822558120286 0.020733659240389772 [:, :, 2, 1] = 0.046658606012685774 0.09431246370509988 … 0.03566906165035084 0.5488662824885293 0.1419498833780018 -0.21416796280721123 0.16589144071696582 -0.15884484818606828 0.16493894507229406 [:, :, 3, 1] = -0.018579123986151785 0.06171379933000325 … -0.16922360457707908 0.16589144071696582 -0.07359553842136482 -0.2434329828577627 0.16338006568616123 0.058590156363127505 0.026593599621632033 [:, :, 1, 2] = -0.0015666062571573973 0.02594442103356245 … -0.04665831296741639 0.09431246370509988 -0.009772599770232695 -0.08920624688640635 0.06171379933000325 0.003966576885614718 0.021521087956812904 [:, :, 2, 2] = 0.04568886626115985 -0.009772599770232695 … 0.19440903793041556 0.1419498833780018 0.15656301098995543 0.12845544403764989 -0.07359553842136482 -0.15074861409446744 0.06658459162163728 [:, :, 3, 2] = -0.04426822558120286 0.003966576885614718 … -0.17977178973309427 -0.15884484818606828 -0.15074861409446744 -0.10624166343749736 0.058590156363127505 0.1463195967689961 -0.06962854234514339 [:, :, 1, 3] = -0.005812488277544385 -0.03826366582658969 … 0.03696269435549077 -0.17106097835757922 -0.013123401400259848 0.11447964815143118 -0.08194878300387559 0.02103295795112134 -0.04519297666128698 [:, :, 2, 3] = -0.045175885355815654 -0.01686983088030815 … -0.15079199885321745 -0.243111876539184 -0.1502420903167546 -0.03915386852157941 0.011444741041931794 0.15030178571181618 -0.09049946612234554 [:, :, 3, 3] = -0.002463992367870199 0.010371756047772723 … -0.025858257613355074 0.030471267392736968 -0.010136504073574153 -0.03952698571752078 0.026722892472875955 0.0076676281530256634 0.0055598905472803205 [:, :, 1, 4] = 0.05498179887992175 -0.04665831296741639 … 0.2884488330306786 0.03566906165035084 0.19440903793041556 0.2701425903745677 -0.16922360457707908 -0.17977178973309427 0.04768952029207749 [:, :, 2, 4] = 0.033367537164883054 -0.08920624688640635 … 0.2701425903745677 -0.21416796280721123 0.12845544403764989 0.36557399438820276 -0.2434329828577627 -0.10624166343749736 -0.027656091753503018 [:, :, 3, 4] = 0.020733659240389772 0.021521087956812904 … 0.04768952029207749 0.16493894507229406 0.06658459162163728 -0.027656091753503018 0.026593599621632033 -0.06962854234514339 0.05434248507723965
julia> P*P ≈ P
true
Here, the adjoint of a TensorMap
results in a new tensor map (actually a simple wrapper of type AdjointTensorMap <: AbstractTensorMap
) with domain and codomain interchanged.
Our original tensor A
living in ℝ^4 * ℝ^2 * ℝ^3
is isomorphic to e.g. a linear map ℝ^3 → ℝ^4 * ℝ^2
. This is where the full power of permute
emerges. It allows to specify a permutation where some indices go to the codomain, and others go to the domain, as in
julia> A2 = permute(A,(1,2),(3,))
TensorMap((ℝ^3 ⊗ ℝ^2) ← ℝ^4): [:, :, 1] = 0.26814943036016314 -0.2169061292400202 -1.0004442150718642 -2.7656365992898713 -1.526196119897884 -0.8989523957134242 [:, :, 2] = -0.5307998523589162 -0.493714726466143 1.0002959876817632 -0.6503891173322137 -0.8625198972463062 0.741031814855964 [:, :, 3] = 0.6386842361146164 0.8787872122341243 -0.47466191163443255 1.1777079333672194 -0.24481039500216692 -0.1632910008400414 [:, :, 4] = 1.8803375328404863 -0.07949775555433829 2.321652666836315 1.178660047986449 -0.04928484684616773 -0.81814622657931
julia> codomain(A2)
(ℝ^3 ⊗ ℝ^2)
julia> domain(A2)
ProductSpace(ℝ^4)
In fact, tsvd(A, (1,3),(2,))
is a shorthand for tsvd(permute(A,(1,3),(2,)))
, where tsvd(A::TensorMap)
will just compute the singular value decomposition according to the given codomain and domain of A
.
Note, finally, that the @tensor
macro treats all indices at the same footing and thus does not distinguish between codomain and domain. The linear numbering is first all indices in the codomain, followed by all indices in the domain. However, when @tensor
creates a new tensor (i.e. when using :=
), the default syntax always creates a Tensor
, i.e. with all indices in the codomain.
julia> @tensor A′[a,b,c] := U[a,c,d]*S[d,e]*Vd[e,b];
julia> codomain(A′)
(ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4)
julia> domain(A′)
ProductSpace{CartesianSpace, 0}()
julia> @tensor A2′[(a,b);(c,)] := U[a,c,d]*S[d,e]*Vd[e,b];
julia> codomain(A2′)
(ℝ^3 ⊗ ℝ^2)
julia> domain(A2′)
ProductSpace(ℝ^4)
julia> @tensor A2′′[a b; c] := U[a,c,d]*S[d,e]*Vd[e,b];
julia> A2 ≈ A2′ == A2′′
true
As illustrated for A2′
and A2′′
, additional syntax is available that enables one to immediately specify the desired codomain and domain indices.
Complex tensors
For applications in e.g. quantum physics, we of course want to work with complex tensors. Trying to create a complex-valued tensor with CartesianSpace
indices is of course somewhat contrived and prints a (one-time) warning
julia> A = randn(ComplexF64, ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4)
┌ Warning: scalartype(data) = ComplexF64 ⊈ ℝ) └ @ TensorKit ~/work/TensorKit.jl/TensorKit.jl/src/tensors/tensor.jl:32 TensorMap((ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}()): [:, :, 1] = 0.10109850738011776 + 0.058384986469977494im … 0.09163236695569442 + 0.9354599537716198im 0.30368933101664247 - 0.2490881016264588im -0.029197914876318398 + 0.14577976430272732im 1.1112247720176451 + 0.31949593860919223im -1.503501191030903 - 0.15669661416455782im [:, :, 2] = -0.06628769737062144 + 0.8800374239512369im … 0.19320624409431178 - 0.08134973491758207im -0.4595307661476333 - 0.2560524989905731im -0.10833842601128714 - 0.9541833356406711im -0.5547468443201704 + 0.1551624345404093im 0.6758531566772015 - 0.9626749972863975im [:, :, 3] = 0.1824286992144814 - 1.179371092182523im … -0.03558967384839094 + 0.5623857649866404im 0.3401912616301199 - 0.22894369309283472im -0.27680686826794754 + 0.9589566422390213im -0.006059409799773182 - 0.7809764347148564im -0.6884100144921067 - 0.8910943572623027im [:, :, 4] = -1.1695677402106501 + 0.1487727480308746im … -0.49687899419363596 + 0.3446335098009741im -0.5618910787202971 - 0.6937094684050003im -0.1929196877948082 - 0.5523302316153806im 0.8514790062740912 - 0.6875158737043797im 0.4146653426317972 - 0.1589199323089606im
although most of the above operations will work in the expected way (at your own risk). Indeed, we instead want to work with complex vector spaces
julia> A = randn(ComplexF64, ℂ^3 ⊗ ℂ^2 ⊗ ℂ^4)
TensorMap((ℂ^3 ⊗ ℂ^2 ⊗ ℂ^4) ← ProductSpace{ComplexSpace, 0}()): [:, :, 1] = 0.09724848695056007 - 0.3406745912945275im … 0.9833508966501175 - 0.8837868700074534im 0.18496233416548485 + 0.41692137813476565im 0.1783081271886417 - 0.8981955724645292im -0.8089654711726614 - 1.2541163290549455im 1.2106936268900756 - 0.17269854580185529im [:, :, 2] = -0.09061255283192994 + 0.46080915697530117im … -0.44854416725854324 + 0.673378338681402im -0.9440762193682016 - 0.7443831336463905im -0.1268456608056258 + 2.1964283126528463im 0.43148681215777046 + 0.08788322495406553im -0.19390256354237767 - 0.8582520329799436im [:, :, 3] = 0.5888648600922609 - 0.6912974951616585im … -0.5578618608976975 + 0.7647091594211344im 0.13273914795155875 - 0.13590950665780124im -0.01269152940608178 - 0.48954151084385555im -0.740285837372327 + 0.4314545566011779im 0.6925872856094247 - 0.4738868060284319im [:, :, 4] = 0.5265792900912621 + 0.7541862884765422im … -0.3239787986967588 + 0.17840876240878814im 1.3115832798554583 - 0.22556861294991062im 0.2726332225139222 - 0.5972956053311547im -0.5387997059667675 - 0.21544344245881428im 0.9208430932511695 - 1.1761160234647985im
where ℂ
is obtained as \bbC+TAB
and we also have the non-Unicode alternative ℂ^n == ComplexSpace(n)
. Most functionality works exactly the same
julia> B = randn(ℂ^3 * ℂ^2 * ℂ^4);
julia> C = im*A + (2.5-0.8im)*B
TensorMap((ℂ^3 ⊗ ℂ^2 ⊗ ℂ^4) ← ProductSpace{ComplexSpace, 0}()): [:, :, 1] = -2.951898158180996 + 1.1508717667827277im … -2.343337191069778 + 2.0160305961948315im -2.1968061222975717 + 0.7545254522975828im -0.3197853765995482 + 0.5680620308891464im 1.2784862937570467 - 0.8167638598773338im -2.844013106818178 + 2.1760413557284863im [:, :, 2] = 0.5384031241285017 - 0.4103604827851468im … -2.4515795479798657 + 0.12048021971696515im -3.602121202795612 + 0.44680516829323935im -2.6145036746925028 + 0.006938455047064251im -1.519401310493729 + 0.8895725995304627im -0.40115280529089736 + 0.20910698470429145im [:, :, 3] = -1.5284026847438774 + 1.2991689176620325im … 3.885423326736729 - 2.045904256468214im -6.288771642169024 + 2.1886371155761433im 0.9599678101509646 - 0.16322794518435665im -4.506630306852983 + 0.5637704027082507im -1.3220558417952892 + 1.2672889329130155im [:, :, 4] = -2.202002088446614 + 0.9898803460816851im … 1.4846619760162438 - 0.8561614349927691im -5.359075274555003 + 3.098669323857031im -0.5310226431889149 + 0.6336950620403445im 0.40399454181173944 - 0.5991360577597036im 0.47809306227515846 + 1.1442104408318543im
julia> scalarBA = dot(B,A)
-6.354768874719448 + 5.638554377109303im
julia> scalarAA = dot(A,A)
23.96004177944527 + 0.0im
julia> normA² = norm(A)^2
23.96004177944527
julia> U,S,Vd = tsvd(A,(1,3),(2,));
julia> @tensor A′[a,b,c] := U[a,c,d]*S[d,e]*Vd[e,b];
julia> A′ ≈ A
true
julia> permute(A,(1,3),(2,)) ≈ U*S*Vd
true
However, trying the following
julia> @tensor D[a,b,c,d] := A[a,b,e]*B[d,c,e]
ERROR: SpaceMismatch("ProductSpace((ℂ^4)') ≠ ProductSpace(ℂ^4)")
julia> @tensor d = A[a,b,c]*A[a,b,c]
ERROR: SpaceMismatch("((ℂ^3)' ⊗ (ℂ^2)' ⊗ (ℂ^4)') ≠ (ℂ^3 ⊗ ℂ^2 ⊗ ℂ^4)")
we obtain SpaceMismatch
errors. The reason for this is that, with ComplexSpace
, an index in a space ℂ^n
can only be contracted with an index in the dual space dual(ℂ^n) == (ℂ^n)'
. Because of the complex Euclidean inner product, the dual space is equivalent to the complex conjugate space, but not the the space itself.
julia> dual(ℂ^3) == conj(ℂ^3) == (ℂ^3)'
true
julia> (ℂ^3)' == ℂ^3
false
julia> @tensor d = conj(A[a,b,c])*A[a,b,c]
23.96004177944527 + 0.0im
julia> d ≈ normA²
true
This might seem overly strict or puristic, but we believe that it can help to catch errors, e.g. unintended contractions. In particular, contracting two indices both living in ℂ^n
would represent an operation that is not invariant under arbitrary unitary basis changes.
It also makes clear the isomorphism between linear maps ℂ^n → ℂ^m
and tensors in ℂ^m ⊗ (ℂ^n)'
:
julia> m = randn(ComplexF64, ℂ^3, ℂ^4)
TensorMap(ℂ^3 ← ℂ^4): -0.5306359223607394 + 0.19735515490398897im … -1.047132328918675 - 0.6270843872373263im -0.38370718349065985 - 0.4397798082912746im 0.20707841342836736 - 1.6971022130772506im -0.4395004737209958 + 0.6358084102599134im -1.0216152079715832 - 0.8086898415615119im
julia> m2 = permute(m, (1,2), ())
TensorMap((ℂ^3 ⊗ (ℂ^4)') ← ProductSpace{ComplexSpace, 0}()): -0.5306359223607394 + 0.19735515490398897im … -1.047132328918675 - 0.6270843872373263im -0.38370718349065985 - 0.4397798082912746im 0.20707841342836736 - 1.6971022130772506im -0.4395004737209958 + 0.6358084102599134im -1.0216152079715832 - 0.8086898415615119im
julia> codomain(m2)
(ℂ^3 ⊗ (ℂ^4)')
julia> space(m, 1)
ℂ^3
julia> space(m, 2)
(ℂ^4)'
Hence, spaces become their corresponding dual space if they are 'permuted' from the domain to the codomain or vice versa. Also, spaces in the domain are reported as their dual when probing them with space(A, i)
. Generalizing matrix vector and matrix matrix multiplication to arbitrary tensor contractions require that the two indices to be contracted have spaces which are each others dual. Knowing this, all the other functionality of tensors with CartesianSpace
indices remains the same for tensors with ComplexSpace
indices.
Symmetries
So far, the functionality that we have illustrated seems to be just a convenient (or inconvenient?) wrapper around dense multidimensional arrays, e.g. Julia's Base Array
. More power becomes visible when involving symmetries. With symmetries, we imply that there is some symmetry action defined on every vector space associated with each of the indices of a TensorMap
, and the TensorMap
is then required to be equivariant, i.e. it acts as an intertwiner between the tensor product representation on the domain and that on the codomain. By Schur's lemma, this means that the tensor is block diagonal in some basis corresponding to the irreducible representations that can be coupled to by combining the different representations on the different spaces in the domain or codomain. For Abelian symmetries, this does not require a basis change and it just imposes that the tensor has some block sparsity. Let's clarify all of this with some examples.
We start with a simple $ℤ₂$ symmetry:
julia> V1 = ℤ₂Space(0=>3,1=>2)
Rep[ℤ₂](0=>3, 1=>2)
julia> dim(V1)
5
julia> V2 = ℤ₂Space(0=>1,1=>1)
Rep[ℤ₂](0=>1, 1=>1)
julia> dim(V2)
2
julia> A = randn(V1*V1*V2')
TensorMap((Rep[ℤ₂](0=>3, 1=>2) ⊗ Rep[ℤ₂](0=>3, 1=>2) ⊗ Rep[ℤ₂](0=>1, 1=>1)') ← ProductSpace{GradedSpace{Z2Irrep, Tuple{Int64, Int64}}, 0}()): * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](0), Irrep[ℤ₂](0)) ← (): [:, :, 1] = -0.4472453303632673 -1.3896290022592985 -0.8582092659133544 -0.508003968537569 -0.15416520644636625 1.1709360396138127 0.6680113635656999 0.5819982330197675 1.3333201124358622 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (): [:, :, 1] = 0.18647862529409087 1.5214348240330762 0.95382142510749 -0.9171464332101884 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (): [:, :, 1] = -0.6644490015807565 -0.23924273439403473 0.7014598734185198 -1.752946018035769 0.15662158600155882 1.6983960700791663 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (): [:, :, 1] = -1.4927509197493176 0.529331835112161 -1.2661783455296183 0.8243346629719457 0.9566006442326993 -0.5969347620651088
julia> convert(Array, A)
5×5×2 Array{Float64, 3}: [:, :, 1] = -0.447245 -1.38963 -0.858209 0.0 0.0 -0.508004 -0.154165 1.17094 0.0 0.0 0.668011 0.581998 1.33332 0.0 0.0 0.0 0.0 0.0 0.186479 1.52143 0.0 0.0 0.0 0.953821 -0.917146 [:, :, 2] = 0.0 0.0 0.0 -1.49275 0.529332 0.0 0.0 0.0 -1.26618 0.824335 0.0 0.0 0.0 0.956601 -0.596935 -0.664449 -0.239243 0.70146 0.0 0.0 -1.75295 0.156622 1.6984 0.0 0.0
Here, we create a 5-dimensional space V1
, which has a three-dimensional subspace associated with charge 0 (the trivial irrep of $ℤ₂$) and a two-dimensional subspace with charge 1 (the non-trivial irrep). Similar for V2
, where both subspaces are one- dimensional. Representing the tensor as a dense Array
, we see that it is zero in those regions where the charges don't add to zero (modulo 2). Of course, the Tensor(Map)
type in TensorKit.jl won't store these zero blocks, and only stores the non-zero information, which we can recognize also in the full Array
representation.
From there on, the resulting tensors support all of the same operations as the ones we encountered in the previous examples.
julia> B = randn(V1'*V1*V2);
julia> @tensor C[a,b] := A[a,c,d]*B[c,b,d]
TensorMap((Rep[ℤ₂](0=>3, 1=>2) ⊗ Rep[ℤ₂](0=>3, 1=>2)) ← ProductSpace{GradedSpace{Z2Irrep, Tuple{Int64, Int64}}, 0}()): * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](0)) ← (): -0.6464035510952867 0.39104572100328366 -1.6487462096231722 2.348456431741502 2.0564375972249396 -1.3411852149572223 0.6257816438123571 0.5739576124320414 1.9229557448607988 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (): -0.5992314938926434 0.8506563941844599 5.851992320702361 2.1771855696182363
julia> U,S,V = tsvd(A,(1,3),(2,));
julia> U'*U # should be the identity on the corresponding domain = codomain
TensorMap(Rep[ℤ₂](0=>3, 1=>2) ← Rep[ℤ₂](0=>3, 1=>2)): * Data for sector (Irrep[ℤ₂](0),) ← (Irrep[ℤ₂](0),): 0.9999999999999998 1.0457541463059424e-15 -8.378659037470288e-17 1.0457541463059424e-15 0.9999999999999989 -2.7287769931206685e-19 -8.378659037470288e-17 -2.7287769931206685e-19 0.9999999999999997 * Data for sector (Irrep[ℤ₂](1),) ← (Irrep[ℤ₂](1),): 1.0000000000000004 -1.0820409604481732e-16 -1.0820409604481732e-16 1.0000000000000004
julia> U'*U ≈ one(U'*U)
true
julia> P = U*U' # should be a projector
TensorMap((Rep[ℤ₂](0=>3, 1=>2) ⊗ Rep[ℤ₂](0=>1, 1=>1)') ← (Rep[ℤ₂](0=>3, 1=>2) ⊗ Rep[ℤ₂](0=>1, 1=>1)')): * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](0)): [:, :, 1, 1] = 0.8635330731739157 0.19656713459704178 -0.16145407669235434 [:, :, 2, 1] = 0.19656713459704178 0.36589367005433415 0.33932353690868694 [:, :, 3, 1] = -0.16145407669235434 0.33932353690868694 0.7765058708474936 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](0)): [:, :, 1, 1] = 0.17502265215751978 -0.15001572802944071 [:, :, 2, 1] = 0.21187051026056838 0.18261237101170869 [:, :, 3, 1] = 0.0659292448926652 -0.16730199184095082 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.17502265215751978 0.21187051026056838 0.0659292448926652 [:, :, 2, 1] = -0.15001572802944071 0.18261237101170869 -0.16730199184095082 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.16216900199294595 0.2366463808451654 [:, :, 2, 1] = 0.2366463808451654 0.831898383931309 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](0)): [:, :, 1, 1] = 0.912270575506748 -0.20094882500343522 [:, :, 2, 1] = -0.20094882500343522 0.21935941606118056 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](0)): [:, :, 1, 1] = -0.19242559652145497 0.04678526091965535 -0.02088232422686623 [:, :, 2, 1] = -0.2134060570453025 -0.23482810772020207 0.17370678460308786 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](1)): [:, :, 1, 1] = -0.19242559652145497 -0.2134060570453025 [:, :, 2, 1] = 0.04678526091965535 -0.23482810772020207 [:, :, 3, 1] = -0.02088232422686623 0.17370678460308786 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.4142678537549468 0.31813001125645773 -0.2426387018963018 [:, :, 2, 1] = 0.31813001125645773 0.29030114081498054 -0.21791416562421195 [:, :, 3, 1] = -0.2426387018963018 -0.21791416562421195 0.16380101386214493
julia> P*P ≈ P
true
We also support other abelian symmetries, e.g.
julia> V = U₁Space(0=>2,1=>1,-1=>1)
Rep[U₁](0=>2, 1=>1, -1=>1)
julia> dim(V)
4
julia> A = randn(V*V, V)
TensorMap((Rep[U₁](0=>2, 1=>1, -1=>1) ⊗ Rep[U₁](0=>2, 1=>1, -1=>1)) ← Rep[U₁](0=>2, 1=>1, -1=>1)): * Data for sector (Irrep[U₁](0), Irrep[U₁](0)) ← (Irrep[U₁](0),): [:, :, 1] = 0.8618680483815161 -0.06193519093348356 0.5313739361675629 -0.09040044377162845 [:, :, 2] = -0.3155908889289009 -1.9394459733372664 0.07515375137348727 0.35154917812104447 * Data for sector (Irrep[U₁](-1), Irrep[U₁](1)) ← (Irrep[U₁](0),): [:, :, 1] = -0.31257939754651193 [:, :, 2] = -0.9917126577135643 * Data for sector (Irrep[U₁](1), Irrep[U₁](-1)) ← (Irrep[U₁](0),): [:, :, 1] = -0.01998676109258198 [:, :, 2] = -0.22501796204870547 * Data for sector (Irrep[U₁](1), Irrep[U₁](0)) ← (Irrep[U₁](1),): [:, :, 1] = -0.8514862156723214 0.5486427765151223 * Data for sector (Irrep[U₁](0), Irrep[U₁](1)) ← (Irrep[U₁](1),): [:, :, 1] = -1.0722988805590576 1.4615818029308352 * Data for sector (Irrep[U₁](-1), Irrep[U₁](0)) ← (Irrep[U₁](-1),): [:, :, 1] = 0.8051813808195538 1.4327857211404842 * Data for sector (Irrep[U₁](0), Irrep[U₁](-1)) ← (Irrep[U₁](-1),): [:, :, 1] = -0.36456393599298215 -1.0841525114626427
julia> dim(A)
20
julia> convert(Array, A)
4×4×4 Array{Float64, 3}: [:, :, 1] = 0.861868 -0.0619352 0.0 0.0 0.531374 -0.0904004 0.0 0.0 0.0 0.0 0.0 -0.0199868 0.0 0.0 -0.312579 0.0 [:, :, 2] = -0.315591 -1.93945 0.0 0.0 0.0751538 0.351549 0.0 0.0 0.0 0.0 0.0 -0.225018 0.0 0.0 -0.991713 0.0 [:, :, 3] = 0.0 0.0 -1.0723 0.0 0.0 0.0 1.46158 0.0 -0.851486 0.548643 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 4] = 0.0 0.0 0.0 -0.364564 0.0 0.0 0.0 -1.08415 0.0 0.0 0.0 0.0 0.805181 1.43279 0.0 0.0
julia> V = Rep[U₁×ℤ₂]((0, 0) => 2, (1, 1) => 1, (-1, 0) => 1)
Rep[U₁ × ℤ₂]((0, 0)=>2, (1, 1)=>1, (-1, 0)=>1)
julia> dim(V)
4
julia> A = randn(V*V, V)
TensorMap((Rep[U₁ × ℤ₂]((0, 0)=>2, (1, 1)=>1, (-1, 0)=>1) ⊗ Rep[U₁ × ℤ₂]((0, 0)=>2, (1, 1)=>1, (-1, 0)=>1)) ← Rep[U₁ × ℤ₂]((0, 0)=>2, (1, 1)=>1, (-1, 0)=>1)): * Data for sector (Irrep[U₁ × ℤ₂](0, 0), Irrep[U₁ × ℤ₂](0, 0)) ← (Irrep[U₁ × ℤ₂](0, 0),): [:, :, 1] = -0.3154980506167828 -2.361427260746583 0.23140836519510247 -2.368833684559248 [:, :, 2] = -0.7638522505596368 -0.7962057409088035 0.3834057042943979 1.133749209888438 * Data for sector (Irrep[U₁ × ℤ₂](1, 1), Irrep[U₁ × ℤ₂](0, 0)) ← (Irrep[U₁ × ℤ₂](1, 1),): [:, :, 1] = -1.7762382029254458 0.49007427499466755 * Data for sector (Irrep[U₁ × ℤ₂](0, 0), Irrep[U₁ × ℤ₂](1, 1)) ← (Irrep[U₁ × ℤ₂](1, 1),): [:, :, 1] = -1.4984696390596068 -1.6427447876766614 * Data for sector (Irrep[U₁ × ℤ₂](-1, 0), Irrep[U₁ × ℤ₂](0, 0)) ← (Irrep[U₁ × ℤ₂](-1, 0),): [:, :, 1] = 1.3271224277872309 -0.484190151614686 * Data for sector (Irrep[U₁ × ℤ₂](0, 0), Irrep[U₁ × ℤ₂](-1, 0)) ← (Irrep[U₁ × ℤ₂](-1, 0),): [:, :, 1] = -0.602370553619417 -1.1982463723057597
julia> dim(A)
16
julia> convert(Array, A)
4×4×4 Array{Float64, 3}: [:, :, 1] = -0.315498 -2.36143 0.0 0.0 0.231408 -2.36883 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 2] = -0.763852 -0.796206 0.0 0.0 0.383406 1.13375 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 3] = 0.0 0.0 -1.49847 0.0 0.0 0.0 -1.64274 0.0 -1.77624 0.490074 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 4] = 0.0 0.0 0.0 -0.602371 0.0 0.0 0.0 -1.19825 0.0 0.0 0.0 0.0 1.32712 -0.48419 0.0 0.0
Here, the dim
of a TensorMap
returns the number of linearly independent components, i.e. the number of non-zero entries in the case of an abelian symmetry. Also note that we can use ×
(obtained as \times+TAB
) to combine different symmetry groups. The general space associated with symmetries is a GradedSpace
, which is parametrized to the type of symmetry. For a group G
, the fully specified type can be obtained as Rep[G]
, while for more general sectortypes I
it can be constructed as Vect[I]
. Furthermore, ℤ₂Space
(also Z2Space
as non-Unicode alternative) and U₁Space
(or U1Space
) are just convenient synonyms, e.g.
julia> Rep[U₁](0=>3,1=>2,-1=>1) == U1Space(-1=>1,1=>2,0=>3)
true
julia> V = U₁Space(1=>2,0=>3,-1=>1)
Rep[U₁](0=>3, 1=>2, -1=>1)
julia> for s in sectors(V) @show s, dim(V, s) end
(s, dim(V, s)) = (Irrep[U₁](0), 3) (s, dim(V, s)) = (Irrep[U₁](1), 2) (s, dim(V, s)) = (Irrep[U₁](-1), 1)
julia> U₁Space(-1=>1,0=>3,1=>2) == GradedSpace(Irrep[U₁](1)=>2, Irrep[U₁](0)=>3, Irrep[U₁](-1)=>1)
true
julia> supertype(GradedSpace)
ElementarySpace
Note that GradedSpace
is not immediately parameterized by some group G
, but actually by the set of irreducible representations of G
, denoted as Irrep[G]
. Indeed, GradedSpace
also supports a grading that is derived from the fusion ring of a (unitary) pre-fusion category. Note furthermore that the order in which the charges and their corresponding subspace dimensionality are specified is irrelevant, and that the charges, henceforth called sectors (which is a more general name for charges or quantum numbers) are of a specific type, in this case Irrep[U₁] == U1Irrep
. However, the Vect[I]
constructor automatically converts the keys in the list of Pair
s it receives to the correct type. Alternatively, we can directly create the sectors of the correct type and use the generic GradedSpace
constructor. We can probe the subspace dimension of a certain sector s
in a space V
with dim(V, s)
. Finally, note that GradedSpace
is also a subtype of EuclideanSpace
, which implies that it still has the standard Euclidean inner product and we assume all representations to be unitary.
TensorKit.jl also allows for non-abelian symmetries such as SU₂
. In this case, the vector space is characterized via the spin quantum number (i.e. the irrep label of SU₂
) for each of its subspaces, and is created using SU₂Space
(or SU2Space
or Rep[SU₂]
or Vect[Irrep[SU₂]]
)
julia> V = SU₂Space(0=>2,1/2=>1,1=>1)
Rep[SU₂](0=>2, 1/2=>1, 1=>1)
julia> dim(V)
7
julia> V == Vect[Irrep[SU₂]](0=>2, 1=>1, 1//2=>1)
true
Note that now V
has a two-dimensional subspace with spin zero, and two one-dimensional subspaces with spin 1/2 and spin 1. However, a subspace with spin j
has an additional 2j+1
dimensional degeneracy on which the irreducible representation acts. This brings the total dimension to 2*1 + 1*2 + 1*3
. Creating a tensor with SU₂
symmetry yields
julia> A = randn(V*V, V)
TensorMap((Rep[SU₂](0=>2, 1/2=>1, 1=>1) ⊗ Rep[SU₂](0=>2, 1/2=>1, 1=>1)) ← Rep[SU₂](0=>2, 1/2=>1, 1=>1)): * Data for fusiontree FusionTree{Irrep[SU₂]}((0, 0), 0, (false, false), ()) ← FusionTree{Irrep[SU₂]}((0,), 0, (false,), ()): [:, :, 1] = 0.6415056763113447 -0.11647710235790894 -0.014432251953444754 0.28429851238028736 [:, :, 2] = 1.8389852629725991 0.3012294206839654 -0.28703662922203665 1.879419970264739 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1/2), 0, (false, false), ()) ← FusionTree{Irrep[SU₂]}((0,), 0, (false,), ()): [:, :, 1] = -0.27107924522767357 [:, :, 2] = -1.4471048364872476 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1), 0, (false, false), ()) ← FusionTree{Irrep[SU₂]}((0,), 0, (false,), ()): [:, :, 1] = -2.152238626472316 [:, :, 2] = -1.7729234968892795 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 0), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -0.04655762304653508 0.8450972750675583 * Data for fusiontree FusionTree{Irrep[SU₂]}((0, 1/2), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = 0.44302341509099924 0.6780379325764511 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1/2), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -0.8836012764133965 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -0.04523733666657002 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 0), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = -0.3187024625820884 -0.33478507577534444 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1/2), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = 0.8373989516351621 * Data for fusiontree FusionTree{Irrep[SU₂]}((0, 1), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = 0.14859075383784728 -2.515195241502627 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = -1.0442619873186176
julia> dim(A)
24
julia> convert(Array, A)
7×7×7 Array{Float64, 3}: [:, :, 1] = 0.641506 -0.116477 0.0 0.0 0.0 0.0 0.0 -0.0144323 0.284299 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.191682 0.0 0.0 0.0 0.0 0.0 0.191682 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.2426 0.0 0.0 0.0 0.0 0.0 1.2426 0.0 0.0 0.0 0.0 0.0 -1.2426 0.0 0.0 [:, :, 2] = 1.83899 0.301229 0.0 0.0 0.0 0.0 0.0 -0.287037 1.87942 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.02326 0.0 0.0 0.0 0.0 0.0 1.02326 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.0236 0.0 0.0 0.0 0.0 0.0 1.0236 0.0 0.0 0.0 0.0 0.0 -1.0236 0.0 0.0 [:, :, 3] = 0.0 0.0 0.443023 0.0 0.0 0.0 0.0 0.0 0.0 0.678038 0.0 0.0 0.0 0.0 -0.0465576 0.845097 0.0 0.0 0.0 -0.0261178 0.0 0.0 0.0 0.0 0.0 0.0369361 0.0 0.0 0.0 0.0 0.0 -0.721457 0.0 0.0 0.0 0.0 0.0 0.510147 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 4] = 0.0 0.0 0.0 0.443023 0.0 0.0 0.0 0.0 0.0 0.0 0.678038 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.0369361 -0.0465576 0.845097 0.0 0.0 0.0 0.0261178 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.510147 0.0 0.0 0.0 0.0 0.0 0.721457 0.0 0.0 0.0 0.0 [:, :, 5] = 0.0 0.0 0.0 0.0 0.148591 0.0 0.0 0.0 0.0 0.0 0.0 -2.5152 0.0 0.0 0.0 0.0 0.837399 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.318702 -0.334785 0.0 0.0 0.0 -0.738405 0.0 0.0 0.0 0.0 0.0 0.738405 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 6] = 0.0 0.0 0.0 0.0 0.0 0.148591 0.0 0.0 0.0 0.0 0.0 0.0 -2.5152 0.0 0.0 0.0 0.0 0.59213 0.0 0.0 0.0 0.0 0.0 0.59213 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.738405 -0.318702 -0.334785 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.738405 0.0 0.0 [:, :, 7] = 0.0 0.0 0.0 0.0 0.0 0.0 0.148591 0.0 0.0 0.0 0.0 0.0 0.0 -2.5152 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.837399 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.738405 -0.318702 -0.334785 0.0 0.0 0.0 0.738405 0.0
julia> norm(A) ≈ norm(convert(Array, A))
true
In this case, the full Array
representation of the tensor has again many zeros, but it is less obvious to recognize the dense blocks, as there are additional zeros and the numbers in the original tensor data do not match with those in the Array
. The reason is of course that the original tensor data now needs to be transformed with a construction known as fusion trees, which are made up out of the Clebsch-Gordan coefficients of the group. Indeed, note that the non-zero blocks are also no longer labeled by a list of sectors, but by pair of fusion trees. This will be explained further in the manual. However, the Clebsch-Gordan coefficients of the group are only needed to actually convert a tensor to an Array
. For working with tensors with SU₂Space
indices, e.g. contracting or factorizing them, the Clebsch-Gordan coefficients are never needed explicitly. Instead, recoupling relations are used to symbolically manipulate the basis of fusion trees, and this only requires what is known as the topological data of the group (or its representation theory).
In fact, this formalism extends beyond the case of group representations on vector spaces, and can also deal with super vector spaces (to describe fermions) and more general (unitary) fusion categories. Support for all of these generalizations is present in TensorKit.jl. Indeed, all of these concepts will be explained throughout the remainder of this manual, including several details regarding their implementation. However, to just use tensors and their manipulations (contractions, factorizations, ...) in higher level algorithms (e.g. tensoer network algorithms), one does not need to know or understand most of these details, and one can immediately refer to the general interface of the TensorMap
type, discussed on the last page. Adhering to this interface should yield code and algorithms that are oblivious to the underlying symmetries and can thus work with arbitrary symmetric tensors.