4
$\begingroup$

I am very new to Mathematica, and am trying to use it to compute Christoffel symbols for a certain manifold. All this requires is taking some indexed sums of derivatives, but it builds up on several different things, and I am missing something in defining the indexed variables. This might be a little long, but I would really appreciate any help that I could get.

I started by defining the local coordinate function and finding its partial derivatives and then the elements of the metric tensor:

f[x1_, x2_] = {x1, x2, Sqrt[r^2 - x1^2 - x2^2};
fx = D[f[x1, x2], x1],
fy = D[f[x1, x2], x2]
g[1, 1, x1_, x2_] = fx.fx,
g[1, 2, x1_, x2_] = fx.fy 
g[2, 1, x1_, x2_] = fx.fy
g[2, 2, x1_, x2_] = fy.fy

Running this code goes smoothly, giving me three functions of $x_1$ and $x_2$ that match what I computed by hand. I then want to calculate the inverse of the coordinate representation of the metric tensor, which is easily done:

Inverse[{{g[1, 1, x1_, x2_], g[1, 2, x1_, x2_]}, 
{g[2, 1, x1_, x2_], g[2, 2, x1_, x2_]}}]

Then defining the components of this matrix from what we get:

ginv[1, 1, x1_, x2_] = 1 - x1^2/r^2
ginv[2, 2, x1_, x2_] = 1 - x2^2/r^2
ginv[1, 2, x1_, x2_] = -((x1 * x2)/r^2)
ginv[2, 1, x1_, x2_] = -((x1 * x2)/r^2),

we have everything that we should need to get our Christoffel symbols. The equation for Christoffel symbols in local coordinates is

$\newcommand{\p}{\partial} \Gamma_{ij}^k = \frac{1}{2}\left(\frac{\p g_{j \ell}}{\p x^i} + \frac{\p g_{\ell i}}{\p x^j} - \frac{\p g_{ij}}{\p x^\ell}\right)g^{\ell k}$

I don't know anything about using Einstein notation in Mathematica (I am very new to it), so since our indices only range from one to two, I just wrote out the whole thing without using dummy indices at all. This is where I ran into problems. I know that my syntax is wrong, but I thought I'd try it anyway since I could find out how to do this correctly anywhere online at all. Here is what I tried to define the Christoffel symbol "function" (of $i, j, k$) as:

Gamma[i_, j_, k_, x1_, x2_] = 
 0.5*(D[g[j, 1, x1, x2], xi] + D[g[1, i, x1, x2], xj] - 
     D[g[i, j, x1, x2], x1])*ginv[1, k, x1, x2] + 
  0.5*(D[g[j, 2, x1, x2], xi] + D[g[2, i, x1, x2], xj] - 
     D[g[i, j, x1, x2], x2])*ginv[2, k, x1, x2]

I couldn't figure out any other way to make $x$ a function of an index $i$ without changing too much else and running into issues with taking partial derivatives by $x_i$ and other things like that. How do I fix this to accurately define a function of indices that can be differentiated etc. (I am trying to calculate components of the Riemannian curvature tensor using the Christoffel symbols)?

Any help would be wonderful!

$\endgroup$
4
  • $\begingroup$ Can you, please, be more specific as to what the problems/errors that you are encountering are? What should be the expected behavior? $\endgroup$ Mar 16, 2021 at 8:37
  • $\begingroup$ The very first line f[x1_, x2_] = [x1, x2, Sqrt[r^2 - x1^2 - x2^2]. is not syntactically correct. Do you mean: f[x1_, x2_] = {x1, x2, Sqrt[r^2 - x1^2 - x2^2};? $\endgroup$ Mar 16, 2021 at 9:25
  • $\begingroup$ Oh yeah, I just mistyped that in here, I used braces in the engine though. $\endgroup$
    – Rough L
    Mar 16, 2021 at 9:28
  • 1
    $\begingroup$ The expected behavior is, for example, gamma[1, 1, 1, a, b] = 0.5*(D[g[j, 1, x1, x2], x1] + D[g[1, 1, x1, x2], x1] - D[g[1, 1, x1, x2], x1])*ginv[1, k, x1, x2] + 0.5*(D[g[1, 2, x1, x2], x1] + D[g[2, 1, x1, x2], x1] - D[g[1, 1, x1, x2], x2])*ginv[2, k, x1, x2] $\endgroup$
    – Rough L
    Mar 16, 2021 at 9:29

1 Answer 1

4
$\begingroup$

With syntax errors corrected, I choose as summation index m not l to make it more readable.

Can you check if my result is correct:

f[x1_, x2_] = {x1, x2, Sqrt[r^2 - x1^2 - x2^2]};
fx = D[f[x1, x2], x1];
fy = D[f[x1, x2], x2];
g[1, 1, x1_, x2_] = fx.fx;
g[1, 2, x1_, x2_] = fx.fy;
g[2, 1, x1_, x2_] = fx.fy;
g[2, 2, x1_, x2_] = fy.fy;

ginv[1, 1, x1_, x2_] = 1 - x1^2/r^2;
ginv[2, 2, x1_, x2_] = 1 - x2^2/r^2;
ginv[1, 2, x1_, x2_] = -((x1*x2)/r^2);
ginv[2, 1, x1_, x2_] = -((x1*x2)/r^2);

xs = {x1, x2};
gamma[i_, j_, k_, x1_, x2_] := 
 1/2 Sum[(D[g[j, m, x1, x2], xs[[i]]] + D[g[m, i, x1, x2], xs[[j]]] - 
      D[g[i, j, x1, x2], {x1, x2}[[m]]])*ginv[m, k, x1, x2], {m, 1, 2}
   ]

gamma[1, 1, 1, a, b]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you very much! I really appreciate it. And one more question, if you don't mind. Why do you use := instead of = when defining gamma? Is there any difference? $\endgroup$
    – Rough L
    Mar 16, 2021 at 12:15
  • $\begingroup$ With = the right hand side of the expression is calculated immediately. However, at this time indices i,j,k do not have a value yet. Therefore expressions like g[j, m, x1, x2]will have unevaluated indices. Although = may be more efficient, if you are in doubt, use := to be on the safe side. $\endgroup$ Mar 16, 2021 at 12:23
  • $\begingroup$ Awesome, thank you! $\endgroup$
    – Rough L
    Mar 16, 2021 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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