Einsum

The basic idea for einstein notation is to drop the \sum from summations in some cases (reducing notational complexity). For instance, you might want to compute the matrix multiplication between a row vector and a column vector: ixiyi\sum_i x_i * y_i is xiyix_i yi in einsum.

According to Wolfram MathWorld there are 3 rules:

  1. Repeated indices are implicitly summed over.

The index is just ii or jj or the like. Repeated indices mean they appear more than once in a single term.

Examples:

  • xiyi=ixiyix_i y_i = \sum_i x_i y_i ☑️
  1. Each index can appear at most twice in any term.

This means that even the indices you intend to sum over should be repeated at most twice (obviously indices you don't want to sum over should be repeated at most once)

Examples:

  1. xiyizix_i y_i z_i ✖️
  2. xiyjzix_i y_j z_i ☑️
  1. Each term must contain identical non-repeated indices.

This is a rule that only applies when you have more than one term. It specifies that if you use a term that only appears once in the first term (a non-repeating term), then you should make an effort to use the same index where there are non-repeating indices. To my mind, this does not always make things intuitive (see the examples below), and it is not emphasized among many Einstein notation users.

Examples:

  1. xiyizj+xicpx_i y_i z_j + x_i c_p ✖️
  2. xiyizj+xicjx_i y_i z_j + x_i c_j ☑️

Does this imply that the index jj in zjz_j equals the index jj in cjc_j? It's a little unclear to my eye.

Applications of Einstein Notation

Kronecker Delta

The Kronecker delta is a pretty simple idea that says the following (written as pseudocode)

δij\delta_{ij}:

if i == j:
    1
else: 
    0

It allows a neat rewriting of the dot product as δijxiyj\delta_{ij} x_i y_j, or the trace as δijAij\delta_{ij} A_{ij}. It also allows a nice expression for matrix multiplication δjkAijBki\delta_{jk} A_{ij} B_{ki}.

Levi-Civita Permutation Tensor

The ϵ\epsilon tensor (called so because it can be described as N-D array) helps compute cyclic things, which arise in cross-products and determinants.

in 3d we can describe the tensor as follows:

ϵijk\epsilon_{ijk}

if i == j or j == k or i == k:
    0
else if you can shift ijk s.t. they are in order decreasing order:
    1
else:
    -1

By shift we mean going from a sequence abcabc -> bcabca -> cabcab. Case 2 is called the cyclic or even case, and case 3 is the acyclic/odd case.

This allows us to rewrite the cross product where CiC_i is hte iith component of the cross product i,j,ki,j,k vary from 1 to 3): u×v=(uyvzuzvy)x^+(uyvzuzvy)y^Ci=ϵijkujvku \times v = (u_y * v_z - u_z * v_y) \hat{x} + (u_y * v_z - u_z * v_y) \hat{y} \to C_i = \epsilon_{ijk} u_j v_k

The Levi-Civita tensor allows for a few nice things:

  1. It encodes that iji \neq j and iki \neq k since terms go to 0 when this is violated.
  2. The signs of the 2 products in each component CiC_i are flipped since we have ijkijk and ikjikj, one of which must necessarily be odd and one even.
  3. It encodes the flip in sign that occurs for the y^\hat{y} term (ie when i=2i = 2). This is since 213213 (ie where i<ji < j so that the expression is u1v3u_1 * v_3) is odd; and 231231 (ie where i>ji > j) is even.