Einsum
The basic idea for einstein notation is to drop the 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: is in einsum.
According to Wolfram MathWorld there are 3 rules:
- Repeated indices are implicitly summed over.
The index is just or or the like. Repeated indices mean they appear more than once in a single term.
Examples:
- ☑️
- 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:
- ✖️
- ☑️
- 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:
- ✖️
- ☑️
Does this imply that the index in equals the index in ? 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)
:
if i == j:
1
else:
0
It allows a neat rewriting of the dot product as , or the trace as . It also allows a nice expression for matrix multiplication .
Levi-Civita Permutation Tensor
The 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:
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 -> -> . 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 is hte th component of the cross product vary from 1 to 3):
The Levi-Civita tensor allows for a few nice things:
- It encodes that and since terms go to 0 when this is violated.
- The signs of the 2 products in each component are flipped since we have and , one of which must necessarily be odd and one even.
- It encodes the flip in sign that occurs for the term (ie when ). This is since (ie where so that the expression is ) is odd; and (ie where ) is even.