# Klein-Gordon Equation: how can I write the summation?

I would like to write a program that gives me the Klein Gordon Equations given a metric. I will explain.

My code is in the following:

I) Standard Quantities

I have no doubt here the first part is given by Hartle's.

Clear[coord, metric, inversemetric, affine, riemann, ricci,
scalar, einstein, t, x, y, z]

n = 4;
coord = {t, r, θ, ϕ};

metric = {{-(1 - ((2*m)/(r))), 0, 0, 0},
{0, (1)/(1 - ((2*m)/(r))), 0, 0},
{0, 0, r^2, 0},
{0, 0, 0, r^2*(Sin[θ]*Sin[θ])}};

inversemetric = Simplify[Inverse[metric]];
Det[metric]


II) MY TRY

I wrote the components by hand:

KG00 = FullSimplify[((1)/(Sqrt[-Det[metric]]))*
D[(Sqrt[-Det[metric]])*(inversemetric[[1, 1]])*
D[Ξ[t, r, θ, ϕ], t], t]];

KG11 =  FullSimplify[((1)/(Sqrt[-Det[metric]]))*
D[(Sqrt[-Det[metric]])*(inversemetric[[2, 2]])*
D[Ξ[t, r, θ, ϕ], r], r]];

KG22 = FullSimplify[((1)/(Sqrt[-Det[metric]]))*
D[(Sqrt[-Det[metric]])*(inversemetric[[3, 3]])*
D[Ξ[t, r, θ, ϕ], θ], θ]];

KG33 =  FullSimplify[((1)/(Sqrt[-Det[metric]]))*
D[(Sqrt[-Det[metric]])*(inversemetric[[4, 4]])*
D[Ξ[t, r, θ, ϕ], ϕ], ϕ]];

KG00 + KG11 + KG22 + KG33


III) What I would Like

I would like to use summation convention on the code of section II), since the Klein-Gordon equations are given by:

$$\frac{1}{\sqrt{-g}}\sum_{\mu=1}^{4}\sum_{\nu=1}^{4}\partial_{\mu}\Bigg(\sqrt{-g}g^{\mu\nu}\partial_{\nu} \Psi(r,\theta,\phi,t) \Bigg) \tag{1}$$

IV) Hartle's code on summation convention

Actually, Hartle's $$[1]$$ gives an way to work with tensor indexes, for instance the Christoffel Symbols are given by:

$$\Gamma^{s}_{jk}=\sum_{s=1}^{4}\frac{1}{2}g^{is}\Bigg(g_{sj,k} + g_{sk,j} - g_{jk,s} \Bigg) \tag{2}$$

and the code using summation is:

affine :=
affine = Simplify[
Table[(1/2)*
Sum[
inversemetric[[i, s]]*(D[metric[[s, j]], coord[[k]]] +
D[metric[[s, k]], coord[[j]]] -
D[metric[[j, k]], coord[[s]]]),
{s, 1, n}
],
{i, 1, n}, {j, 1, n}, {k, 1, n}
] ];

listaffine :=
Table[
If[UnsameQ[affine[[i, j, k]], 0],
{ToString[Γ[i - 1, j - 1, k - 1]],
affine[[i, j, k]]}
],
{i, 1, n}, {j, 1, n}, {k, 1, j}
];

TableForm[
Partition[DeleteCases[Flatten[listaffine], Null], 2],
TableSpacing -> {2, 2}
]

• You mean something like this?: mathematica.stackexchange.com/a/216806/1871 Commented Jul 8, 2020 at 15:33
• @xzczd yes, einstein summation convention. Commented Jul 8, 2020 at 22:54

We can use this code for Klein-Gordon:

Clear[coord, metric, inversemetric, affine, riemann, ricci, scalar, \
einstein, t, r, θ, ϕ]

n = 4;
coord = {t, r, θ, ϕ};

g = {{-(1 - ((2*m)/(r))), 0, 0, 0}, {0, 1/(1 - ((2*m)/(r))), 0,
0}, {0, 0, r^2, 0}, {0, 0, 0, r^2*(Sin[θ]*Sin[θ])}};

g1 = Simplify[Inverse[g]];
dg = Det[g];
KG = 1/Sqrt[-dg] Sum[
D[Sqrt[-dg] g1[[i, j]] D[psi[t, r, θ, ϕ], coord[[j]]],
coord[[i]]], {i, n}, {j, n}]


Now we can compare KG with spherical Laplacian

KG /. m -> 0 // FullSimplify

Laplacian[psi[t, r, θ, ϕ], {r, θ, ϕ},
"Spherical"] // FullSimplify


And we see that two expression differ on second derivative $$\partial_t \partial_t \psi$$ as expected.

You can try my allowtensor. Since it's a 4D problem, you need to set the value of global variable $tensordimension to 4: dmetric = Det[metric]; ref = KG00 + KG11 + KG22 + KG33;$tensordimension = 4;
mykg = allowtensor[
1/Sqrt[-dmetric] D[Sqrt[-dmetric] inversemetric[[i, j]] D[Ξ[t, r, θ, ϕ],
coord[[j]]], coord[[i]]], {i, j}];

mykg == ref // Simplify
(* True *)


Definitions of metric etc. are the same as yours.