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] = 1.1708435894546758 -1.5886163269800004 -0.381048046138748 1.0688641120394895 -0.27125847591802366 -1.1448788617945025 [:, :, 2] = 1.8763146716849994 1.3285158304861175 0.611107532423627 0.7697632169086024 0.4638423781178158 0.06549981919819921 [:, :, 3] = -1.0907322148146594 -1.8823856031477335 1.3130045412706088 -1.0650983469797513 -0.6642770823623377 -2.1605128418616353 [:, :, 4] = -0.7035017288558382 -1.528624874062647 1.0905416305991065 0.3242311584160197 -1.4137257633797824 2.6527134778034838
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.6094160575244569 -0.2667828862608196 -5.703842514751949 2.0079994009348328 0.15150504095775946 -2.23779742551776 [:, :, 2] = -4.418337012621754 -1.6347651078894767 -0.9285291631302903 -4.5499257031051235 0.2914598781625315 3.87846954925709 [:, :, 3] = -2.6823579097205115 -0.5498073587125912 1.8717274260643442 0.7284488981033569 -1.4730716615993413 -1.6820153466407808 [:, :, 4] = -4.550370331460441 1.8491237949820913 2.6006885303018117 3.6843946267776215 0.6808119849418675 -3.4226544013340865
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)
-8.969194623256781
julia> scalarAA = dot(A,A)
38.89960471024108
julia> normA² = norm(A)^2
38.89960471024108
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] = -2.465926127650033 2.089083255634145 -4.081101070246399 -1.7942273753583335 2.077916803379715 -2.2014564110240564 [:, :, 2, 1] = -2.3845978632561247 -3.449610281256193 0.7031956443848582 -0.310142820912345 -2.065660208526941 2.1330264437251185 [:, :, 1, 2] = -4.616894664125467 0.6758256324239882 2.0735186397861454 -2.988337502846901 -1.1159715153215146 3.6232697247061707 [:, :, 2, 2] = -4.5549100400710385 -6.661932303164306 0.7678761014840465 -0.9698576980230629 -3.402351658526237 1.843563793409505 [:, :, 1, 3] = 0.28644939492171606 -0.1402425402950169 -0.02310422847038093 0.8071486516040224 -0.5016668101955686 2.3285081147340456 [:, :, 2, 3] = 3.7052807377058317 6.458765286362001 -1.1937507621828976 0.11256287229142337 3.7396337110788416 -3.655652345918068
julia> @tensor d = A[a,b,c]*A[a,b,c]
38.89960471024108
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.29609782376113236 -0.2808961077842776 … 0.3062446387618147 -0.20396266475505573 -0.15720765283514165 -0.07592671069524908 0.2263857795395148 -0.01817657679690274 -0.5007412368762599 [:, :, 2] = 0.3547202374686868 0.5035554162238675 … -0.17154089588002805 -0.12468637023457707 0.15835983994501826 0.3001765216435525 -0.05683918630576709 0.12888752231523226 -0.44060791302403385
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}()): -1.1131071683767932 -0.5307591843207126 0.5693442961548408
julia> M₁ = randn(ℝ^4, ℝ^3)
TensorMap(ℝ^4 ← ℝ^3): -0.442293107501099 -0.4631021949540687 -0.7022905503619539 -0.9164081968381188 0.45961186573014506 0.5674417413670999 1.1817615668611277 -2.029258825092949 -0.5507512600916962 -0.5404626835656775 0.48229816193053243 0.04077785775573257
julia> M₂ = randn(ℝ^4 → ℝ^2) # alternative syntax for randn(ℝ^2, ℝ^4)
TensorMap(ℝ^2 ← ℝ^4): 1.0834755457870933 -0.659196989652644 … 0.12502109442883677 1.759330697247123 2.5843789212328123 -0.5045503136905867
julia> w = M₁ * v # matrix vector product
TensorMap(ℝ^4 ← ProductSpace{CartesianSpace, 0}()): 0.3382702526420516 1.0991870329482374 -0.5519466011366694 0.3688253490141256
julia> M₃ = M₂ * M₁ # matrix matrix product
TensorMap(ℝ^2 ← ℝ^3): 0.0396386996363099 -0.7140920928210802 -1.12163661003049 -1.337635446611281 -2.508095224289775 -0.5055672737395983
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}()): 1.2390075682918027 0.5907918527492049 -0.6337412173243933 0.5907918527492049 0.2817053117407881 -0.30218471422479354 -0.6337412173243933 -0.30218471422479354 0.3241529275640511
julia> M₁′ = M₁ ⊗ M₁
TensorMap((ℝ^4 ⊗ ℝ^4) ← (ℝ^3 ⊗ ℝ^3)): [:, :, 1, 1] = 0.19562319294297872 0.4053210291190104 … 0.23904291980264666 0.4053210291190104 0.8398039832320923 0.49528443330471333 -0.5226849957323759 -1.0829759865797959 -0.6386980277605449 0.23904291980264666 0.49528443330471333 0.29209991232701366 [:, :, 2, 1] = 0.20482690889681482 0.42439064742963306 … 0.25028945505003153 -0.20328316033816374 -0.4211920811191658 -0.24840306235114204 0.8975271916743897 1.859629420821269 1.0967386702590691 -0.21331715278232344 -0.44198198891309826 -0.2606641588757692 [:, :, 3, 1] = 0.31061826988824565 0.6435848169136482 … 0.3795618354914382 -0.25097557111508956 -0.5200082630169062 -0.3066810863064439 0.2435934862861023 0.5047129691669531 0.29766050400633653 -0.018035765424020748 -0.03736916309685218 -0.0220389104327227 [:, :, 1, 2] = 0.20482690889681482 -0.20328316033816374 … -0.21331715278232344 0.42439064742963306 -0.4211920811191658 -0.44198198891309826 -0.5472763755257476 0.5431516385932225 0.5699614315372679 0.25028945505003153 -0.24840306235114204 -0.2606641588757692 [:, :, 2, 2] = 0.21446364297127624 -0.21284726384656488 … -0.22335333741234242 -0.21284726384656488 0.2112430671199449 0.22166995804311163 0.9397542160304593 -0.9326714346503324 -0.9787078014236411 -0.22335333741234242 0.22166995804311163 0.2326115170015701 [:, :, 3, 2] = 0.32523229536812176 -0.32278107013650803 … -0.3387134415807524 -0.2627835159356629 0.2608029574428952 0.27367610886401283 0.25505411742218365 -0.25313181420397285 -0.26562632042314965 -0.018884315432204545 0.01874198728359071 0.019667085843054523 [:, :, 1, 3] = 0.31061826988824565 -0.25097557111508956 … -0.018035765424020748 0.6435848169136482 -0.5200082630169062 -0.03736916309685218 -0.8299399811875063 0.6705808413803908 0.048189705074654705 0.3795618354914382 -0.3066810863064439 -0.0220389104327227 [:, :, 2, 3] = 0.32523229536812176 -0.2627835159356629 … -0.018884315432204545 -0.32278107013650803 0.2608029574428952 0.01874198728359071 1.4251292971013791 -1.1514861613952982 -0.08274882771920528 -0.3387134415807524 0.27367610886401283 0.019667085843054523 [:, :, 3, 3] = 0.4932120171276961 -0.3985089728430461 … -0.028637904165854895 -0.3985089728430461 0.3219901298457267 0.023139058614132787 0.38678740556233693 -0.3125192540865566 -0.022458456542809657 -0.028637904165854895 0.023139058614132787 0.0016628336831467586
julia> w′ = M₁′ * v′
TensorMap((ℝ^4 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}()): 0.11442676382251743 0.37182227533626744 … 0.12476264399180115 0.37182227533626744 1.2082121334015494 0.40540804105893474 -0.18670711621142277 -0.60669254684928 -0.20357189780139245 0.12476264399180116 0.4054080410589348 0.13603213807539158
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): 1.0000000000000007 2.2301398178853353e-17 2.2301398178853353e-17 0.9999999999999999
julia> U'*U ≈ one(U'*U)
true
julia> P = U*U' # should be a projector
TensorMap((ℝ^3 ⊗ ℝ^4) ← (ℝ^3 ⊗ ℝ^4)): [:, :, 1, 1] = 0.21350036810592016 0.09544857060367662 … 0.029829343753732616 -0.1046216800212112 0.00962459614771906 0.08399695323772101 0.046870326988209185 0.04033696768941986 -0.304560934044986 [:, :, 2, 1] = -0.1046216800212112 -0.005494178397911084 … -0.041073660934740935 0.05714745953625728 0.012319178158470272 -0.021941706673886337 -0.039087175029977037 -0.012363174286393165 0.15707031839762356 [:, :, 3, 1] = 0.046870326988209185 -0.09221256444838576 … 0.07907967621587364 -0.039087175029977037 -0.04459062148264731 -0.034250516826930186 0.05448121427761551 -0.011440780400890884 -0.08831690000164465 [:, :, 1, 2] = 0.09544857060367662 0.3324706805767489 … -0.1724032742822785 -0.005494178397911084 0.12390197291195194 0.1724830308080102 -0.09221256444838576 0.07000773962060178 -0.08121423658872055 [:, :, 2, 2] = 0.00962459614771906 0.12390197291195194 … -0.07530918966867702 0.012319178158470272 0.04979208501734622 0.059472165898618236 -0.04459062148264731 0.023268104379568926 0.008945755942087982 [:, :, 3, 2] = 0.04033696768941986 0.07000773962060178 … -0.027675960240805913 -0.012363174286393165 0.023268104379568926 0.04006909581973059 -0.011440780400890884 0.0169423813526132 -0.04768710067469567 [:, :, 1, 3] = 0.015198246253096208 -0.24470539203038666 … 0.1633156700735412 -0.04327088482238662 -0.10310815187923066 -0.11111944779899793 0.1015474032985885 -0.04223426730170238 -0.06936354782894753 [:, :, 2, 3] = 0.19380696010405804 0.14023124366152934 … -0.007267238348844731 -0.08733847182311358 0.030851972740723228 0.10119918431030235 0.021621260540377343 0.04622689614282978 -0.26630824967071304 [:, :, 3, 3] = 0.07382776629525752 -0.19601735702320042 … 0.15710121116345374 -0.06879956996766488 -0.09118901725436952 -0.07758772327906326 0.10564129305743913 -0.02712615406181436 -0.14873780282068003 [:, :, 1, 4] = 0.029829343753732616 -0.1724032742822785 … 0.12321205772967699 -0.041073660934740935 -0.07530918966867702 -0.074744697534125 0.07907967621587364 -0.027675960240805913 -0.07776704306834226 [:, :, 2, 4] = 0.08399695323772101 0.1724830308080102 … -0.074744697534125 -0.021941706673886337 0.059472165898618236 0.0958708095430222 -0.034250516826930186 0.04006909581973059 -0.09424051571469443 [:, :, 3, 4] = -0.304560934044986 -0.08121423658872055 … -0.07776704306834226 0.15707031839762356 0.008945755942087982 -0.09424051571469443 -0.08831690000164465 -0.04768710067469567 0.4448771193277612
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] = 1.1708435894546758 -1.5886163269800004 -0.381048046138748 1.0688641120394895 -0.27125847591802366 -1.1448788617945025 [:, :, 2] = 1.8763146716849994 1.3285158304861175 0.611107532423627 0.7697632169086024 0.4638423781178158 0.06549981919819921 [:, :, 3] = -1.0907322148146594 -1.8823856031477335 1.3130045412706088 -1.0650983469797513 -0.6642770823623377 -2.1605128418616353 [:, :, 4] = -0.7035017288558382 -1.528624874062647 1.0905416305991065 0.3242311584160197 -1.4137257633797824 2.6527134778034838
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:29 TensorMap((ℝ^3 ⊗ ℝ^2 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}()): [:, :, 1] = -0.9895023782850492 + 0.9715906398868588im … 0.31953367983828546 + 0.2996890742385173im 0.5247793908509883 + 0.713882947231014im -1.2694231564823124 - 0.2591209447567897im 0.05280281469370158 + 0.9327006171088899im 1.1450423852631275 - 0.5011659120297319im [:, :, 2] = -0.6312828543345019 - 0.8317951038391252im … -0.20773169426454777 + 0.6138368245690893im 0.7920503608983905 - 0.6351545426621443im -1.1800519518005266 + 0.20160186434076524im -1.2497603684403096 + 0.49822246853708396im -0.8607349386429192 - 0.9661412361779946im [:, :, 3] = 0.3627058220638841 + 0.8225752788611455im … 0.07988812716984305 + 0.4745292062836807im -0.7568973786718524 - 0.4971734987954001im 1.3142221643070215 + 0.5036911856953308im -0.06362834848157103 + 0.5306269463581591im -0.8517147600162237 + 0.13100167328225432im [:, :, 4] = -1.197314378377217 + 0.1967202983718848im … 0.1667793881953473 - 0.9615735981005861im 0.02950424159772501 + 0.5238170539935845im 0.016811350432769465 - 0.4396982469106374im -0.44999810735830115 + 0.2594554564037546im 0.2898396256791988 - 0.4979630390851748im
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.40200884959551936 - 0.22575744954337093im … 0.6996508331451174 + 0.41763247826392386im 0.5372702943003134 + 0.7492538204515348im 0.41673219252651916 - 0.36558946712675616im 0.5963174582142805 - 0.7337217535946893im 0.5456175163285188 - 0.5870522682895156im [:, :, 2] = -1.482678987012794 + 0.6690973068850411im … 0.6354086361951526 + 0.09166246243957646im -0.9225288679384335 + 0.4269694183961948im 0.07628543575601777 - 0.45559056185678504im 0.08571931160053996 + 0.10726049829320221im 0.5672337292680047 + 0.4715858466473389im [:, :, 3] = -0.45330219971430064 + 0.7978946634323528im … 0.08206789336001577 + 0.07067375291113462im -0.4236683801832738 - 0.531609045192882im 0.0577045912026585 - 0.8260350878089695im -0.2303723686885574 - 0.2277963064499552im 0.9233250271739551 - 0.9803046928992359im [:, :, 4] = -0.6523650158271675 - 0.12344350818526068im … -0.8047911036520734 + 0.030122786386775034im -0.1303620871361549 + 0.36733161585605295im -0.1732838689618165 - 1.3757491314371753im 1.27337815279425 - 0.3321444388340326im -0.7987393908221618 + 0.22137431422818618im
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] = 1.0849392087961933 + 0.12707068663461618im … 0.07206930308979437 + 0.5429462631119276im -3.4759265285538063 + 1.4098055608930404im 0.9491817395489313 + 0.22998266535142312im 0.6332863084478437 + 0.6284568006612711im 2.7239547340912846 - 0.1381912727280472im [:, :, 2] = -0.29013732073965287 - 1.6039461825793184im … -2.0032072770241447 + 1.2471029768622146im -4.460665019300365 + 0.3682537243509013im -0.3920906635478558 + 0.34754342788550285im 0.09711807957050654 + 0.02031816668415315im -3.3799386978288988 + 1.497906641646104im [:, :, 3] = -2.4656248452171603 + 0.08037145845683769im … -2.960890467495107 + 1.006937242026887im 5.39963732436908 - 1.9814374295196573im 4.248874469254357 - 1.0376040108598654im -0.24012611287207725 - 0.08063719450550702im 1.2670284060629835 + 0.8315734389615559im [:, :, 4] = -1.9271313881222383 + 0.003818950991232195im … 0.2608166524283062 - 0.8978917240728994im -1.9044055053387048 + 0.3615015574982937im -0.320817860889534 + 0.36961756858273054im 1.6307916986526676 + 0.8578110296522868im -1.717087594115248 - 0.32011114125830203im
julia> scalarBA = dot(B,A)
1.7171430576736968 - 4.755886379040659im
julia> scalarAA = dot(A,A)
17.941019460339444 + 0.0im
julia> normA² = norm(A)^2
17.94101946033944
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]
17.94101946033944 + 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.7991089662832322 + 0.5046836102384422im … -1.158884557136529 - 0.7018847356474055im 1.03763813528155 + 1.0884755086760183im 0.8076859291073651 - 0.6584018366255214im -0.7109213157474735 - 0.3777600456953145im -0.6891637456464186 - 0.7326346368722416im
julia> m2 = permute(m, (1,2), ())
TensorMap((ℂ^3 ⊗ (ℂ^4)') ← ProductSpace{ComplexSpace, 0}()): 0.7991089662832322 + 0.5046836102384422im … -1.158884557136529 - 0.7018847356474055im 1.03763813528155 + 1.0884755086760183im 0.8076859291073651 - 0.6584018366255214im -0.7109213157474735 - 0.3777600456953145im -0.6891637456464186 - 0.7326346368722416im
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.22228828491535974 -0.9346434424361905 -0.040951792918492526 0.39561273037174294 -0.39112986555407103 1.119806048681606 0.058832379042997145 0.3741716371473299 1.2609365746541132 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (): [:, :, 1] = 1.0394215992060882 0.5684493596977398 1.9539594774357616 1.6473792854695466 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (): [:, :, 1] = 0.9888689679933619 0.04283360258641262 0.16927804707344427 0.4045459528622351 1.1591851200731809 -0.8389588555601444 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (): [:, :, 1] = 2.5363614817747573 -0.951246539902551 -0.7982465693739317 -0.07953290389571407 -0.7273278721944437 -1.5112482166828338
julia> convert(Array, A)
5×5×2 Array{Float64, 3}: [:, :, 1] = -0.222288 -0.934643 -0.0409518 0.0 0.0 0.395613 -0.39113 1.11981 0.0 0.0 0.0588324 0.374172 1.26094 0.0 0.0 0.0 0.0 0.0 1.03942 0.568449 0.0 0.0 0.0 1.95396 1.64738 [:, :, 2] = 0.0 0.0 0.0 2.53636 -0.951247 0.0 0.0 0.0 -0.798247 -0.0795329 0.0 0.0 0.0 -0.727328 -1.51125 0.988869 0.0428336 0.169278 0.0 0.0 0.404546 1.15919 -0.838959 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)) ← (): -1.6396797730315136 -1.8097709288929584 -2.398375115173981 0.09280623816308962 1.8514858249772468 0.22994270136546516 0.8836536200975117 1.2952200371285645 0.01210914211564531 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (): -0.9557125692158273 -0.07910217696321331 -3.458672373600604 -2.5902551964706437
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),): 1.0000000000000004 2.567457967849588e-16 -1.389776358868301e-16 2.567457967849588e-16 1.0000000000000004 -6.570612512024117e-17 -1.389776358868301e-16 -6.570612512024117e-17 1.0000000000000002 * Data for sector (Irrep[ℤ₂](1),) ← (Irrep[ℤ₂](1),): 1.0 8.809752125903182e-17 8.809752125903182e-17 1.0000000000000002
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.39372598471883496 0.05039447010700454 -0.3133178484331348 [:, :, 2, 1] = 0.05039447010700454 0.4462246337401306 0.28450815097528315 [:, :, 3, 1] = -0.3133178484331348 0.28450815097528315 0.7165265170524151 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](0)): [:, :, 1, 1] = 0.014058906168699216 -0.3712149028113285 [:, :, 2, 1] = 0.3181465144072252 -0.2498129595625697 [:, :, 3, 1] = -0.14290495531747632 -0.0598454596499779 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.014058906168699216 0.3181465144072252 -0.14290495531747632 [:, :, 2, 1] = -0.3712149028113285 -0.2498129595625697 -0.0598454596499779 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.8141487934273961 0.17167950332434692 [:, :, 2, 1] = 0.17167950332434692 0.6293740710612244 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](0)): [:, :, 1, 1] = 0.1085968765973061 0.24020037385800547 [:, :, 2, 1] = 0.24020037385800547 0.5780069703240266 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](0)): [:, :, 1, 1] = 0.11932946435804817 -0.061159233505334816 -0.14535268309237093 [:, :, 2, 1] = 0.07518718812848714 -0.1064566058164976 -0.41137886527956596 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.11932946435804817 0.07518718812848714 [:, :, 2, 1] = -0.061159233505334816 -0.1064566058164976 [:, :, 3, 1] = -0.14535268309237093 -0.41137886527956596 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.8937116815638562 -0.18363559216696476 0.20341201234686665 [:, :, 2, 1] = -0.18363559216696476 0.0522202873581011 0.026416613539540224 [:, :, 3, 1] = 0.20341201234686665 0.026416613539540224 0.3674641841567104
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.1513755277171083 0.06921029956215004 -0.3485389434466378 -0.7232937048599649 [:, :, 2] = -0.6914332607985602 -2.307162626387257 0.37169856979950183 -1.7089711749255998 * Data for sector (Irrep[U₁](-1), Irrep[U₁](1)) ← (Irrep[U₁](0),): [:, :, 1] = 2.557489141743063 [:, :, 2] = 1.077329899446417 * Data for sector (Irrep[U₁](1), Irrep[U₁](-1)) ← (Irrep[U₁](0),): [:, :, 1] = -0.76635579072471 [:, :, 2] = -0.00013078557830302048 * Data for sector (Irrep[U₁](1), Irrep[U₁](0)) ← (Irrep[U₁](1),): [:, :, 1] = 0.1493998474480217 0.3965133824959567 * Data for sector (Irrep[U₁](0), Irrep[U₁](1)) ← (Irrep[U₁](1),): [:, :, 1] = 0.7301862841513677 -0.7396574539970889 * Data for sector (Irrep[U₁](-1), Irrep[U₁](0)) ← (Irrep[U₁](-1),): [:, :, 1] = 1.5829814776018607 2.1830465403392036 * Data for sector (Irrep[U₁](0), Irrep[U₁](-1)) ← (Irrep[U₁](-1),): [:, :, 1] = 0.38858496374114937 -0.7412848478393272
julia> dim(A)
20
julia> convert(Array, A)
4×4×4 Array{Float64, 3}: [:, :, 1] = 0.151376 0.0692103 0.0 0.0 -0.348539 -0.723294 0.0 0.0 0.0 0.0 0.0 -0.766356 0.0 0.0 2.55749 0.0 [:, :, 2] = -0.691433 -2.30716 0.0 0.0 0.371699 -1.70897 0.0 0.0 0.0 0.0 0.0 -0.000130786 0.0 0.0 1.07733 0.0 [:, :, 3] = 0.0 0.0 0.730186 0.0 0.0 0.0 -0.739657 0.0 0.1494 0.396513 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 4] = 0.0 0.0 0.0 0.388585 0.0 0.0 0.0 -0.741285 0.0 0.0 0.0 0.0 1.58298 2.18305 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.166284796829247 0.5456617183379359 1.340679035242332 0.7744368458543008 [:, :, 2] = -0.850359737694992 1.3559115401655446 -1.100511714126212 0.17723221260339211 * Data for sector (Irrep[U₁ × ℤ₂](1, 1), Irrep[U₁ × ℤ₂](0, 0)) ← (Irrep[U₁ × ℤ₂](1, 1),): [:, :, 1] = -0.6712887999364963 0.7612164695522561 * Data for sector (Irrep[U₁ × ℤ₂](0, 0), Irrep[U₁ × ℤ₂](1, 1)) ← (Irrep[U₁ × ℤ₂](1, 1),): [:, :, 1] = -0.61149302289211 -0.05460342232115294 * Data for sector (Irrep[U₁ × ℤ₂](-1, 0), Irrep[U₁ × ℤ₂](0, 0)) ← (Irrep[U₁ × ℤ₂](-1, 0),): [:, :, 1] = 0.5159734405410056 -0.17297704152134244 * Data for sector (Irrep[U₁ × ℤ₂](0, 0), Irrep[U₁ × ℤ₂](-1, 0)) ← (Irrep[U₁ × ℤ₂](-1, 0),): [:, :, 1] = 1.5373365669361416 -0.21471336073448258
julia> dim(A)
16
julia> convert(Array, A)
4×4×4 Array{Float64, 3}: [:, :, 1] = 0.166285 0.545662 0.0 0.0 1.34068 0.774437 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 2] = -0.85036 1.35591 0.0 0.0 -1.10051 0.177232 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 -0.611493 0.0 0.0 0.0 -0.0546034 0.0 -0.671289 0.761216 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 4] = 0.0 0.0 0.0 1.53734 0.0 0.0 0.0 -0.214713 0.0 0.0 0.0 0.0 0.515973 -0.172977 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.8065558926540803 2.118085585325207 -0.15614924852963533 0.6389550013258082 [:, :, 2] = 0.6929543395449571 0.09744426742880365 -0.21433652546342272 -1.4805759390607702 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1/2), 0, (false, false), ()) ← FusionTree{Irrep[SU₂]}((0,), 0, (false,), ()): [:, :, 1] = -1.7321030069670236 [:, :, 2] = 1.1812684960309143 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1), 0, (false, false), ()) ← FusionTree{Irrep[SU₂]}((0,), 0, (false,), ()): [:, :, 1] = -0.4260082607154751 [:, :, 2] = -1.2876283472811318 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 0), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -1.427203265312266 -1.7883302124045075 * Data for fusiontree FusionTree{Irrep[SU₂]}((0, 1/2), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -0.6539184190439842 1.0422955002134122 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1/2), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -1.22603242421359 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = 0.38457601510503053 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 0), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = -0.19112054530242237 0.40373808918704635 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1/2), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = -0.49034035861470116 * Data for fusiontree FusionTree{Irrep[SU₂]}((0, 1), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = 0.26014609813727 -0.10487802697456498 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = 0.9813533638115978
julia> dim(A)
24
julia> convert(Array, A)
7×7×7 Array{Float64, 3}: [:, :, 1] = 0.806556 2.11809 0.0 0.0 0.0 0.0 0.0 -0.156149 0.638955 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1.22478 0.0 0.0 0.0 0.0 0.0 1.22478 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.245956 0.0 0.0 0.0 0.0 0.0 0.245956 0.0 0.0 0.0 0.0 0.0 -0.245956 0.0 0.0 [:, :, 2] = 0.692954 0.0974443 0.0 0.0 0.0 0.0 0.0 -0.214337 -1.48058 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.835283 0.0 0.0 0.0 0.0 0.0 -0.835283 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.743413 0.0 0.0 0.0 0.0 0.0 0.743413 0.0 0.0 0.0 0.0 0.0 -0.743413 0.0 0.0 [:, :, 3] = 0.0 0.0 -0.653918 0.0 0.0 0.0 0.0 0.0 0.0 1.0423 0.0 0.0 0.0 0.0 -1.4272 -1.78833 0.0 0.0 0.0 0.222035 0.0 0.0 0.0 0.0 0.0 -0.314005 0.0 0.0 0.0 0.0 0.0 -1.00105 0.0 0.0 0.0 0.0 0.0 0.70785 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.653918 0.0 0.0 0.0 0.0 0.0 0.0 1.0423 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.314005 -1.4272 -1.78833 0.0 0.0 0.0 -0.222035 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.70785 0.0 0.0 0.0 0.0 0.0 1.00105 0.0 0.0 0.0 0.0 [:, :, 5] = 0.0 0.0 0.0 0.0 0.260146 0.0 0.0 0.0 0.0 0.0 0.0 -0.104878 0.0 0.0 0.0 0.0 -0.49034 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.191121 0.403738 0.0 0.0 0.0 0.693922 0.0 0.0 0.0 0.0 0.0 -0.693922 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.260146 0.0 0.0 0.0 0.0 0.0 0.0 -0.104878 0.0 0.0 0.0 0.0 -0.346723 0.0 0.0 0.0 0.0 0.0 -0.346723 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.693922 -0.191121 0.403738 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.693922 0.0 0.0 [:, :, 7] = 0.0 0.0 0.0 0.0 0.0 0.0 0.260146 0.0 0.0 0.0 0.0 0.0 0.0 -0.104878 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.49034 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.693922 -0.191121 0.403738 0.0 0.0 0.0 -0.693922 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.