0

Anyone know how to do the partial derivative of a tensor in d dimensions on Mathematica ?

I want to implement something which will calculate directly like that :

enter image description here

1 Answers1

2

One way is to utilize FeynCalc --- see this link

<< FeynCalc`;

$\frac{\partial p^{\mu}}{\partial p^{\nu}}$

FourDivergence[FVD[p, μ], FVD[p, ν]]

g^(μν)


$\frac{\partial p^{\mu}}{\partial p^{\mu}}$

FourDivergence[FVD[p, μ], FVD[p, μ]]

D


$\frac{\partial p^{-2}}{\partial p^{\nu}}$

FourDivergence[1/SPD[p, p], FVD[p, ν]]

-((2 p^ν)/p^4)

Another approach would be to define in mathematica something, say partD, and implement the rules of differentiation. If you like this latter approach, ping a comment and I will try to update.

Edit after the comment: for the latter approach see the very useful information contained here. It is an excellent response by the user @unstable, so please upvoting it!

Also, I have not used this code in a while so please make sure to run extensive tests. Below I am giving the basics and some basic results. You might need to add a couple of lines for yourself.

We start by some basic rules

  1. Basic rules

1.1: Addition

a : pD[_Plus, ___] := Thread[Unevaluated[a], Plus, 1]

1.2: Multiplication

pD[a_Times, x___] := 
 Plus @@ (MapAt[pD[#, x] &, a, #] & /@ Range[Length[a]])

1.3 Powers

pD[a_^b_, x___] := b a^(b - 1) pD[a, x]
  1. Definitions for covariant type terms -- - indices down --- $\partial_a x_b$

pD[fvd[notk_Symbol, idx_List], fvd[k_Symbol, derividx_List]] := 0 /; FreeQ[notk, k] pD[fvd[k_Symbol, idx_List], fvd[k_Symbol, derividx_List]] := fvd[idx, derividx]

  1. Definitions for contravariant type terms -- - indices up --- $\partial^a x^b$

pD[fvu[notk_Symbol, idx_List], fvu[k_Symbol, derividx_List]] := 0 /; FreeQ[notk, k] pD[fvu[k_Symbol, idx_List], fvu[k_Symbol, derividx_List]] := fvu[idx, derividx]

  1. Definitions for mixed quantities --- $\partial_a x^b$ and $\partial^a x_b$

pD[fvd[notk_Symbol, idx_List], fvu[k_Symbol, derividx_List]] := 0 /; FreeQ[notk, k] pD[fvd[k_Symbol, idx_List], fvu[k_Symbol, derividx_List]] := fvmix[idx, derividx]

and for the latter form

pD[fvu[notk_Symbol, idx_List], fvd[k_Symbol, derividx_List]] := 0 /; FreeQ[notk, k] pD[fvu[k_Symbol, idx_List], fvd[k_Symbol, derividx_List]] := fvmix[idx, derividx]

  1. Display format - I had a Euclidean metric so it is written as a Kronecker-$\delta$

Format[fvd[k_Symbol, {i_}]] := DisplayForm@SubscriptBox[k, i] Format[fvu[k_Symbol, {i_}]] := DisplayForm@SuperscriptBox[k, i] Format[fvd[{i_}, {j_}]] := DisplayForm@SubscriptBox[δ, RowBox[{i, j}]] Format[fvu[{i_}, {j_}]] := DisplayForm@SuperscriptBox[δ, RowBox[{i, j}]] Format[fvmix[{i_}, {j_}]] := DisplayForm@SubsuperscriptBox[δ, RowBox[{j}], RowBox[{i}]]

Ok, so now how we can code stuff:

First, displaying the metric:

fvd[{a}, {b}]

δ_{ab}

and with indices up

fvu[{a}, {b}]

δ^{ab}

and with up-down

fvmix[{a}, {b}]

δ^{a}_{b}

So, you get the idea. Recall that 4-vectors are symbol and list, i.e

fvd[x, {a}]

x_{a}

A couple of minimal examples:

  1. $\partial_a x_b$

pD[fvd[x, {b}], fvd[x, {a}]]

δ_{ba}

Let's do a sum as well to make sure it works

pD[fvd[x, {b}] + fvd[x, {c}], fvd[x, {a}]]

δ_{ba} + δ_{ca}

We also do a product

pD[fvd[x, {b}] fvd[x, {c}], fvd[x, {a}]]

x_c δ_{ba} + x_b δ_{ca}

Something a bit more complicated

pD[(fvd[x, {a}] fvd[x, {a}])/fvd[x, {b}], fvd[x, {a}]]

vectors

bmf
  • 15,157
  • 2
  • 26
  • 63