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 --zero
... % 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.extension
In [2]: %%parse_latex
...: % ignore "\begin{align}" "\end{align}"
...: \begin{align}
...: % coord [t, r, \theta, \phi]
...: % define gDD --dim 4 --zero
...: % 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
nrpylatex-1.2.5.tar.gz
(33.3 kB
view hashes)
Built Distribution
nrpylatex-1.2.5-py3-none-any.whl
(35.3 kB
view hashes)
Close
Hashes for nrpylatex-1.2.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3c86cf0e6c3779d321b17608d1308f48ca1ca7bfe6e868388792db13fb98be7 |
|
MD5 | 60879e749456a76c128a6f2074320afb |
|
BLAKE2b-256 | e458aa5470e1121e895793b4a871140f82d5b8affe01865ef3aec488fc56bbe8 |