Cadabra and Python algorithms in General Relativity and Cosmology I Generalities

2025-04-27 0 0 411.31KB 30 页 10玖币
侵权投诉
Cadabra and Python algorithms in General Relativity and Cosmology I:
Generalities
Oscar Castillo-Felisolaa, Dominic T. Priceb,, Mattia Scomparinc
aDepartamento de F´ısica and Centro Cient´ıfico y Tecnol´ogico de Valparıso (CCTVal),
Universidad T´ecnica Federico Santa Mar´ıa
Casilla 110-V, Valpara´ıso, Chile
bDepartment of Mathematical Sciences, Durham University,
South Road, Durham DH1 3LE, United Kingdom
cVia del Grano 33,
Mogliano Veneto, Italy
Abstract
The aim of this work is to present a series of concrete examples which illustrate how the computer algebra system
Cadabra can be used to manipulate expressions appearing in General Relativity and other gravitational theories. We
highlight the way in which Cadabras philosophy diers from other systems with related functionality. The use of
various new built-in packages is discussed, and we show how such packages can also be created by end-users directly
using the notebook interface.
The current paper focuses on fairly generic applications in gravitational theories, including the use of dierential
forms, the derivation of field equations and the construction of their solutions. A follow-up paper discusses more
specific applications related to the analysis of gravitational waves [1].
Keywords: Computer Algebra System, Cadabra, Gravitation, Classical Field Theory.
1. Introduction
Algebraic manipulation of mathematical expressions is a common but tedious part of most research in physics.
Symbolic computer algebra software has been used from the early days to help with this, and many special-purpose
systems have been built to deal with expression manipulations specific to particular areas in physics. This is in
particular true for research in gravity; for a recent review of the many uses of symbolic computer algebra in this field
see Ref. [2].
Cadabra is a relatively new, free and open-source standalone computer algebra system,1which was designed from
the ground up to manipulate mathematical expressions which occur in classical and quantum field theory [36]. In
contrast to many special-purpose systems written for sometimes very specific tasks, it aims to provide a wide variety
of basic field-theory building blocks, not only to tackle gravity computations but also to provide support for things
like fermions and anti-commuting variables, algebra-valued objects, component and abstract computations, tensor
symmetries and various others. Its main philosophy is to provide a simple-to-use ‘scratchpad’ for computations in
field theory in its widest sense, to help with computations which are too tedious to do by hand, while keeping them
close in form to what those computations would look like on paper. It is programmable in Python, yet also accepts
mathematical expressions in standard L
A
T
E
X notation. It has been used in a wide variety of computations in high-energy
physics and gravity, but also in dierent fields such as nuclear physics [7].
Corresponding author
Email addresses: o.castillo.felisola@protonmail.com (Oscar Castillo-Felisola), dominicprice@outlook.com (Dominic T. Price),
mattia.scompa@gmail.com (Mattia Scomparin)
1The ocial site for Cadabra is https://cadabra.science, and the actual code is hosted at https://github.com/kpeeters/
cadabra2.
Preprint submitted to Computer Physics Communications October 4, 2022
arXiv:2210.00005v1 [gr-qc] 30 Sep 2022
Because Cadabra tries to encourage and support a work-flow which is close to how computations are done with
pencil and paper, it diers sometimes quite strongly from other computer algebra systems with a wide scope. In the
present paper, and its followup companion [1], our goal is to show how gravity computations (which will at least in
spirit be familiar to many readers) can be done with Cadabra. For a deeper look into using the system for advanced
gravity computations, see e.g. [8].
The approach of cadabra is that (geometrical) objects are first declared by assigning properties to objects, after
which they can then be manipulated with algorithms, which act according to the previously assigned properties. A
brief example is in order,
1{a,b}::NonCommuting.
2{a,b}::Distributable.
3{b}::SelfAntiCommuting.
4expr := b(a+b+ab);
5distribute(_);
b(a+b+ab)
ba +bab
In the above example aand bare the objects, and we assign the properties NonCommuting and Distributable to
them, and additionally assign the property SelfAntiCommuting to the object b. The first assignment forbids the
rearrangement of bab as ab2, while the last assignment ensures that b2=0. Notice that output is shown only when a
command ends with a semi-colon (;).
This paper is organised as follows. Section 2briefly introduces the basic concepts of General Relativity (see
Sec. 2.1) and their implementation in cadabra (see Sec. 2.2). The code in Sec. 2.2 is intended to serve as a header file,
which can be called from other cadabra notebooks in order to avoid the declaration of “standard” properties. In Sec. 3
we exemplify the manipulation of tensor expressions by writing down explicit expressions for the Lanczos–Lovelock
Lagrangians in Sec. 3.1, and their field equations in Sec. 3.2. In Sec. 4we explore the capabilities of cadabra to
manipulate dierential forms. Specifically, we obtain the Bianchi identities from the structural equations.2Next, in
Sec. 5the variational principle is exemplified by extremising the Einstein–Hilbert action.2For reasons of space, the
variation of the Lanczos–Lovelock action is not addressed in this paper. We then deal with the resolution of Einstein
field equations in Sec. 6. In Sec. 6.1 we consider the Schwarzschild spacetime, while Friedman–Robertson–Walker
cases are examined in Sec. 6.2. Some conclusions are drawn in the Sec. 7. In Appendix A we introduce a tool that
could help to improve the performance of calculations or long routines.
2. Formalism
2.1. Introduction to the formalism of General Relativity
Let us start by giving a brief reminder of the ingredients of General Relativity, both to set our conventions and
to prepare for the discussion of its properties formulated in Cadabras language. General Relativity is currently the
best model of gravitational interactions, and was proposed in 1915 by A. Einstein [9,10], as an attempt to conciliate
the concepts introduced by the special theory of relativity with those of gravitation. In his model, Einstein proposed
that the gravitational interaction is an eect of the curvature of the spacetime. Meanwhile, the matter distribution
determines how the spacetime curves. This is sometimes called the geometrisation of gravity.
Since the theory has to be invariant under general coordinate transformations, its building blocks are tensors (or
more generally tensor densities). In General Relativity the spacetime is assumed to be a pseudo-Riemannian manifold,
whose geometry is completely characterised by the metric tensor, gµν. In order for the derivative of a tensor to be a
tensor, the concept of connection (Γλµν) has to be introduced, allowing to define a covariant derivative (µ=µµ).
The condition of metricity, i.e. g=0, relates the connection (the Levi-Civita connection) to the metric and partial
derivatives of it,
Γµντ =1
2gµσ(τgνσ +νgτσ σgντ).(1)
2The content of this section is available on the user contributed notebooks section of the ocial cadabra webpage.
2
The Levi-Civita connection is symmetric in its lower indices, Γµντ = Γµτν, this property is referred as torsion-free
condition.
The action of the commutator of covariant derivatives on a vector yields an algebraic operator, dubbed the curva-
ture tensor,
[µ,ν]Vτ=RτσµνVσ,
where
Rτσµν =µΓτνσ νΓτµσ + ΓτµλΓλνσ ΓτνλΓλµσ.(2)
The curvature tensor, also known as the Riemann tensor, is skew-symmetric in the last two indices, and additionally
satisfies the algebraic and dierential Bianchi identities,
Rτσµν +Rτµνσ +Rτνσµ =0,
λRτσµν +µRτσνλ +νRτσλµ =0.
The contraction of the Riemann tensor are interesting geometrical quantities,
Rσν =Rτστν and R=gµνRµν,(3)
called the Ricci tensor and Ricci scalar (curvature) respectively.
From a physics perspective, the relevant geometrical object is the Einstein tensor,
Gµν =Rµν 1
2gµνR.(4)
The field equations of General Relativity are obtained by extremising the Einstein–Hilbert action,
S=1
2κZd4xg(R2Λ),(5)
where κis the coupling constant of gravity (inversely proportional to the gravitational Newton constant GN), Λis the
cosmological constant, and the symbol gstands for the determinant of the metric tensor.3
The interaction between matter and gravity is (formally) achieved through the minimal coupling mechanism, i.e.
starting from the action on a flat spacetime and replacing the partial derivative by covariant derivative, the Minkowski
metric by the curved metric, and the flat volume measure d4xby the invariant volume measure d4xg. Hence, to
the action in Eq. (5) one adds the matter action,
Smat =Zd4xgLmat(ψ, g,ψ).(6)
This then leads to Einstein’s equations, which set the Einstein tensor Gµν proportional to the energy-momentum tensor,
Tµν, which encodes the properties of the matter distribution.
2.2. Introduction to the formalism of Cadabra: The header.cnb library
The code presented in this article is organised as a project containing a notebook for each chapter, as well as a
separate library with two Cadabra packages which can be re-used in other computations.4The structure of the project
is depicted in figure 1.
The header.cnb notebook is included at the start of some of the notebooks and defines a set of objects and related
properties which will be used throughout the discussion of tensor perturbations in General Relativity. Providing this
structure also allows us to define a useful workflow for the follow up to this paper [1]. The purpose of this is to avoid
repetitive declarations and ensure consistency between the notebooks. As expected, the file begins by importing the
global dependencies:
3The minus sign in front of the determinant is necessary because the spacetime has a Lorentzian signature.
4The project can be downloaded from it ocial GitLab repository https://gitlab.com/cdbgr/cadabra-gravity-I.
3
PROJECT
libraries
header.cnb
timing.cnb
sec3_lanczos_lovelock.cnb
sec4_bianchi_identities.cnb
sec5_variational_principle.cnb
sec6_solution1_schw.cnb
sec6_solution2_frw.cnb
Figure 1: Organisation of notebooks discussed in the present paper.
1import sympy
2import cdb.core.manip as manip
3import cdb.core.component as comp
4import cdb.sympy.solvers as solv
The last three imports are from the Cadabra standard library [11], and provide common operations. The cdb.core.comp
library is useful for component calculations and cdb.sympy.solvers is a simple Cadabra wrapper for the equation
solvers provided in the sympy library.
Although these imports appear to be regular Python packages, they are in fact Cadabra notebooks and can be
found at <cadabra-root-dir>/lib/python3.x/site-packages/cdb. When Cadabra finds an import state-
ment, it will not only do a standard search in sys.path for Python packages, but it will also search for notebook
files, which are automatically converted into Python scripts and imported using the native functionality. Not only
does this make writing packages for Cadabra very natural, but it also makes these packages very easy to read, as
the documentation is written next to the code in L
A
T
E
X cells using the \algorithm command, and test code can be
written under the exported functions in ghost cells which are ignored when imported, similarly to how if __name__
== "__main__" statements are used in Python.
After this, the header.cnb file defines one main function init_properties, which accepts a coordinates pa-
rameter containing the range of coordinates used through the notebooks and a metrics parameter with the names of
the metric tensors required, and uses this to inject appropriate property declarations into the Cadabra kernel. It begins
by declaring the coordinates and indices used in the notebooks:
5def init_properties(*, coordinates, metrics=[$g_{\mu\nu}$], signature=-1):
6"""
7Initialise common property declarations which are shared between the
8two papers
9"""
10 @(coordinates)::Coordinate.
11 index_list := {\mu,\nu,\rho,\sigma,\alpha,\beta,\gamma,\tau,\chi,\psi,\lambda,\lambda#}.
12 @(index_list)::Indices(position=independent, values=@(coordinates)).
13 Integer(index_list, Ex(rf"1..{len(coordinates)}"))
The use of the pull-in syntax @(...) allows us to use Cadabra expressions inside other expressions, similarly to
how curly brackets are used in Python strings to include other objects (e.g. 'This is some {}'.format('text')).
As the ::Property syntax expects a Cadabra expression on the left hand side, not a variable name, we use it here to
declare properties on these expressions which are not hard-coded. As well as assigning the Indices property to our
index list, we also assign the Integer property which makes the number of coordinates countable, allowing functions
like eliminate_kronecker which makes the substitution δµ
µDto work. One final thing to note is the #, which
declares an infinite set of labelled indices (i.e. \lambda1,\lambda2) which is useful to ensure that spare indices are
always available (useful when running code in loops and when doing higher perturbative orders of a computation, for
which it is not always easy to estimate how many dummy indices will be required).
The function then associates the relevant properties to the metrics defined in the metrics parameter:
15 sig = Ex(signature)
4
16 for metric in metrics:
17 # Both lower indices: Metric
18 for index in metric.top().indices():
19 index.parent_rel = parent_rel_t.sub
20 @(metric)::Metric(signature=@(sig)).
21
22 # Both upper indices: InverseMetric
23 for index in metric.top().indices():
24 index.parent_rel = parent_rel_t.super
25 @(metric)::InverseMetric(signature=@(sig)).
26
27 # Mixed indices: KroneckerDelta
28 for index in metric.top().indices():
29 index.parent_rel = parent_rel_t.sub
30 @(metric)::KroneckerDelta.
31 index.parent_rel = parent_rel_t.super
Here the for loops act over the two indices of the metric, lowering them for the Metric declaration and raising them
for the InverseMetric declaration. Note that the (1,1) forms of the metric tensor (e.g. gµν) must be declared as
KroneckerDelta. After this some standard symbols are defined
33 # Symbols
34 i::ImaginaryI.
35 \delta{#}::KroneckerDelta.
36 \partial{#}::PartialDerivative.
37 \nabla{#}::Derivative.
38 d{#}::Derivative.
Finally, we introduce some of the standard GR objects. For each one, multiple properties must be defined—we
begin by assigning a Cadabra identifier to each one and assigning a LaTeXForm to it which controls how it will
be rendered in L
A
T
E
X. The symmetries and dependencies of each are then defined; as Cadabra makes very few
assumptions about the objects one uses any dependence on derivatives must be explicitly stated.
40 # LaTeX Typography
41 ch{#}::LaTeXForm("\Gamma").
42 {rm{#},rc{#},sc}::LaTeXForm("R").
43 ei{#}::LaTeXForm("G").
44 Lmb{#}::LaTeXForm("\Lambda").
45
46 # Symmetries
47 ch^{\rho}_{\mu\nu}::TableauSymmetry(shape={2},indices={1,2}).
48 rm^{\rho}_{\sigma\mu\nu}::TableauSymmetry(shape={1,1}, indices={2,3}).
49 rc_{\mu\nu}::Symmetric.
50 ei_{\mu\nu}::Symmetric.
This completes the init_properties function, and the remainder of the header.cnb file are some algebraic
definitions of the GR objects that are used throughout the notebooks, allowing them to be substituted for each other.
One can check the sanity of the definition with a few testing lines,
init_properties(coordinates=$t,x,y,z$, metrics=[$g_{\mu\nu}$, $\eta_{\mu\nu}$])
# Test that properties are declared correctly
assert eliminate_metric($g_{\mu\rho}x^{\rho\nu}$) == $x_{\mu}^{\nu}$
assert eliminate_kronecker($g_{\mu}^{\rho}x_{\rho\nu}$) == $x_{\mu\nu}$
assert eliminate_kronecker($\eta^{\mu}_{\mu}$) == $4$
assert eliminate_kronecker($g_{\mu}^{\mu}$) == $4$
As some of them depend on definitions of symbols as derivatives in order for index consistency to be main-
tained, they are defined as functions returning expression objects so that they are only parsed when called (after
init_properties has been invoked) and not during import where they would raise a parsing error
58 def ch():
59 return $ch^{\mu}_{\nu\tau} = \frac{1}{2} g^{\mu\sigma} (\partial_{\tau}{g_{\nu\sigma}} + \partial_{\
nu}{g_{\tau\sigma}} - \partial_{\sigma}{g_{\nu\tau}})$
5
摘要:

CadabraandPythonalgorithmsinGeneralRelativityandCosmologyI:GeneralitiesOscarCastillo-Felisolaa,DominicT.Priceb,,MattiaScomparincaDepartamentodeF´sicaandCentroCient´coyTecnol´ogicodeValpara´so(CCTVal),UniversidadT´ecnicaFedericoSantaMar´aCasilla110-V,Valpara´so,ChilebDepartmentofMathematicalSc...

展开>> 收起<<
Cadabra and Python algorithms in General Relativity and Cosmology I Generalities.pdf

共30页,预览5页

还剩页未读, 继续阅读

声明:本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。玖贝云文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知玖贝云文库,我们立即给予删除!
分类:图书资源 价格:10玖币 属性:30 页 大小:411.31KB 格式:PDF 时间:2025-04-27

开通VIP享超值会员特权

  • 多端同步记录
  • 高速下载文档
  • 免费文档工具
  • 分享文档赚钱
  • 每日登录抽奖
  • 优质衍生服务
/ 30
客服
关注