Repository navigation
Physics Examples
Three formulas of physics, each written as one einsum, with the indices of the formula: the optical conductivity of a two-band chain by the Kubo formula, a trace at every momentum, and the norm of a matrix-product state. Summa finds how to compute them. Every block on this page runs after
Needs["Summa`"]The Rice–Mele chain has two orbitals in each cell, and the Bloch Hamiltonian
with the velocity
nk = 400; ks = 2. Pi Range[0, nk - 1]/nk;
h = Table[(1 + 0.6 Cos[k]) PauliMatrix[1] + 0.6 Sin[k] PauliMatrix[2] + 0.4 PauliMatrix[3], {k, ks}];
v = Table[-0.6 Sin[k] PauliMatrix[1] + 0.6 Cos[k] PauliMatrix[2], {k, ks}];The energies e[[k, n]] and the eigenvectors u[[k, n]], the lower band first; the gap between the bands goes from
1.13 to 3.30:
bands[hk_] := Module[{vals, vecs}, {vals, vecs} = Eigensystem[hk]; {vals[[#]], vecs[[#]]} &[Ordering[vals]]];
{e, u} = Transpose[bands /@ h];
MinMax[e[[All, 2]] - e[[All, 1]]]{1.13137, 3.29848}
k:
vb = Einsum["kna,kab,kmb->knm", Conjugate[u], v, u];
Dimensions[vb]{400, 2, 2}
At zero temperature, with the lower band filled (
Everything but the two velocities makes one array, with the delta function broadened into a Lorentzian of width
f = {1., 0.}; eta = 0.05; omegas = Subdivide[0.02, 4., 299];
w = Table[(f[[n]] - f[[m]]) eta/(nk om ((om - e[[k, m]] + e[[k, n]])^2 + eta^2)), {k, nk}, {n, 2}, {m, 2}, {om, omegas}];and the formula is one einsum, with the indices of the formula: k, n and m are each in three tensors.
sigma = Re[Einsum["knm,kmn,knmw->w", vb, vb, w]];
ListLinePlot[Transpose[{omegas, sigma}], AxesLabel -> {"ω", "Re σ(ω)"}, PlotRange -> All]
The light is absorbed between the smallest and the largest gap, with a peak at each edge, where the gap
direct[j_] := Re[Sum[vb[[k, n, m]] vb[[k, m, n]] w[[k, n, m, j]], {k, nk}, {n, 2}, {m, 2}]];
Max[Abs[sigma[[{1, 150, 300}]] - direct /@ {1, 150, 300}]] < 10^-12True
Summa first multiplies the two velocities element by element (the second one transposed), then sums k, n and m
at once against w, in one product of a vector and a matrix:
EinsumPath["knm,kmn,knmw->w", vb, vb, w]["Contractions"] // Columnknm,kmn->knm
knm,knmw->w
In the network, the three indices are hyperedges:
EinsumDiagram["knm,kmn,knmw->w", "TensorNames" -> {"v", "v", "W"}]
With k, and the trace a
loop of three matrices for every k:
p = Einsum["ka,kb->kab", u[[All, 1]], Conjugate[u[[All, 1]]]];
velocity = Re[Einsum["kab,kbc,kca->k", p, v, p]];The lower band is
Max[Abs[velocity - 0.6 Sin[ks]/Sqrt[(1 + 0.6 Cos[ks])^2 + (0.6 Sin[ks])^2 + 0.16]]] < 10^-12True
EinsumDiagram["kab,kbc,kca->k", "TensorNames" -> {"P", "v", "P"}]
A state of four sites, a, b, c) and its conjugate (indices A, B, C) along the physical indices p, q,
r, s:
mps = "pa,aqb,brc,cs,pA,AqB,BrC,Cs->";
SeedRandom[4]; psi = {RandomReal[1, {2, 32}], RandomReal[1, {32, 2, 32}], RandomReal[1, {32, 2, 32}], RandomReal[1, {32, 2}]};
norm = Einsum[mps, Sequence @@ psi, Sequence @@ psi];The same against the 16 amplitudes of the state, themselves an einsum:
amplitudes = Flatten[Einsum["pa,aqb,brc,cs->pqrs", Sequence @@ psi]];
Abs[norm - amplitudes . amplitudes] < 10^-12 normTrue
Summa contracts each half of the network from its two ends, and joins the halves at the end:
EinsumPath[mps, Sequence @@ psi, Sequence @@ psi]["Contractions"] // Columnpa,aqb->pqb
brc,cs->brs
pqb,brs->pqrs
pA,AqB->pqB
BrC,Cs->Brs
pqB,Brs->pqrs
pqrs,pqrs->
The overlap
SeedRandom[5]; phi = Map[RandomComplex[{-1 - I, 1 + I}, Dimensions[#]] &, psi];
overlap = Einsum[mps, Sequence @@ Conjugate[phi], Sequence @@ psi];
Abs[overlap - Conjugate[Flatten[Einsum["pa,aqb,brc,cs->pqrs", Sequence @@ phi]]] . amplitudes] < 10^-12 Abs[overlap]True
Start
Recipes
Reference
Documents