Wednesday, October 17, 2012

Chain Rule under Einstein Notation

OK, so the other day I was trying to do all this symbolic math in order to get expressions for the derivatives of certain mappings from one vector space into another. Ultimately, all this would go into a Python function. When dealing with the first derivative things are pretty easy, because all you have is matrix-vector multiplication, and you can easily do that using NumPy's dot() function. The problem was that second and higher derivatives started showing in my formulas. These are higher dimensional tensors, and all of a sudden it is not clear what row multiplies what column when (for example, there are two ways to right multiply a 3-tensor to a vector) and what dimensions get added where when derivatives are taken. In particular, I was having a lot of trouble with applying chain rule. After reading the wikipedia article on Ricci calculus I wrote down a simple little rule for chain rule in index notation. Here it is:

Suppose we have a vector valued mapping $A^i(\mathbf{x})=B^i\left(\mathbf{C}\left(\mathbf{x}\right)\right)$ and we want to find its derivative with respect to $x^i$. We do this by applying chain rule, but first a little bit about the notation. The superscript denotes that $\mathbf{A}$ is a column vector, and the little equality above simply says that the $i$th element of $\mathbf{A}$ is equal to the $i$th element of $\mathbf{B}$. Now, we want to take the derivative with respect to $x$, which is also a column vector. The standard notation for this is
\[ \partial_{x^j}A^i(\mathbf{x}) = A^i_{,\,j}. \]
Now, on to chain rule. We drop the arguments of the functions, since they are unambiguous. Then, we write:
\[ A^i_{,\,j} = B^i_{,\,k}C^k_{,\,l}x^l_{,\,j} = B^i_{,\,k}C^k_{,\,l}\delta^l_j = B^i_{,\,k}C^k_{,\,j} .\]
And that's it! Now you know how to do chain rule, so taking derivatives and calculating them in [insert favorite programming language here] should be a piece of cake!

p.s. I might have been a little bit sloppy in my terminology and notation, but I am open to suggestions.
p.p.s. I have enabled $\LaTeX$ in my posts and comments. Feel free to give it a try!

1 comment:

  1. This is a test to see if $\LaTeX$ actually works in comments or not