## SAGE tip: Calculation of Riemann tensor

February 3, 2011 by doxdrum

I just finished a sheet of SAGE where given a metric, the Christoffel symbols, the Riemann tensor and the Ricci tensor are calculated. I publish it in my google site (at the end of the page).

It is a very rudimentary sheet, but it could be a tiny part of a class for computing **GR tensors** (or even more) 🙂

## Possible Improvements

As you might notice, the Ricci tensor of the Schwarzschild metric is not simplified! Although is zero.
A way to show the non-zero components of the tensors.
It is just the `hard-core’ code… so is far from being efficient.
Implement tensors like a class, and allow raising and lowering indices with ease.
Much more!!!!Please! feel free to post either here or in sage-devel google group about possible improvements or your own implementations.

Enjoy!

DOX.

### Like this:

Like Loading...

*Related*

Posted in Linux, Mathematics, Physics, Science | Tagged Calculation, Christoffel, chrome, chromium, CLI, Command, Computers, Free, Functions, General, How to, HowTo, Linux, Maple, Mathematica, Mathematics, Matlab, Notebook, Packages, Programming, Python, Relativity, Ricci, Riemann, Sage, Sage-dev, Sagemath, Symbolic, Symbols, Tensor, Tensors, Terminal, Tips and Tricks, Ubuntu, Web Browser | 8 Comments

on February 4, 2011 at 9:14 pm |SAGE tip: Convert a 2D list into a matrix « Doxdrum's Blog[…] Comments « SAGE tip: Calculation of Riemann tensor […]

on February 4, 2011 at 11:12 pm |yutakashinoHi, thanks for showing your implementation of Riemann tensor, but I got an error on my SAGE 4.5.3. Which version of SAGE do you use?

—

cosa = [[[sum(ginv[a][i] * diff(g[b][i], coord[c]), i, 0, dim-1) for b in range(dim)] for a in range(dim)] for c in range(dim)]

evaluate

Traceback (most recent call last):

File “”, line 1, in

File “_sage_input_8.py”, line 10, in

exec compile(u’open(“___code___.py”,”w”).write(“# -*- coding: utf-8 -*-\\n” + _support_.preparse_worksheet_cell(base64.b64decode(“Y29zYSA9IFtbW3N1bShnaW52W2FdW2ldICogZGlmZihnW2JdW2ldLCBjb29yZFtjXSksIGksIDAsIGRpbS0xKSBmb3IgYiBpbiByYW5nZShkaW0pXSBmb3IgYSBpbiByYW5nZShkaW0pXSBmb3IgYyBpbiByYW5nZShkaW0pXQ==”),globals())+”\\n”); execfile(os.path.abspath(“___code___.py”))

File “”, line 1, in

File “/private/var/folders/tG/tGhuuqZjGqaop4NGbrF4Hk+++TI/-Tmp-/tmp1Je76m/___code___.py”, line 3, in

exec compile(u’cosa = [[[sum(ginv[a][i] * diff(g[b][i], coord[c]), i, _sage_const_0 , dim-_sage_const_1 ) for b in range(dim)] for a in range(dim)] for c in range(dim)]

File “”, line 1, in

File “free_module_element.pyx”, line 2413, in sage.modules.free_module_element.FreeModuleElement_generic_dense.__getitem__ (sage/modules/free_module_element.c:16355)

File “expression.pyx”, line 3678, in sage.symbolic.expression.Expression.__index__ (sage/symbolic/expression.cpp:16613)

File “expression.pyx”, line 673, in sage.symbolic.expression.Expression._integer_ (sage/symbolic/expression.cpp:4115)

File “integer.pyx”, line 638, in sage.rings.integer.Integer.__init__ (sage/rings/integer.c:6425)

File “number_field_element_quadratic.pyx”, line 937, in sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic._integer_ (sage/rings/number_field/number_field_element_quadratic.cpp:7984)

TypeError: Unable to coerce I to an integer

on February 5, 2011 at 8:44 am |doxdrumHi there yutakashino, I’m using SAGE 4.6.1.

However, I must apologize, that line was a try to construct a 3D list… and if I remember well, didn’t work for me either. So, you can just forget about that line.

I’ll drop that line from the worksheet and upload it again! THX. 😉

DOX.

on February 5, 2011 at 9:54 pmyutakashinoHello doxdrum, thanks. It works. I totally agree with your idea of making a general relativity calculation machinery in SAGE.

on February 6, 2011 at 5:11 amdoxdrumThen you’ll love my new section of posts,

GR-module. In there I expect to keep track of the development of the module for GR calculations. Of course it could be a slow process… ’cause I’m not a programmer.Cya around! 🙂

on February 5, 2011 at 7:49 am |Joris VankerschaverHi Dox, great post and a great worksheet! I just had one technical comment: for those of us who subscribe to your site through Google Reader, whenever you post an article I just see the summary but no link. I’m not sure if this is clear, but I can send you a screenshot if necessary.

on February 5, 2011 at 8:38 am |doxdrumHi Joris, thank you for your comment. I’ll try to solve that problem, ’cause it happens to me as well! 😛

on February 6, 2011 at 5:00 am |doxdrumHi again Joris.

Yesterday I add my blog to Google reader and the links were working.

add subscription.https://doxdrum.wordpress.com/feed/Don’t know why didn’t work before. Let me know if the problem holds. 🙂 Cya