# Mathematica for General Relativity and Gravity research

**URL:** <https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202>\
**Category:** Questions\
**Tags:** astronomy, physics, mathematica\
**Created:** [May 14, 2014, 6:31pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202 "2014-05-14T18:31:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![latoshboris](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@latoshboris](https://community.wolfram.com/u/latoshboris)\
**Post date:** [May 14, 2014, 6:31pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/1 "2014-05-14T18:31:41Z")

</div>

Dear community members,

I’m currently try to use Wolfram Mathematica to some gravity research. But i can’t find built-in methods do differential geometry calculations in Mathematica.  
For example, is there any way to compute Einstein or Ricci tensor by metric? Or something more complicate, like create manifold, some medium with fixed state equation and write Einstein equations for this system?

Thanks,

Boris Latosh

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [May 14, 2014, 8:39pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/2 "2014-05-14T20:39:11Z")

</div>

There are some old Mathematica (v 4) notebooks for doing GR at this link:

> **[mathematica](https://web.physics.ucsb.edu/~gravitybook/mathematica.html)**

I’ve updated and run one of them myself and it worked fine,  
working from the pdf version. It may be possible to run the notebook itself  
but I didn’t try that.

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [May 15, 2014, 4:11pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/3 "2014-05-15T16:11:43Z")

</div>

You might want to have a look at this:

> **[Wolfram Mathematica: Books](https://www.wolfram.com/books/profile.cgi?id=7182)**

M.

---

<div class="post-metadata">

**Author:** ![stevec](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/stevec/32/8277_2.png) [@stevec](https://community.wolfram.com/u/stevec)\
**Post date:** [May 15, 2014, 6:41pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/4 "2014-05-15T18:41:52Z")

</div>

If you want a full tensor analysis system that will also do what you mention, see

[http://smc.vnet.net/mathtensor.html](http://smc.vnet.net/mathtensor.html)

[http://www.amazon.com/MathTensor-System-Tensor-Analysis-Computer/dp/0201569906/ref=sr\_1\_1?ie=UTF8&qid=1400179230&sr=8-1&keywords=mathtensor](http://www.amazon.com/MathTensor-System-Tensor-Analysis-Computer/dp/0201569906/ref=sr_1_1?ie=UTF8&qid=1400179230&sr=8-1&keywords=mathtensor)

Steve C.

---

<div class="post-metadata">

**Author:** ![latoshboris](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@latoshboris](https://community.wolfram.com/u/latoshboris)\
**Post date:** [May 15, 2014, 8:06pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/5 "2014-05-15T20:06:20Z")

</div>

Great! Thank to everybody! This will do for beginning!

---

<div class="post-metadata">

**Author:** ![doug](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/doug/32/9648_2.png) [@doug](https://community.wolfram.com/u/doug)\
**Post date:** [May 15, 2014, 10:11pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/6 "2014-05-15T22:11:52Z")

</div>

How does one work from a pdf version?

---

<div class="post-metadata">

**Author:** ![samcarrettie](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/samcarrettie/32/29668_2.png) [@samcarrettie](https://community.wolfram.com/u/samcarrettie)\
**Post date:** [May 15, 2014, 10:19pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/7 "2014-05-15T22:19:42Z")

</div>

Please take a look at the new Symbolic Tensors functionality introduced in version 9. Specifically:

- [Symbolic Tensors](http://reference.wolfram.com/mathematica/guide/SymbolicTensors.html) - guide
- [Tensors](http://reference.wolfram.com/mathematica/guide/Tensors.html) - guide
- [Symbolic Tensors](http://reference.wolfram.com/mathematica/tutorial/SymbolicTensors.html)- tutorial
- [Tensor Symmetries](http://reference.wolfram.com/mathematica/tutorial/TensorSymmetries.html) - tutorial
- [Symmetrized Arrays](http://reference.wolfram.com/mathematica/tutorial/SymmetrizedArrays.html) - tutorial

To get started with basic examples read through this page: [TensorProduct](http://reference.wolfram.com/mathematica/ref/TensorProduct.html)

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [May 17, 2014, 1:29pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/8 "2014-05-17T13:29:04Z")

</div>

I looked at the TensorProduct page and didn’t see a component-based definition of TensorProduct.

---

<div class="post-metadata">

**Author:** ![dreiss](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/dreiss/32/29094_2.png) [@dreiss](https://community.wolfram.com/u/dreiss)\
**Post date:** [May 18, 2014, 2:16am UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/9 "2014-05-18T02:16:03Z")

</div>

You may want to look through this thread on Mathematica StackExchange:

[http://mathematica.stackexchange.com/questions/8895/how-to-calculate-scalar-curvature-ricci-tensor-and-christoffel-symbols-in-mathem/](http://mathematica.stackexchange.com/questions/8895/how-to-calculate-scalar-curvature-ricci-tensor-and-christoffel-symbols-in-mathem/)

which has material that may help you get going (as well as having some additional possibly useful links)

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/szhorvat/32/3531_2.png) [@szhorvat](https://community.wolfram.com/u/szhorvat)\
**Post date:** [May 20, 2014, 2:10pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/10 "2014-05-20T14:10:17Z")

</div>

I did not need this type of functionality in the past, so unfortunately I cannot tell you which packages are the most useful.

But you’ll find [a list of tensor-related packages here on Mathematica.SE](http://mathematica.stackexchange.com/a/19938/12).

The list can be edited by the public wiki-style, so if you put some time into trying one of these packages, you can add a paragraph to the wiki post describing your experiences.

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [May 20, 2014, 2:43pm UTC](https://community.wolfram.com/t/mathematica-for-general-relativity-and-gravity-research/2202/11 "2014-05-20T14:43:23Z")

</div>

Here’s my rewrite of one of the notebooks at [mathematica](http://web.physics.ucsb.edu/~gravitybook/mathematica.html).

```auto
rewritten from http://web.physics.ucsb.edu/~gravitybook/math/curvature.pdf 

In[5]:= n = 4;

In[6]:= coord = {r, \[Theta], \[Phi], t};

In[8]:= metric = DiagonalMatrix[{(1 - 2 m/r)^-1, r^2, r^2 Sin[\[Theta]]^2, 
    2 m/r - 1}];

In[10]:= inversemetric = Simplify @ Inverse[metric];

In[12]:= 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, n}], {i, n}, {j, n}, {k, n}];

In[14]:= riemann = Simplify @ 
   Table[D[affine[[i, j, l]], coord[[k]]] - D[affine[[i, j, k]], coord[[l]]] +
      Sum[affine[[s, j, l]] affine[[i, k, s]] - 
       affine[[s, j, k]] affine[[i, l, s]], {s, n}], {i, n}, {j, n}, {k, 
     n}, {l, n}];

In[15]:= ricci = Simplify @ Table[Sum[riemann[[i, j, i, l]], {i, n}], {j, n}, {l, n}]

Out[15]= {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}

In[16]:= scalar = Simplify[Sum[inversemetric[[i, j]] ricci[[i, j]], {i, n}, {j, n}]]

Out[16]= 0

In[17]:= einstein = ricci - 1/2 scalar*metric

Out[17]= {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}

```

It shows that the Schwarzschild metric satisifes the Einstein equation. I didn’t show the components of the 3rd and 4th rank tensors here.
