ricci
{ricci} provides a compact R interface for performing tensor calculations. This is achieved by allowing (upper and lower) index labeling of R’s array and making use of Ricci calculus conventions.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (18.4%) to scientific vocabulary
Keywords
calculus
covariant
derivative
r
ricci
tensor
Last synced: 6 months ago
·
JSON representation
Repository
{ricci} provides a compact R interface for performing tensor calculations. This is achieved by allowing (upper and lower) index labeling of R’s array and making use of Ricci calculus conventions.
Basic Info
- Host: GitHub
- Owner: lschneiderbauer
- License: gpl-3.0
- Language: R
- Default Branch: main
- Homepage: https://lschneiderbauer.github.io/ricci/
- Size: 2.31 MB
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
- Releases: 1
Topics
calculus
covariant
derivative
r
ricci
tensor
Created 8 months ago
· Last pushed 6 months ago
Metadata Files
Readme
Changelog
License
README.Rmd
---
output: github_document
bibliography: references.bib
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ricci
[](https://github.com/lschneiderbauer/ricci/actions/workflows/R-CMD-check.yaml) [](https://app.codecov.io/gh/lschneiderbauer/ricci) [](https://CRAN.R-project.org/package=ricci) [](https://lifecycle.r-lib.org/articles/stages.html#experimental)
The goal of {ricci} is to provide a *compact*[^1] R interface for performing [tensor calculations](https://en.wikipedia.org/wiki/Ricci_calculus). This is achieved by allowing (upper and lower) index labeling of R’s `array` and making use of Ricci calculus conventions to *implicitly* trigger **contractions** and diagonal subsetting. Explicit tensor operations, such as **addition, subtraction and multiplication of tensors** via the standard operators (`*`, `+`, `-`, `/`, `==`), **raising and lowering indices**, taking **symmetric** or **antisymmetric tensor parts**, as well as the **Kronecker product** are available. Common tensors like the Kronecker delta, Levi Civita epsilon, certain metric tensors, the Christoffel symbols, the Riemann as well as Ricci tensors are provided. The **covariant derivative** of tensor fields with respect to any metric tensor can be evaluated. An effort was made to provide the user with useful error messages.
[^1]: By compact interface, we mean an interface that is concise and non-verbose. The author is of the opinion that the less we need to write in order to express an intent, the less likely are we to make mistakes.
{ricci} uses the [calculus](https://calculus.eguidotti.com/) package [@guidotti2022] behind the scenes to perform calculations and provides an alternative interface to a subset of its functionality. {[calculus](https://calculus.eguidotti.com/)} supports symbolic calculations, allowing {ricci} to support it as well. Symbolic expressions are optionally simplified if the [Ryacas](https://r-cas.github.io/ryacas/) package is installed.
## Installation
You can install the latest CRAN release of ricci with:
``` r
install.packages("ricci")
```
Alternatively, you can install the development version of ricci from [GitHub](https://github.com/) with:
``` r
# install.packages("pak")
pak::pak("lschneiderbauer/ricci")
```
## Example
The central object is R's `array`. Adding index slot labels allows us to perform common tensor operations implicitly. After the desired calculations have been carried out we can remove the labels to obtain an ordinary `array`.
The following (admittedly very artificial) example shows how to express the contraction of two tensors, and subsequent symmetrization and diagonal subsetting. For demonstration purposes we use an arbitrary array of rank 3.
```{r example_num}
library(ricci)
# numeric data
a <- array(1:(2^3), dim = c(2, 2, 2))
# create labeled array (tensor)
(a %_% .(i, j, k) *
# mutliply with a labeled array (tensor) and raise index i and k
a %_% .(i, l, k) |> r(i, k, g = g_mink_cart(2))) |>
# * -i and +i as well as -k and +k dimension are implictely contracted
# the result is a tensor of rank 2
sym(j, l) |> # symmetrize over i and l
subst(l -> j) |> # rename index and trigger diagonal subsetting
as_a(j) # we unlabel the tensor with index order (j)
```
The same instructions work for a symbolic array:
```{r example_symb}
# enable optional simplfying procedures
# (takes a toll on performance)
options(ricci.auto_simplify = TRUE)
# symbolic data
a <- array(paste0("a", 1:(2^3)), dim = c(2, 2, 2))
(a %_% .(i, j, k) *
# mutliply with a labeled array (tensor) and raise index i and k
a %_% .(i, l, k) |> r(i, k, g = g_mink_cart(2))) |>
# * -i and +i as well as -k and +k dimension are implictely contracted
# the result is a tensor of rank 2
sym(j, l) |> # symmetrize over i and l
subst(l -> j) |> # rename index and trigger diagonal subsetting
as_a(j) # we unlabel the tensor with index order (j)
```
Another main feature is the covariant derivative of symbolic arrays. The following examples calculate the Hessian matrix as well as the Laplacian of the scalar function $\sin(r)$ in spherical coordinates in three dimensions.
$$D_{ik} = \nabla_i \nabla_k \sin(r)$$
```{r covd}
covd("sin(r)", .(i, k), g = g_eucl_sph(3)) |>
simplify()
```
$$\Delta \sin(r) = \nabla_i \nabla^i \sin(r)$$
```{r covd2}
covd("sin(r)", .(i, +i), g = g_eucl_sph(3)) |>
simplify()
```
The covariant derivative can not only be taken from scalars, but general indexed tensors, as the following example, involving the curl of $a$, shows.
$$\left(\nabla \times a\right)^i = \varepsilon^{i}_{\;jk} \nabla^j a^k$$
```{r covd3}
g <- g_eucl_sph(3)
a <- c(0, 1, 0)
(a %_% .(+k) |> covd(.(+j), g = g) *
e(i, j, k) |> r(i, g = g)) |>
simplify()
```
For more details, see `vignette("ricci", package = "ricci")`. For more information about how to use tensor fields and the covariant derivative, see `vignette("tensor_fields", package = "ricci")`.
Owner
- Name: Lukas Schneiderbauer
- Login: lschneiderbauer
- Kind: user
- Location: Vienna, Austria
- Repositories: 8
- Profile: https://github.com/lschneiderbauer
GitHub Events
Total
- Create event: 1
- Release event: 1
- Issues event: 2
- Push event: 52
Last Year
- Create event: 1
- Release event: 1
- Issues event: 2
- Push event: 52
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 1
- Total pull requests: 0
- Average time to close issues: about 1 month
- Average time to close pull requests: N/A
- Total issue authors: 1
- Total pull request authors: 0
- Average comments per issue: 0.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: about 1 month
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 0.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- lschneiderbauer (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
- Total maintainers: 1
cran.r-project.org: ricci
Ricci Calculus
- Homepage: https://github.com/lschneiderbauer/ricci
- Documentation: http://cran.r-project.org/web/packages/ricci/ricci.pdf
- License: GPL (≥ 3)
-
Latest release: 0.1.1
published 6 months ago
Rankings
Dependent packages count: 25.6%
Forks count: 29.0%
Dependent repos count: 31.4%
Stargazers count: 37.4%
Average: 41.7%
Downloads: 85.3%
Maintainers (1)
Last synced:
6 months ago
Dependencies
.github/workflows/R-CMD-check.yaml
actions
- actions/checkout v4 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml
actions
- JamesIves/github-pages-deploy-action v4.5.0 composite
- actions/checkout v4 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml
actions
- actions/checkout v4 composite
- actions/upload-artifact v4 composite
- codecov/codecov-action v5 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION
cran
- calculus * imports
- rlang * imports
- knitr * suggests
- rmarkdown * suggests
- testthat >= 3.0.0 suggests
- waldo * suggests