Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

TensorNetworks

Guides

  • TensorNetworks

Tech Notes

  • Building Tensor Networks
  • Contraction Paths and Execution
  • Matrix Product States
  • Tensor Networks Overview
  • Young Tableaux and Tensor Symmetries

Symbols

  • ActivateTensors
  • BinaryTensorNetwork
  • BinaryTensorNetworkQ
  • CanonicalPath
  • CanonicalPathQ
  • ContractIndices
  • ContractionTree
  • EinsteinSummation
  • GreedyContractionPath
  • HookFactor
  • HookLength
  • HookLengths
  • IndexedMultiply
  • InitializeTensorNetwork
  • MetricTensor
  • MetricTensorQ
  • MPSCanonicalForm
  • MPSCanonicalQ
  • MPSEntanglementEntropy
  • MPSNormalize
  • MPSNorm
  • MPSOverlap
  • MPSSchmidtValues
  • MPSTruncate
  • OptimalContractionPath
  • PartitionQ
  • PathIndexContractions
  • PathQ
  • PathToTreePath
  • RandomTensorNetwork
  • SparseTensorNetwork
  • TableauColumns
  • TableauDimension
  • TableauRows
  • TableauShape
  • TableauSize
  • TensorNetworkAdd
  • TensorNetworkContraction
  • TensorNetworkContractions
  • TensorNetworkContract
  • TensorNetworkData
  • TensorNetworkDelete
  • TensorNetworkFreeIndices
  • TensorNetworkGraphData
  • TensorNetworkGraphQ
  • TensorNetworkIndexDimensions
  • TensorNetworkIndexGraph
  • TensorNetworkIndices
  • TensorNetwork
  • TensorNetworkQ
  • TensorNetworkRemoveCycles
  • TensorNetworkReplaceIndices
  • TensorNetworkSize
  • TensorNetworkTensors
  • TensorNetworkToNetGraph
  • ToTensorNetworkGraph
  • TransposePartition
  • TreePathQ
  • TreePathToPath
  • YoungProject
  • YoungSymmetrize
  • YoungTableau
  • YoungTableauQ
Wolfram`TensorNetworks`
EinsteinSummation
​
EinsteinSummation
[{
i
1
,
i
2
,…},{
A
1
,
A
2
,…}]
returns an inactive expression contracting the tensors
A
1
,
A
2
,…
over indices that appear more than once, with the output indices automatically taken to be those appearing exactly once.
​
​
EinsteinSummation
[{
i
1
,
i
2
,…}out,{
A
1
,
A
2
,…}]
uses
out
as the explicit list of output indices.
​
​
EinsteinSummation
["spec",{
A
1
,
A
2
,…}]
parses
"spec"
as an einsum-style string such as
"ij,jk->ik"
in which commas separate the per-tensor index lists and
"->"
separates input indices from output.
​
Details and Options
​
Examples  
(47)
Basic Examples  
(9)
Multiply two matrices via the einsum-string form, then activate to a numerical result:
In[1]:=
{Amat,Bmat}={RandomReal[{-1,1},{2,3}],RandomReal[{-1,1},{3,4}]};​​EinsteinSummation["ij,jk->ik",{Amat,Bmat}]
Out[1]=
TensorContract[{{0.14461,0.733859,0.557848},{0.806258,-0.231906,-0.102523}}{{-0.16682,-0.187316,0.252484,-0.720577},{0.986553,-0.370761,-0.760649,-0.58844},{0.595025,-0.968575,-0.494359,0.0681437}},{{2,3}}]
In[2]:=
ActivateTensors@EinsteinSummation["ij,jk->ik",{Amat,Bmat}]
Out[2]=
{{1.0318,-0.839492,-0.797474,-0.498021},{-0.424292,0.0342575,0.430649,-0.451495}}
​
Take the trace of a square matrix using a repeated index:
In[1]:=
Msq=RandomReal[{-1,1},{4,4}];
In[2]:=
ActivateTensors@EinsteinSummation["ii",{Msq}]
Out[2]=
1.05388
​
Form the outer product of two vectors:
In[1]:=
ActivateTensors@EinsteinSummation["i,j->ij",{{1,2,3},{4,5}}]
Out[1]=
{{4,5},{8,10},{12,15}}
​
Define two random complex-valued tensors:
In[1]:=
A=SparseArray@RandomComplex[{-1-I,1+I},{2,3,2}];​​B=SparseArray@RandomComplex[{-1-I,1+I},{3,2}];
Execute a summation as
∑
j
A
ijk
B
jl
In[2]:=
EinsteinSummation[{{i,j,k},{j,l}},{A,B}]
Out[2]=
TensorContractSparseArray
Specified elements: 12
Dimensions: {2,3,2}
SparseArray
Specified elements: 6
Dimensions: {3,2}
,{{2,4}}
Activate the outcome and get the final tensor:
In[3]:=
einsum=Activate@EinsteinSummation[{{1,2,3},{2,4}},{A,B}]
Out[3]=
SparseArray
Specified elements: 8
Dimensions: {2,2,2}

