# Vector calculus with index notation

How would you calculate this in Mathematica?

$$\sum_i\partial_i\partial_i G_{jk}$$ $$G_{jk}=\bigg(\frac{\delta_{jk}}{r}+\frac{(x_j-y_j)(x_k-y_k)}{r^3}\bigg)$$

where $$r=|\boldsymbol{x}- \boldsymbol{y}|^2=\sum_m(x_m-y_m)(x_m-y_m)$$ and $$\partial_i = \partial/\partial x_i=\nabla_{x_i}.$$

So far I haven't been able to find a good way to perform the type of calculation exemplified above in Mathematica. I wondered what do people do when faced with the simplification of this type of expressions. There are clearly plenty of pretty obvious algebraic manipulations that are a waste of time to do by hand, and yet the index notation used by Mma does not seem to make this type of calculation straightforward.

Solution (as requested by comment)

I define $$X_i = x_i-y_i$$.

$$\partial_{i}G_{jk}=\delta_{jk}\partial_{i}r^{-1}+r^{-3}\partial_{i}\left(X_{j}X_{k}\right)+\partial_{i}r^{-3}\\=r^{-3}\left(-\delta_{jk}X_{i}+\delta_{ij}X_{k}+\delta_{ik}X_{j}\right)-3r^{-5}X_{i}X_{j}X_{k}$$

$$\nabla^{2}G_{jk}=\sum_i\partial_{i}\partial_{i}G_{jk}=\partial_{i}\left[r^{-3}\left(-\delta_{jk}X_{i}+\delta_{ij}X_{k}+\delta_{ik}X_{j}\right)-3r^{-5}X_{i}X_{j}X_{k}\right]\\=\partial_{i}r^{-3}\left(-\delta_{jk}X_{i}+\delta_{ij}X_{k}+\delta_{ik}X_{j}\right)+r^{-3}\left(-\delta_{jk}\partial_{i}X_{i}+\delta_{ij}\partial_{i}X_{k}+\delta_{ik}\partial_{i}X_{j}\right)-3\partial_{i}r^{-5}X_{i}X_{j}X_{k}-3r^{-5}\partial_{i}\left(X_{i}X_{j}X_{k}\right)\\=-3r^{-5}\left(-\delta_{jk}r^{2}+2X_{j}X_{k}\right)+r^{-3}\left(-\delta_{jk}+\delta_{jk}+\delta_{kj}\right)+15r^{-7}X_{i}X_{i}X_{j}X_{k}-9r^{-5}X_{j}X_{k}\\=4\delta_{jk}r^{-3}$$

• What does $m$ mean there? Are you using some summation convention? – murray Feb 28 '19 at 20:54
• Yes, I will put sum symbols to avoid confusion. Thanks for pointing that out. – usumdelphini Feb 28 '19 at 20:54
• You could: 1. present your expression in a MMA compatible format, copy-pastable; 2. explicitly mention the pretty obvious manipulations you have in mind.. – MarcoB Feb 28 '19 at 21:49
• @MarcoB If I could do those things, I would have answered my own question. 1. The question in indeed about what is the best way to set the expression up in Mma. 2. I will add those to the question. – usumdelphini Feb 28 '19 at 21:58

Your expression looks very much like an elastic Green's function with a special choice of elastic factors. I recently solved such an elastic problem and glad to share the solution. Let us first define the components of the Green's function:

r[x_, y_, z_] := Sqrt[x^2 + y^2 + z^2];
Subscript[G, 1, 1] = 1/r[x, y, z] + x^2/r[x, y, z]^3
Subscript[G, 2, 2] = 1/r[x, y, z] + y^2/r[x, y, z]^3;
Subscript[G, 3, 3] = 1/r[x, y, z] + z^2/r[x, y, z]^3;
Subscript[G, 1, 2] = (x*y)/r[x, y, z]^3;
Subscript[G, 1, 3] = (x*z)/r[x, y, z]^3;
Subscript[G, 2, 3] = (y*z)/r[x, y, z]^3;


Then let us define the derivative in question:

Subscript[f, j_, k_] := (Laplacian[Subscript[G, j,
k], {x, y, z}] /. {x -> x1 - x2, y -> y1 - y2, z -> z1 - z2}) //
Simplify


Now let us evaluate a few components:

Subscript[f, 1, 1]
(*  (2 (-2 x1^2 + 4 x1 x2 - 2 x2^2 + y1^2 - 2 y1 y2 + y2^2 + z1^2 -
2 z1 z2 + z2^2))/((x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2)^(5/2)  *)


and

Subscript[f, 3, 2]

(*  0  *)


This can also be done without subscripts defining G[1,1] and so on instead. However, with the subscripts it looks more in the notebook in a more traditional way.

Have fun!

I asked a similar question here Manipulations with tensors that keep so(3,1) symmetry manifest I received the answer, which efficiently solves the problem. Essentially, you may use the package <xTensor and then teach mathematica how to differentiate every object that you have