LaTeX Interface to SymPy (CAS) for General Relativity
Project description
NRPy+'s LaTeX Interface to SymPy (CAS) for General Relativity
- automatic expansion of
- Einstein summation convention
- Levi-Civita and Christoffel symbols
- Lie and covariant derivatives
- metric inverse and determinant
- automatic index raising and lowering
- arbitrary coordinate system (default)
- exception handling and debugging
§ Installation
To install NRPyLaTeX using PyPI, run the following command in the terminal
$ pip install nrpylatex
§ Exporting (CAS)
If you are using Mathematica instead of SymPy, run the following code to convert your output
from sympy import mathematica_code
namespace = parse_latex(...)
for var in namespace:
exec(f'{var} = mathematica_code({var})')
If you are using a different CAS, reference the SymPy documentation to find the relevant printing function.
§ Interactive Tutorial (MyBinder)
Quick Start | NRPy+ Integration | Guided Example (BSSN Formalism)
§ Documentation and Usage
Getting Started and API Reference
Simple Example (Kretschmann Scalar)
Python REPL or Script (*.py)
>>> from nrpylatex import parse_latex
>>> parse_latex(r"""
... % ignore "\begin{align}" "\end{align}"
... \begin{align}
... % coord [t, r, \theta, \phi]
... % define gDD --dim 4 --zeros
... % define G M --const
... %% define Schwarzschild metric diagonal
... g_{t t} &= -\left(1 - \frac{2GM}{r}\right) \\
... g_{r r} &= \left(1 - \frac{2GM}{r}\right)^{-1} \\
... g_{\theta \theta} &= r^2 \\
... g_{\phi \phi} &= r^2 \sin^2{\theta} \\
... %% generate metric inverse gUU, determinant det(gDD), and connection GammaUDD
... % assign gDD --metric
... R^\alpha{}_{\beta \mu \nu} &= \partial_\mu \Gamma^\alpha_{\beta \nu} - \partial_\nu \Gamma^\alpha_{\beta \mu}
... + \Gamma^\alpha_{\mu \gamma} \Gamma^\gamma_{\beta \nu} - \Gamma^\alpha_{\nu \sigma} \Gamma^\sigma_{\beta \mu} \\
... K &= R^{\alpha \beta \mu \nu} R_{\alpha \beta \mu \nu}
... \end{align}
... """)
('G', 'GammaUDD', 'gDD', 'gUU', 'epsilonUUUU', 'RUDDD', 'K', 'RUUUU', 'M', 'r', 'theta', 'RDDDD', 'gdet')
>>> from sympy import simplify
>>> print(simplify(K))
48*G**2*M**2/r**6
IPython REPL or Jupyter Notebook
In [1]: %load_ext nrpylatex
In [2]: %%parse_latex
...: % ignore "\begin{align}" "\end{align}"
...: \begin{align}
...: % coord [t, r, \theta, \phi]
...: % define gDD --dim 4 --zeros
...: % define G M --const
...: %% define Schwarzschild metric diagonal
...: g_{t t} &= -\left(1 - \frac{2GM}{r}\right) \\
...: g_{r r} &= \left(1 - \frac{2GM}{r}\right)^{-1} \\
...: g_{\theta \theta} &= r^2 \\
...: g_{\phi \phi} &= r^2 \sin^2{\theta} \\
...: %% generate metric inverse gUU, determinant det(gDD), and connection GammaUDD
...: % assign gDD --metric
...: R^\alpha{}_{\beta \mu \nu} &= \partial_\mu \Gamma^\alpha_{\beta \nu} - \partial_\nu \Gamma^\alpha_{\beta \mu}
...: + \Gamma^\alpha_{\mu \gamma} \Gamma^\gamma_{\beta \nu} - \Gamma^\alpha_{\nu \sigma} \Gamma^\sigma_{\beta \mu} \\
...: K &= R^{\alpha \beta \mu \nu} R_{\alpha \beta \mu \nu}
...: \end{align}
Out[2]: ('G', 'GammaUDD', 'gDD', 'gUU', 'epsilonUUUU', 'RUDDD', 'K', 'RUUUU', 'M', 'r', 'theta', 'RDDDD', 'gdet')
In [3]: from sympy import simplify
In [4]: print(simplify(K))
Out[4]: 48*G**2*M**2/r**6
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nrpylatex-1.4.0.tar.gz.
File metadata
- Download URL: nrpylatex-1.4.0.tar.gz
- Upload date:
- Size: 32.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.8 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56685c58b62f90875bf7a75d0115f2b7b9154c2554f1e0968dee5786ac334b8c
|
|
| MD5 |
100f730cd3bed713dd2d7689c327a50d
|
|
| BLAKE2b-256 |
d57bf374701590597a4b0a983599ba4db53dbfdc923b7ac48bc6f8492981ac04
|
File details
Details for the file nrpylatex-1.4.0-py3-none-any.whl.
File metadata
- Download URL: nrpylatex-1.4.0-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.8 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
786f1c8529df21ef0e6f2e3323fc8d1ef92e40151e70b5186a6052284756962d
|
|
| MD5 |
ca531b91aaf72273b881bdd86d4ec612
|
|
| BLAKE2b-256 |
46727a5d62aa8a4bd964814ef65707319ab5dbc97fabb7b216f4bb9440f842e8
|
File details
Details for the file nrpylatex-1.4.0-py2.py3-none-any.whl.
File metadata
- Download URL: nrpylatex-1.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 36.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.8 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a78943e579039c0371e90e3123afe2d35a4604c2c42fcdc857760f9e104b4a22
|
|
| MD5 |
a13b279195cbeee0ca16ef27c032dcd0
|
|
| BLAKE2b-256 |
9abcec27c8481714a73853d12fdde15b6a7321cec7a144e2df5e395f288ea491
|