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$.



  • $\begingroup$ What does $m$ mean there? Are you using some summation convention? $\endgroup$
    – murray
    Feb 28 '19 at 20:54
  • $\begingroup$ Yes, I will put sum symbols to avoid confusion. Thanks for pointing that out. $\endgroup$ Feb 28 '19 at 20:54
  • 1
    $\begingroup$ You could: 1. present your expression in a MMA compatible format, copy-pastable; 2. explicitly mention the pretty obvious manipulations you have in mind.. $\endgroup$
    – MarcoB
    Feb 28 '19 at 21:49
  • $\begingroup$ @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. $\endgroup$ 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}) // 

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)  *)


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.