
it is not difficult to create very powerful and generic programs by using Python with Cadabra. In particular, we
wish to draw to the attention of the reader the following constructs which differ from other CASs and which are used
throughout this paper when constructing algorithms and performing other manipulations:
•Expressions in Cadabra are mutable which provides powerful ways to interact with them, especially by com-
bining this with Python iterator constructions which allows expressions to be visited and modified using for
loops and other intuitive constructs.
•By allowing expressions to be queried for different property types, ‘smart’ algorithms can be written which
respond differently to different types of input. Properties can also be dynamically attached to new symbols
which allows the construction of functions which programmatically define new sets of objects.
•Python has many useful and performant inbuilt containers which have rich interfaces, and also provides im-
plementations of many more useful container types such as defaultdict in the collections library. These
make storing and accessing related expressions very easy and natural which improves the organisation of the
code.
•As Cadabra uses a L
A
T
E
Xformat for inputting and outputting expressions, expressions can be created or ma-
nipulated by using Python’s string and regex functions if a feature is not implemented in Cadabra. While this
is not always an optimal solution, it is one of the great strengths of Python which makes it such a productive
language that it is almost always possible to achieve some end.
In order to showcase as many of these features as possible, we have chosen to take a more in-depth look at tensor
perturbation theory in General Relativity which is by no means the only field topic whose analysis is assisted by
using the tools Python and Cadabra offer; but as it is a very well studied topic with a lot of literature dedicated to
it we hope this makes the paper accessible to a large audience. Tensor perturbations, also known as Gravitational
Waves, are disturbances in the curvature of the spacetime metric and represent one of the most definitive theoretical
and phenomenological signatures of General Relativity as a standard theory of gravitation. Recently, gravitational
waves have attracted a wide interest thanks to the detections made by the LIGO and Virgo interferometers sourced by
compact binary coalescences [6–12].
Having taken gravitational waves as the most effective case study to examine, the main purpose of this work is
therefore to put forth the first structured insight on the approach, design, and implementation of hybrid Cadabra and
Python functions/commands and methods of defining a new coding environment within Cadabra. In particular, we
use our multi-annual experience gained in both Cadabra and Python to provide a programming vision of the entire
life-cycle of such a development process, which consists of five phases as displayed in Table 1.
Step Description Ref. Secs.
Theory Analysis, modelling, formalism, reference objects Sec. 2
Ref. libraries development Supporting functions & environments, coding core paradigms Sec. 3
Main algorithms development Code development, optimization, new user-oriented commands Sec. 4
Notebooks Explore the new environment, upgrade Cadabra, communicate Sec. 5,6,7
Testing & Discussion Timing, performance, perspectives & generalizations Sec. 8
Table 1: Steps of the development process with related reference sections of this article.
When talking about gravitational waves, methods related to Perturbation Theory are essential and Section 2is
dedicated to providing a general overview of tensorial perturbative expansions in General Relativity. In particular,
the spacetime metric representing the gravitational field is treated as a series of successive, increasingly small tensor
perturbations around a background, where an N-th order gravitational wave solution is obtained by (i) truncating the
series by keeping only the first Nterms, and (ii) forcing consistency with perturbed General Relativity equations and
gauge conditions.
Operating tensorial expansions within Cadabra naturally leads to us introducing in Section 3a set of new hybrid
Cadabra and Python functions (see Table 2) collected inside a library which we call perturbations.cnb. These
functions are united by the goal of defining the basic perturbative elements we will deal with. They fix the core
2