## Learn to Use ITensor

main / tutorials / diagrams C++v3 | C++v2 | Julia

Thomas E. Baker—August 20, 2015

In classical physics, free body diagrams represent the sum of forces in Newton's equations. In quantum field theories, Feyman diagrams represent integrals found in perturbative calculations. Both examples express a mathematical equation as a picture; tensor network diagrams do the same for summations.

For example, the expectation value of a Hamiltonian as a tensor diagram looks like:

$$=\langle\psi|\hat H|\psi\rangle$$

and the summation we are representing here is

$$=\sum_{\begin{matrix} \sigma_1\ldots\sigma_5\\\\ \sigma_1'\ldots\sigma_5'\\\\ \end{matrix}} \sum_{ \begin{matrix} b_1'\ldots b_4'\\\\ a_1\ldots a_4\\\\ b_1\ldots b_4\\\\ \end{matrix}} A_{b_1'b_2'}^{\sigma_2'\dagger}A_{b_1'}^{\sigma_1'\dagger}A_{b_2'b_3'}^{\sigma_3'\dagger}A_{b_3'b_4'}^{\sigma_4'\dagger}A_{b_4'}^{\sigma_5'\dagger}H_{a_1}^{\sigma_1'\sigma_1}H_{a_1a_2}^{\sigma_2'\sigma_2}H_{a_2a_3}^{\sigma_3'\sigma_3}H_{a_3a_4}^{\sigma_4'\sigma_4}H_{a_4}^{\sigma_5'\sigma_5}A_{b_1}^{\sigma_1}A_{b_1b_2}^{\sigma_2}A_{b_2b_3}^{\sigma_3}A_{b_3b_4}^{\sigma_4}A_{b_4}^{\sigma_5}$$

which shows why we wanted to draw these diagrams instead of writing out this summation. The diagram is clearer—once you understood how to read them.

In this discussion, we will see what the diagrams represent, how to understsand each shape and line in a diagram, and understand other things you might see in a diagram. We will also connect this with the MPS| and MPO| tensor networks used for DMRG and other tensor network methods in another discussion. Better yet, we'll make sure to connect this entire discussion with ITensor code you can use for your own projects!

## Diagrams 101

Each diagram will consist of blobs connected by lines. Each blob represents a tensor (an object with indices) and each line is the index of that tensor.

For example, one tensor with one line is a vector:

$$=A^\mu$$

To make a vector in ITensor, one may use the code

Index mu("mu",m);//Index mu ranges from 1 to m
ITensor A(mu);


Since a matrix is a rank two object (there are two indices), the diagrammatic representation looks like

$$=A^{\mu\nu}$$
Index mu("mu",m),nu("nu",n);//for an (m x n) matrix
ITensor A(mu,nu);


A trace over matrices would look like

$$=\sum_{\alpha\beta\gamma\eta} A^{\alpha\beta}B^{\beta\gamma}C^{\gamma\eta}D^{\eta\alpha}$$
Index a("a",z),b("b",y),c("c",x),d("d",w),e("e",v);
ITensor A(a,b),B(b,c),C(d,e),D(e,a);
ITensor Tr = A*B*C*D;


Note that when two ITensors are multiplied with the * operator, any matching Index is automatically summed over!

Diagrams can be simple, like those above, or they can be complicated like this one:

$$=\sum_{\gamma\delta\eta\mu} A^{\alpha\beta\gamma\delta\eta\mu}B^{\gamma\delta\eta\mu\nu\zeta}$$
Index a("a",z),b("b",y),c("c",x),d("d",w),e("e",v),
f("f",u),g("g",t),h("h",s);
ITensor A(a,b,c,d,e,f),B(c,d,e,f,g,h);
ITensor C = A*B;


Back to Tutorials
Back to Main