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.48302896167214215 -0.7423477203710039 1.86584256308899 -0.4165950374445757 -0.7902228160291441 3.7194834704812414 [:, :, 2] = 0.9591611126838058 1.2942092867850157 1.3125835158977905 -1.239207421563456 2.052291756183218 -0.1057170040449484 [:, :, 3] = 0.571794415099297 0.29296586699992916 -0.4097768742837239 0.7213709426987975 0.43215060133799105 -1.251854220900602 [:, :, 4] = 1.0419026680544814 1.3318164841226912 1.8650046693412883 -1.0171585204233444 1.879740592922827 1.3265095852739834
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] = 1.0835711297624284 4.846769528310327 -1.7751721835100671 -0.6645718700503795 -2.92937052548842 1.705393833673886 [:, :, 2] = 1.8865823041417058 4.822903663304675 1.09343846933665 -5.281968302340634 0.733551609263394 5.996216043465471 [:, :, 3] = 5.578922545582016 -3.176363555044426 1.0554508850731543 -3.9809809011296746 -1.4668617766286396 -3.1025341006411775 [:, :, 4] = -2.2881977116774186 0.3597941658473127 -1.9558668196573818 -1.9303514548572331 0.3484917875544432 0.018913185439029867
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)
-1.8185435141488038
julia> scalarAA = dot(A,A)
44.49504884733735
julia> normA² = norm(A)^2
44.49504884733735
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] = 0.323659630774888 -0.5413259208066837 -1.235530813058169 1.7519973868847245 -0.46104888191819515 -2.2290276920839553 [:, :, 2, 1] = -0.2936319519378742 0.05986444667813883 6.403066916637308 -3.7736355283154768 0.9740939289611978 9.088102946936802 [:, :, 1, 2] = -0.22454513680435703 -0.36057396232733124 -4.152945740849082 1.7734257239413536 -0.7390314058808802 -6.211253275900975 [:, :, 2, 2] = -3.2861815640769696 -3.5443444106940074 -3.1374305278383527 1.7127736689027306 -5.50271626185141 0.9379700953888956 [:, :, 1, 3] = -0.25399094494207913 0.08878899689342674 -2.2103511706790027 0.3223394178216622 -0.17471195536306558 -3.229152033889632 [:, :, 2, 3] = 1.5156561173289864 2.5438568712503002 2.986033126308913 -3.4251649055641247 4.101989112327563 0.4128164357075864
julia> @tensor d = A[a,b,c]*A[a,b,c]
44.49504884733735
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.09327881414172044 0.15299861523487568 … 0.1529330298699322 -0.22804356148586175 -0.32992767425330466 -0.33556711275018763 0.7313268199899817 -0.18767883544447453 0.08309527488761244 [:, :, 2] = 0.172851256738016 -0.3259105840483288 … -0.3468949843546974 -0.35141216080581833 -0.1560938265338016 -0.293399322436442 -0.19238133658856446 -0.42047601384714905 -0.5221975073089776
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.3874616999335991 1.034914436738018 0.17325887634428053
julia> M₁ = randn(ℝ^4, ℝ^3)
TensorMap(ℝ^4 ← ℝ^3): -0.3338835609702304 -0.4114173129085875 1.216382875393862 0.31578249283814597 -0.44843510176163376 0.9066818131503915 1.2035895713428724 -0.09549606725635175 2.0231855297039236 0.22037298566114713 0.6143839033827391 0.06998571824680307
julia> M₂ = randn(ℝ^4 → ℝ^2) # alternative syntax for randn(ℝ^2, ℝ^4)
TensorMap(ℝ^2 ← ℝ^4): 0.2817632345496459 0.3496049298844833 … -0.8642403464544043 0.05435173212350903 -0.9100270798478557 -0.7953254725816146
julia> w = M₁ * v # matrix vector product
TensorMap(ℝ^4 ← ProductSpace{CartesianSpace, 0}()): -0.6782832395415337 0.13113482571751833 1.9216390255349403 0.9537194955186987
julia> M₃ = M₂ * M₁ # matrix matrix product
TensorMap(ℝ^2 ← ℝ^3): 0.7403824774924589 -0.8762328339889109 2.1364902508561237 -1.6427354943896784 -0.01071609681235783 -2.7678441193017127
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.9250499687826328 1.4359041436823539 0.24039005510122072 1.4359041436823539 1.0710478913687693 0.179308112421703 0.24039005510122072 0.179308112421703 0.03001863823208269
julia> M₁′ = M₁ ⊗ M₁
TensorMap((ℝ^4 ⊗ ℝ^4) ← (ℝ^3 ⊗ ℝ^3)): [:, :, 1, 1] = 0.11147823228616158 -0.10543458320085645 … -0.07357891719418533 -0.10543458320085645 0.0997185827830737 0.06958993076626203 -0.4018587720265914 0.3800725151926478 0.265238627347449 -0.07357891719418533 0.06958993076626203 0.04856425280920816 [:, :, 2, 1] = 0.13736547747872274 -0.1299183846670453 … -0.09066526159835184 0.14972510864022193 -0.14160795431041637 -0.09882298225047156 0.03188456699420334 -0.030155986174450002 -0.021044753460179946 -0.20513268546421892 0.19401168056983195 0.13539361513060397 [:, :, 3, 1] = -0.4061302459397107 0.3841124166375056 … 0.26805792595763644 -0.30272615244159784 0.2863142431676407 0.19980817820861413 -0.6755083891609879 0.6388865700439699 0.44585543572728314 -0.02336708082530184 0.022100264571043592 0.015422961683687815 [:, :, 1, 2] = 0.13736547747872274 0.14972510864022193 … -0.20513268546421892 -0.1299183846670453 -0.14160795431041637 0.19401168056983195 -0.49517758728668326 -0.5397318119043821 0.7394660589123916 -0.09066526159835184 -0.09882298225047156 0.13539361513060397 [:, :, 2, 2] = 0.16926420536092263 0.18449396458066036 … -0.25276817462401574 0.18449396458066036 0.20109404049196683 -0.2755113082341484 0.039288735383945984 0.04282378863793792 -0.05867124655865796 -0.25276817462401574 -0.2755113082341484 0.3774675807358109 [:, :, 3, 2] = -0.5004409740625639 -0.5454687785083552 … 0.7473260589924008 -0.3730245952294201 -0.40658795114551843 0.5570507114894768 -0.8323735541463255 -0.9072674088954439 1.2430126230069711 -0.02879333614307722 -0.03138405268386616 0.04299809875751545 [:, :, 1, 3] = -0.4061302459397107 -0.30272615244159784 … -0.02336708082530184 0.3841124166375056 0.2863142431676407 0.022100264571043592 1.4640257435841089 1.091272774834058 0.08423408062479275 0.26805792595763644 0.19980817820861413 0.015422961683687815 [:, :, 2, 3] = -0.5004409740625639 -0.3730245952294201 … -0.02879333614307722 -0.5454687785083552 -0.40658795114551843 -0.03138405268386616 -0.11615978087808676 -0.08658454740872074 -0.00668336085668079 0.7473260589924008 0.5570507114894768 0.04299809875751545 [:, :, 3, 3] = 1.4795872995514394 1.1028722309471934 … 0.08512942919755098 1.1028722309471934 0.8220719102976816 0.06345477791464385 2.460968232076512 1.8343855244115888 0.1415940924428678 0.08512942919755098 0.06345477791464385 0.004898000758520904
julia> w′ = M₁′ * v′
TensorMap((ℝ^4 ⊗ ℝ^4) ← ProductSpace{CartesianSpace, 0}()): 0.46006815304295756 -0.08894655440439281 … -0.6468919490343402 -0.08894655440439281 0.017196342515963886 0.12506583982824396 -1.3034155434692751 0.2519937987055063 1.8327046020022268 -0.6468919490343402 0.12506583982824399 0.9095808761324413
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.0000000000000004 -2.4894031070814934e-16 -2.4894031070814934e-16 1.0
julia> U'*U ≈ one(U'*U)
true
julia> P = U*U' # should be a projector
TensorMap((ℝ^3 ⊗ ℝ^4) ← (ℝ^3 ⊗ ℝ^4)): [:, :, 1, 1] = 0.038578494123597144 -0.07060558343140899 … -0.07422664567119143 -0.03947040064025177 0.003794248121470617 -0.019413139266922876 -0.10147065432097357 -0.05517334821191146 -0.09801352410611285 [:, :, 2, 1] = -0.03947040064025177 0.07963859344934342 … 0.08702772322442173 0.17549437269737034 0.13009115074016264 0.1796280093854336 -0.09916923145134628 0.1905593346433208 0.1645572119828421 [:, :, 3, 1] = -0.10147065432097357 0.17459110451016957 … 0.17858014715223625 -0.09916923145134628 -0.2112554178565636 -0.18896467565631248 0.5718494963042616 -0.05636282835768436 0.16123085755906877 [:, :, 1, 2] = -0.07060558343140899 0.1296262850585123 … 0.1364552887482488 0.07963859344934342 0.00039415288355104054 0.04428064096550065 0.17459110451016957 0.10832298131933882 0.18290315658601639 [:, :, 2, 2] = 0.003794248121470617 0.00039415288355104054 … 0.003691326651810053 0.13009115074016264 0.13321755292015927 0.15651070000709477 -0.2112554178565636 0.12755415165184542 0.05409637633716215 [:, :, 3, 2] = -0.05517334821191146 0.10832298131933882 … 0.11715872729804838 0.1905593346433208 0.12755415165184542 0.18634622249794944 -0.05636282835768436 0.21202342349458203 0.2039763018923508 [:, :, 1, 3] = -0.026127115503028094 0.04913740167128053 … 0.05224694028793243 0.050831438826965725 0.02132759862054497 0.041645472091930084 0.0325132913253787 0.0612876345920897 0.0778446557245397 [:, :, 2, 3] = -0.012342661646498712 0.01954455073552354 … 0.01918726403146013 -0.042958812284418654 -0.05633242094989562 -0.05951912525719561 0.11597548431831471 -0.037523032075673736 0.004913304990060056 [:, :, 3, 3] = 0.02939832212546896 -0.049486568909202354 … -0.050096458205862116 0.04874790930189707 0.08105314926379847 0.07841616859254753 -0.19574935976860272 0.03619763611774759 -0.03718964281029623 [:, :, 1, 4] = -0.07422664567119143 0.1364552887482488 … 0.14372464179564334 0.08702772322442173 0.003691326651810053 0.050459458088677016 0.17858014715223625 0.11715872729804838 0.19385570828444723 [:, :, 2, 4] = -0.019413139266922876 0.04428064096550065 … 0.050459458088677016 0.1796280093854336 0.15651070000709477 0.1986884495656604 -0.18896467565631248 0.18634622249794944 0.12532835334523373 [:, :, 3, 4] = -0.09801352410611285 0.18290315658601639 … 0.19385570828444723 0.1645572119828421 0.05409637633716215 0.12532835334523373 0.16123085755906877 0.2039763018923508 0.2795950613483576
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.48302896167214215 -0.7423477203710039 1.86584256308899 -0.4165950374445757 -0.7902228160291441 3.7194834704812414 [:, :, 2] = 0.9591611126838058 1.2942092867850157 1.3125835158977905 -1.239207421563456 2.052291756183218 -0.1057170040449484 [:, :, 3] = 0.571794415099297 0.29296586699992916 -0.4097768742837239 0.7213709426987975 0.43215060133799105 -1.251854220900602 [:, :, 4] = 1.0419026680544814 1.3318164841226912 1.8650046693412883 -1.0171585204233444 1.879740592922827 1.3265095852739834
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.9561546135206911 - 0.3008772489448677im … -0.7077014967867438 - 0.599669022669235im -0.548072252250287 + 0.32380341686279307im -1.2452795200936704 + 0.03320171133602372im 0.49044147625688406 - 1.292823784431604im -1.23121919954525 + 0.809916168908349im [:, :, 2] = 0.0005376470220499056 + 0.7165192896858443im … 0.2733172964839695 - 0.595773919253225im 0.05055667514833831 + 0.2903988351422158im 0.04395928058008617 + 0.20191904817110767im 0.20650998510907775 - 0.37062591757355im -0.1336285807982732 + 0.17846881972171627im [:, :, 3] = -0.09132965397773765 + 0.7099982870044419im … 0.39390748663985653 + 0.08411068932326278im 1.4137383872806617 + 0.4321727992888974im 0.1767308203077639 - 0.3063550654718755im -0.08414898609858759 - 0.9374016135214052im 0.8109338547589396 - 0.1614452975877655im [:, :, 4] = -1.0190013643566642 - 0.6376254921147149im … -0.4846777032515214 + 0.2579904102158498im -0.48897991263567103 + 0.6786055821970347im 0.8163435642687364 + 0.3115788796634152im 1.095818792390796 + 0.12201675348177643im 0.32658266610549624 + 0.04241187565120848im
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] = 2.0460070020769754 - 0.8380663472948616im … 0.06208385630326151 - 0.9297058944313425im -0.5872066799983408 - 0.42084438375862016im 0.3396017577900188 + 0.23919570006941523im -1.4934158809863924 + 0.0017470036387407122im 1.121688270438808 - 0.9198460575971601im [:, :, 2] = -0.26349682437283967 - 1.0967519659038918im … 0.5817524926997761 + 0.17007960828002844im 0.006571888187782666 - 0.1680819761629166im 1.2409854807307696 + 0.16687988756045774im 0.5881998466780042 - 0.9445849050341452im -0.9459181229832698 + 0.6457640192571987im [:, :, 3] = 0.13195527892253622 + 0.8660316191062073im … -0.27715022496171476 + 1.576662304293325im -1.051024447708593 + 0.47685561978222785im 0.27501047018687735 - 0.7736578499834587im -0.8781599474106071 - 1.0501173398347752im 0.35748645393016937 - 0.1657501990262124im [:, :, 4] = 0.417698214799012 + 0.23895707129071783im … 1.4724654976969784 + 0.9705319387650927im 0.40330490825392873 - 0.6523929215289055im 0.18074492228502553 + 0.7755086376656509im -0.15482321421701586 + 2.1444620954424902im 0.8082258502335601 + 0.7532925279565682im
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.1302618192733007 + 2.675872015378787im … 0.005336403770527243 + 0.3578820933147224im 0.5824986216159569 - 0.6389360361126885im -2.0485712304502215 + 0.9186019275118767im -3.822084000095477 - 0.2709080421202368im 0.1695342738835086 + 1.3617880412271766im [:, :, 2] = -4.827602343198105 + 1.6322965545397994im … 2.3655687012955853 - 0.2296549663644203im 1.5323000257828328 - 0.42997788769059053im 0.43267514071464636 + 1.0491278716827364im 1.4666370618400992 + 0.4211431565000989im 0.23677710788961792 - 1.2283312836702511im [:, :, 3] = -0.5209518186294233 + 0.021529742769965332im … -2.224784731038981 - 0.06975104840310492im -1.2905364390799052 - 0.7906465855333362im 2.218079326324192 - 0.18720440224215734im 0.35431202184755584 - 0.6555022456546968im -5.15135988783645 + 2.0589616817262213im [:, :, 4] = -5.800369921562538 + 2.197350326885995im … -2.9596952882033243 + 2.1089977695172126im 1.595490194306759 + 0.10151378096501557im -1.3667654535034703 + 0.36994710335312775im -0.7393769253077214 - 0.604450468660142im 3.4218177812595725 - 0.527809448715605im
julia> scalarBA = dot(B,A)
0.6789660556979115 + 4.310571811738245im
julia> scalarAA = dot(A,A)
34.344487994055356 + 0.0im
julia> normA² = norm(A)^2
34.344487994055356
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]
34.34448799405536 + 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): -1.0477723704965587 - 0.19371842193586594im … 0.07459352148648389 + 0.033503837784549066im 0.06616729735204345 - 0.013174219878789889im 0.27783393146521407 - 0.21568140810458147im -1.2112237682144504 - 0.4795762758542271im 0.6329394665498579 - 0.03308260338144447im
julia> m2 = permute(m, (1,2), ())
TensorMap((ℂ^3 ⊗ (ℂ^4)') ← ProductSpace{ComplexSpace, 0}()): -1.0477723704965587 - 0.19371842193586594im … 0.07459352148648389 + 0.033503837784549066im 0.06616729735204345 - 0.013174219878789889im 0.27783393146521407 - 0.21568140810458147im -1.2112237682144504 - 0.4795762758542271im 0.6329394665498579 - 0.03308260338144447im
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.6291160815935487 -0.00036280466120081344 0.2347506860776858 -0.9516821098013591 -0.0015904662995215664 -1.425338438548593 -0.9507442714586808 0.39862950051597135 0.4775330533320411 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (): [:, :, 1] = 1.008538911576305 0.054672486109237736 -0.46229143890020585 1.4051143108351498 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (): [:, :, 1] = -0.473326606482998 0.1281409788173561 -0.004605256644978009 0.5531006494723133 1.4628445439112694 -0.4679137981496421 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (): [:, :, 1] = 0.47353856747550915 -0.881047023430013 0.0048603124304110535 1.3451611414995086 0.736601914459784 1.3055268987168507
julia> convert(Array, A)
5×5×2 Array{Float64, 3}: [:, :, 1] = 0.629116 -0.000362805 0.234751 0.0 0.0 -0.951682 -0.00159047 -1.42534 0.0 0.0 -0.950744 0.39863 0.477533 0.0 0.0 0.0 0.0 0.0 1.00854 0.0546725 0.0 0.0 0.0 -0.462291 1.40511 [:, :, 2] = 0.0 0.0 0.0 0.473539 -0.881047 0.0 0.0 0.0 0.00486031 1.34516 0.0 0.0 0.0 0.736602 1.30553 -0.473327 0.128141 -0.00460526 0.0 0.0 0.553101 1.46284 -0.467914 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.3927940542400081 -1.7736601668573888 0.8859235331101452 -0.15764937018342862 3.322235532481978 -2.5452498344515124 -0.28510467994047767 1.0096526685312752 0.05032850139572537 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (): -2.1259048373299456 -1.3061710832978584 0.8251733763952507 0.5048652725413002
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.9999999999999997 -2.203083530870933e-16 -1.5179615089580505e-16 -2.203083530870933e-16 0.9999999999999998 -2.789506090960437e-17 -1.5179615089580505e-16 -2.789506090960437e-17 0.9999999999999998 * Data for sector (Irrep[ℤ₂](1),) ← (Irrep[ℤ₂](1),): 1.0000000000000002 1.1106226733404162e-16 1.1106226733404162e-16 0.9999999999999999
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.14833768749193402 -0.2390732442622481 -0.2262976323302008 [:, :, 2, 1] = -0.2390732442622481 0.9185225463256105 -0.10410681884739231 [:, :, 3, 1] = -0.2262976323302008 -0.10410681884739231 0.8252338867667244 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](0)): [:, :, 1, 1] = -0.1136007356708028 0.07114672372077611 [:, :, 2, 1] = 0.07996549316058003 0.021216792125854922 [:, :, 3, 1] = 0.28578200874194576 0.022421290088873117 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](1)): [:, :, 1, 1] = -0.1136007356708028 0.07996549316058003 0.28578200874194576 [:, :, 2, 1] = 0.07114672372077611 0.021216792125854922 0.022421290088873117 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.11395726263014573 -0.0002028843162632124 [:, :, 2, 1] = -0.0002028843162632124 0.9939486167855847 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](0)): [:, :, 1, 1] = 0.5100951899718877 -0.21633201966440696 [:, :, 2, 1] = -0.21633201966440696 0.41755011642487727 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](1), Irrep[ℤ₂](0)): [:, :, 1, 1] = 0.22841989268249607 0.018899789623828954 0.3880279564495864 [:, :, 2, 1] = -0.30342945469931953 0.2983612717228904 0.1237480970485629 * Data for sector (Irrep[ℤ₂](1), Irrep[ℤ₂](0)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.22841989268249607 -0.30342945469931953 [:, :, 2, 1] = 0.018899789623828954 0.2983612717228904 [:, :, 3, 1] = 0.3880279564495864 0.1237480970485629 * Data for sector (Irrep[ℤ₂](0), Irrep[ℤ₂](1)) ← (Irrep[ℤ₂](0), Irrep[ℤ₂](1)): [:, :, 1, 1] = 0.23324082782176328 -0.18577662296732064 -0.009028237116426743 [:, :, 2, 1] = -0.18577662296732064 0.2888085883354453 0.2854970813967547 [:, :, 3, 1] = -0.009028237116426743 0.2854970813967547 0.5503052774460265
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.2867986570454213 1.4686325343632656 -1.0607997534616265 -0.425823847644031 [:, :, 2] = 0.37834586847495094 -1.692986898045361 -0.29660587893911167 -1.10697538351964 * Data for sector (Irrep[U₁](-1), Irrep[U₁](1)) ← (Irrep[U₁](0),): [:, :, 1] = 1.719708574836088 [:, :, 2] = -1.7920170265880668 * Data for sector (Irrep[U₁](1), Irrep[U₁](-1)) ← (Irrep[U₁](0),): [:, :, 1] = -1.1437421478435639 [:, :, 2] = -1.1246868201576592 * Data for sector (Irrep[U₁](1), Irrep[U₁](0)) ← (Irrep[U₁](1),): [:, :, 1] = 0.9726833746793604 0.8584699283102072 * Data for sector (Irrep[U₁](0), Irrep[U₁](1)) ← (Irrep[U₁](1),): [:, :, 1] = -0.8371586974862553 -1.1290622061836593 * Data for sector (Irrep[U₁](-1), Irrep[U₁](0)) ← (Irrep[U₁](-1),): [:, :, 1] = -1.7975975179214951 0.8313649493839075 * Data for sector (Irrep[U₁](0), Irrep[U₁](-1)) ← (Irrep[U₁](-1),): [:, :, 1] = -0.6096158646046775 0.38464799274203854
julia> dim(A)
20
julia> convert(Array, A)
4×4×4 Array{Float64, 3}: [:, :, 1] = 0.286799 1.46863 0.0 0.0 -1.0608 -0.425824 0.0 0.0 0.0 0.0 0.0 -1.14374 0.0 0.0 1.71971 0.0 [:, :, 2] = 0.378346 -1.69299 0.0 0.0 -0.296606 -1.10698 0.0 0.0 0.0 0.0 0.0 -1.12469 0.0 0.0 -1.79202 0.0 [:, :, 3] = 0.0 0.0 -0.837159 0.0 0.0 0.0 -1.12906 0.0 0.972683 0.85847 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 4] = 0.0 0.0 0.0 -0.609616 0.0 0.0 0.0 0.384648 0.0 0.0 0.0 0.0 -1.7976 0.831365 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] = 2.3486216608873787 0.561710883045885 -0.47157908512525215 0.34571472192855707 [:, :, 2] = -1.5225613664667734 -0.16640589709081985 -1.6261946094602033 -1.0635051120866392 * Data for sector (Irrep[U₁ × ℤ₂](1, 1), Irrep[U₁ × ℤ₂](0, 0)) ← (Irrep[U₁ × ℤ₂](1, 1),): [:, :, 1] = -0.5231789187051377 -0.08419034824138397 * Data for sector (Irrep[U₁ × ℤ₂](0, 0), Irrep[U₁ × ℤ₂](1, 1)) ← (Irrep[U₁ × ℤ₂](1, 1),): [:, :, 1] = -0.3442055445471175 2.101775015850242 * Data for sector (Irrep[U₁ × ℤ₂](-1, 0), Irrep[U₁ × ℤ₂](0, 0)) ← (Irrep[U₁ × ℤ₂](-1, 0),): [:, :, 1] = -0.9761496591252604 0.62243813327491 * Data for sector (Irrep[U₁ × ℤ₂](0, 0), Irrep[U₁ × ℤ₂](-1, 0)) ← (Irrep[U₁ × ℤ₂](-1, 0),): [:, :, 1] = -0.6634749097375561 -1.6083182893358305
julia> dim(A)
16
julia> convert(Array, A)
4×4×4 Array{Float64, 3}: [:, :, 1] = 2.34862 0.561711 0.0 0.0 -0.471579 0.345715 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 2] = -1.52256 -0.166406 0.0 0.0 -1.62619 -1.06351 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.344206 0.0 0.0 0.0 2.10178 0.0 -0.523179 -0.0841903 0.0 0.0 0.0 0.0 0.0 0.0 [:, :, 4] = 0.0 0.0 0.0 -0.663475 0.0 0.0 0.0 -1.60832 0.0 0.0 0.0 0.0 -0.97615 0.622438 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] = -1.493251216219093 0.04888400736909962 -0.499554585711745 0.17084619623646155 [:, :, 2] = 0.12469874199728036 0.5835076444484565 0.24496686069968465 -0.7348457148889461 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1/2), 0, (false, false), ()) ← FusionTree{Irrep[SU₂]}((0,), 0, (false,), ()): [:, :, 1] = -0.5451256465287226 [:, :, 2] = 1.3961970270446962 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1), 0, (false, false), ()) ← FusionTree{Irrep[SU₂]}((0,), 0, (false,), ()): [:, :, 1] = 1.3520051887720943 [:, :, 2] = -0.06838515486218959 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 0), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -0.8857773296386046 -0.09186210997507445 * Data for fusiontree FusionTree{Irrep[SU₂]}((0, 1/2), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -0.6239314521988636 -0.6249504509888005 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1/2), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = -0.5482226325356204 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1), 1/2, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1/2,), 1/2, (false,), ()): [:, :, 1] = 1.9381892500563316 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 0), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = 0.2903564076283035 -0.1328801557737839 * Data for fusiontree FusionTree{Irrep[SU₂]}((1/2, 1/2), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = 0.12540325789666157 * Data for fusiontree FusionTree{Irrep[SU₂]}((0, 1), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = -1.0451090081165193 0.40931632792085826 * Data for fusiontree FusionTree{Irrep[SU₂]}((1, 1), 1, (false, false), ()) ← FusionTree{Irrep[SU₂]}((1,), 1, (false,), ()): [:, :, 1] = -0.5530021876548156
julia> dim(A)
24
julia> convert(Array, A)
7×7×7 Array{Float64, 3}: [:, :, 1] = -1.49325 0.048884 0.0 0.0 0.0 0.0 0.0 -0.499555 0.170846 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.385462 0.0 0.0 0.0 0.0 0.0 0.385462 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.780581 0.0 0.0 0.0 0.0 0.0 -0.780581 0.0 0.0 0.0 0.0 0.0 0.780581 0.0 0.0 [:, :, 2] = 0.124699 0.583508 0.0 0.0 0.0 0.0 0.0 0.244967 -0.734846 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.98726 0.0 0.0 0.0 0.0 0.0 -0.98726 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.0394822 0.0 0.0 0.0 0.0 0.0 0.0394822 0.0 0.0 0.0 0.0 0.0 -0.0394822 0.0 0.0 [:, :, 3] = 0.0 0.0 -0.623931 0.0 0.0 0.0 0.0 0.0 0.0 -0.62495 0.0 0.0 0.0 0.0 -0.885777 -0.0918621 0.0 0.0 0.0 1.11901 0.0 0.0 0.0 0.0 0.0 -1.58252 0.0 0.0 0.0 0.0 0.0 -0.447622 0.0 0.0 0.0 0.0 0.0 0.316516 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.623931 0.0 0.0 0.0 0.0 0.0 0.0 -0.62495 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.58252 -0.885777 -0.0918621 0.0 0.0 0.0 -1.11901 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.316516 0.0 0.0 0.0 0.0 0.0 0.447622 0.0 0.0 0.0 0.0 [:, :, 5] = 0.0 0.0 0.0 0.0 -1.04511 0.0 0.0 0.0 0.0 0.0 0.0 0.409316 0.0 0.0 0.0 0.0 0.125403 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.290356 -0.13288 0.0 0.0 0.0 -0.391032 0.0 0.0 0.0 0.0 0.0 0.391032 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 -1.04511 0.0 0.0 0.0 0.0 0.0 0.0 0.409316 0.0 0.0 0.0 0.0 0.0886735 0.0 0.0 0.0 0.0 0.0 0.0886735 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.391032 0.290356 -0.13288 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.391032 0.0 0.0 [:, :, 7] = 0.0 0.0 0.0 0.0 0.0 0.0 -1.04511 0.0 0.0 0.0 0.0 0.0 0.0 0.409316 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.125403 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.391032 0.290356 -0.13288 0.0 0.0 0.0 0.391032 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.