Let $\mathbf{R} = [x,y,z]$ be a cartesian vector, $R_\alpha$ it's tensor representation with $\alpha = x,y,z$ and let $R=\sqrt{x^2 + y^2 + z^2}$ be its norm. I want to do tensor derivatives of the Coulomb potential $1/R$. The first derivative is $\frac{\partial}{\partial R_\alpha} \frac{1}{R} = -\frac{R_\alpha}{R^3}$ and the second derivative is $\frac{\partial}{\partial R_\beta} \frac{\partial}{\partial R_\alpha} \frac{1}{R}= \frac{\delta_{\alpha\beta}R^2 - R_\alpha R_\beta }{R^5}$. I want to make further derivatives in Mathematica.

I tried

R = Sqrt[x^2 + y^2 + z^2]


$\sqrt{x^2 + y^2 + z^2}$

rR = 1/R


$\frac{1}{\sqrt{x^2 + y^2 + z^2}}$

drR = Grad[rR, {x, y, z}, "Cartesian"]


$\{-\frac{x}{(x^2 + y^2 + z^2)^{3/2}}, -\frac{y}{(x^2 + y^2 + z^2)^{3/2}}, -\frac{z}{(x^2 + y^2 + z^2)^{3/2}} \}$

So can I make Mathematica identify the denominators as $R^3$ and the numerators as $R_\alpha$ and get it to the compact form $-\frac{R_\alpha}{R^3}$, or is there some other way to do tensor calculus/arithmetics compactly?

Perhaps something like the following will suffice?

R /: D[R, R[α_], NonConstants->{R}] := R[α]/R
R /: D[R[α_], R[β_], NonConstants->{R}] := KroneckerDelta[α, β]

R /: MakeBoxes[R[α_], fmt_] := MakeBoxes[Subscript[R,α], fmt]


D[1/R, R[α], NonConstants->{R}] //TeXForm

$-\frac{R_{\alpha }}{R^3}$
D[1/R, R[α], R[β], NonConstants->{R}] //TeXForm

$\frac{3 R_{\alpha } R_{\beta }}{R^5}-\frac{\delta _{\alpha ,\beta }}{R^3}$
• This is beautiful, thanks a lot! Maybe you put in Clear[R] at the top, because I didn't get it to work first since $R$ was already defined in the notebook. – Jonatan Öström May 2 '17 at 10:06