Check the result is the same as running summation manually:
In[4]:=
Table[Sum[A〚i,j,k〛B〚j,l〛,{j,3}],{i,2},{k,2},{l,2}]einsum
Out[4]=
True
Use string notation for compact expressions:
In[5]:=
Activate@EinsteinSummation["ijk,jl",{A,B}]einsum
Out[5]=
True
​
Use string notation for compact expressions:
In[1]:=
A=SparseArray@RandomComplex[{-1-I,1+I},{2,3,2}];​​B=SparseArray@RandomComplex[{-1-I,1+I},{3,2}];​​Activate@EinsteinSummation["ijk,jl->lk",{A,B}]Activate@EinsteinSummation[{{i,j,k},{j,l}}{l,k},{A,B}]
Out[1]=
True
​
Define two symbolic arrays of 3-rank and 2-rank with dimension
{
n
1
,
n
2
,
n
3
}
and
{
n
2
,
n
4
}
:
In[1]:=
A=ArraySymbol["A",{n1,n2,n3}];​​B=ArraySymbol["B",{n2,n4}];
Execute a summation as
∑
j
A
ijk
B
jl
In[2]:=
EinsteinSummation[{{1,2,3},{2,4}},{A,B}]
Out[2]=
TensorContract
3
A

2
B
,{{2,4}}
​
Define two random complex-valued tensors:
In[1]:=
A=SparseArray@RandomComplex[{-1-I,1+I},{2,3}];​​B=SparseArray@RandomComplex[{-1-I,1+I},{2,3}];
Calculate the inner product of two tensors as
〈A,B〉=Tr[SuperDagger[A]B]=
∑
ij
*
A
ij
B
ij
In[2]:=
einsum=ActivateTensors@EinsteinSummation[{{1,2},{1,2}},{Conjugate@A,B}]
Out[2]=
-0.474878-0.0256801
Compare the result with the trace:
In[3]:=
einsumTr[ConjugateTranspose[A].B]
Out[3]=
True
​
Calculate the cross product via Levi-Civita
(a×b)
i
=
∑
jk
ϵ
ijk
a
j
b
k
In[1]:=
{a,b}=RandomReal[{-1,1},{2,3}]
Out[1]=
{{-0.395861,0.032476,0.326959},{-0.36132,-0.175434,-0.964443}}
Excuse the cross product using EinsteinSummation:
In[2]:=
einsum=ActivateTensors@EinsteinSummation[{{i,j,k},{j},{k}},{LeviCivitaTensor[3],a,b}]
Out[2]=
{0.0260384,-0.499922,0.0811818}
Compare the result with manually summing over all indices:
In[3]:=
Table[Sum[LeviCivitaTensor[3]〚i,j,k〛a〚j〛b〚k〛,{j,3},{k,3}],{i,3}]einsum
Out[3]=
True
​
Double trace
∑
ij
T
ij,ij
In[1]:=
EinsteinSummation[{{i,j,i,j}},{ArraySymbol["T",{n1,n2,n3,n4}]}]
Out[1]=
TensorContract
4
T
,{{1,3},{2,4}}
Scope  
(16)

Applications  
(18)

Properties & Relations  
(4)

SeeAlso
IndexedMultiply
 
▪
ActivateTensors
 
▪
TensorNetwork
 
▪
TensorNetworkContract
 
▪
TensorNetworkContraction
 
▪
TensorContract
 
▪
TensorProduct
 
▪
Inactive
 
▪
Activate
TechNotes
▪
Building Tensor Networks
​​
▪
​​
Contraction Paths and Execution
RelatedGuides
▪
TensorNetworks

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com