Tuesday, September 07, 2010

Learning to Use Tensors in Maxima

In my previous post I used Maxima to derive the metric tensor of the 3-sphere using the coordinate system described by Mathview in his YouTube video. Now I'd like to continue exploring Maxima to calculate various other properties of S^3.

In a follow up video where he calculated the Christofell symbols for the 3-sphere, Mathview used new coordinate transformations that give a right-handed coordinate system instead of a left-handed one as in his previous video. It is very similar to the original, the difference being just the choice of the 3rd angle, theta3. This small change greatly simplifies the metric tensor and, as a consequence, all other derived tensors and properties. You can follow his derivation in the video below.

How do I get the Christoffel Symbols on the 3-Sphere?



Last time I used just the basic facilities of Maxima to derive the metric tensor from the transformations. I then said that it would be nice, in the future, to use one of the tensor packages that comes with Maxima to redo those calculations. Today I found out that you can start from the coordinate transformations and go directly to the metric, Christofells and other tensors. However, we can plug in the output of my original method into the ctensor package and continue from there. Although this gives a little more work it is more pedagogical as it reveals some of the details of how tensors are handled by this package.

So here we will quickly repeat the derivation of the metric tensor, only now using Mathview's new coordinate system. We assign the final matrix to "lg", for "lower-indices g". Maxima uses this convention to name some of the variables that it uses to hold tensors. The first letter in the name can be "l", "u" or "m" for lower, upper or mixed indices respectively.



I don't know why g[2,2] came out with (1 - sin(theta[3])^2) instead of cos(theta[3])^2. I tried other simplification functions but none did this transformation so I ended up doing it by hand.

Next we calculate ug, the inverse of lg, as it will also be needed.



Maxima comes with two packages that handle tensors: itensor and ctensor. The former does indicial tensor manipulation and the latter does component manipulation. ctensor is sometimes also referred to as the "curved space" tensor package. This is the one we want!

As I said, ctensor has a way to allow you to start directly from the coordinate transformations (ct_coordsys()). There is also a dialog based function that asks for the various components of the metric tensor (csetup()). But we have already calculated the metric tensor by our own device and the choice of names "lg" and "ug" was no accident: they are exactly what ctensor expects.

At this point we can see that Maxima implements component tensors as regular multi-dimensional arrays: [n,n] arrays (matrices) for rank 2 tensors, [n,n,n] arrays for rank 3 tensors and so on up to rank 5. Another interesting observation is that ctensor is not built in Maxima, but rather, it's a loadable package. In other words, it's implemented in the Maxima programming language, not in Lisp.

Therefore, we next load ctensor and give it the missing information it needs to do its calculations: the number of dimensions we'll be working on and a list of the variables that hold the coordinates.



Now we're ready for the fun! Equipped with the metric tensor and the list of variable names, ctensor can easily calculate the Christofell symbols, the Ricci tensor and many others. We'll start with the Christofell symbols of the 1st kind, which ctensor names as "lcs" because all the indices are downstairs:



Some observations are needed here. First, note that ctensor displays only the non-zero, unique elements in lcs[i,j,k]. In this exercise there are 6 non-zero elements, but only 4 are unique. The other two are duplicates due to the symmetry of lcs[]. Second, the convention that Mathview uses for the indices is different from the one used by Maxima. To convert between Mathview and Maxima, just reverse the order of the indices. So, what Mathview calls Gamma(3,1,1) is the same as lcs[1,1,3] which is -cos(theta[3]) * sin(theta[3]) * a^2. Finally, it's a pity that wxMaxima displays the Christofell symbols this way. It would have been nicer to use the proper Gamma character!

Now, just for fun we calculate the Christoffell symbols of the second kind (mcs), the Ricci tensor and the Riemann curvature tensor.



This post shows but a small portion of the capabilities of ctensor and Maxima. There are dozens of other interesting functions that you can learn about by reading the manual. Although there's no doubt about the power of Maxima for manipulating tensors, students learning the subject should make sure to go over the whole process of calculating the Christofell symbols and the Ricci and Riemann tensors by hand a few times. By watching Mathview's videos you'll see how much more insight this approach gives you as opposed to just seeing Maxima spit out the answers!

1 comment:

mr.clifford johnson said...

kill(all);

/* http://top-quark.blogspot.com/2010/09/learning-to-use-tensors-in-maxima.html */

r[1] : a * sin(theta[3]);
r[2] : a * cos(theta[3]);
x : r[1] * cos(theta[1]);
y : r[1] * sin(theta[1]);
z : r[2] * cos(theta[2]);
w : r[2] * sin(theta[2]);
X : [x,y,z,w];

g[i,j] := trigsimp(diff(X,theta[i]) . diff(X,theta[j]));

lg : genmatrix(g,3,3,1,1);
ug : invert(lg);

load(ctensor);

dim : 3;
ct_coords : [theta[1],theta[2],theta[3]];

christof(lcs);
christof(mcs);
ricci(1);
riemann(1);