Cadabra

Reference manual

Every algorithm, property and package function has a manual page with examples; in the Cadabra notebook interface you can also press F1 with the cursor on a name. These pages are to-the-point; for the big picture, start with the tutorials or the Cadabra book.

Algorithms

Functions which transform an expression in place, e.g. canonicalise(ex).

Expanding

distribute
Distribute factors over sums.
expand
Write out products of objects with implicit indices.
expand_power
Expand powers into repeated products
expand_delta
Expand generalised Kronecker delta symbols
expand_dummies
Expand contracted dummy index pairs
product_rule
Apply the Leibnitz rule to a derivative of a product
unwrap
Move objects out of derivatives, accents or exterior products.
explicit_indices
Make indices explicit on an expression with implicit indices.

Simplifying and canonical form

canonicalise
Bring a tensorial expression to canonical form by re-ordering indices.
collect_terms
Collect identical terms in a sum.
collect_factors
Collect identical factors in a product.
meld
Combine terms when allowed by symmetries.
sort_product
Sort factors in a product
sort_sum
Sort terms in a sum.
factor_in
Collect terms in a sum that differ only by given pre-factors.
factor_out
Isolate common factors in a sum of products
simplify
Simplify the scalar part of an expression.
reduce_delta
Simplify a self-contracted generalised delta.
eliminate_kronecker
Eliminate Kronecker delta symbols.

Substitution and selecting subexpressions

substitute
Generic substitution algorithm.
complete
Complete a set of substitution rules to cover related objects.
zoom
Only show selected terms in a sum, and restrict subsequent algorithms to these terms.
take_match
Select a subset of terms in a sum for further computations.
replace_match
Put the result of a sub-computation back into the original expression
keep_weight
Keep terms with indicated weight
drop_weight
Drop terms with given weight
vary
Generic variation algorithm for functional derivatives.
integrate_by_parts
Integrate by parts away from the indicated expression

Indices and metrics

einsteinify
Raise or lower indices of pairs which are both upper or lower.
eliminate_metric
Eliminate metrics by raising or lowering indices.
eliminate_vielbein
Eliminates vielbein objects.
rewrite_indices
Rewrite indices by contracting with vielbein or metric.
lower_free_indices
Make all free indices in an expression subscripts.
raise_free_indices
Make all free indices in an expression superscripts.
rename_dummies
Rename dummy indices, within a set or from one set to another.
split_index
Split the range of an index into two subsets
epsilon_to_delta
Replace a product of two epsilon tensors with a generalised delta

Symmetrisation and Young tableaux

asym
Anti-symmetrise or symmetrise an expression in indicated indices or arguments
slot_asym
Anti-symmetrise or symmetrise an expression in indicated index slots
young_project_tensor
Project tensors with their Young projector.
young_project_product
Project all tensors in a product with their Young tableau projector.
decompose
Decompose a tensor monomial on a given basis of monomials.
decompose_product
Decompose a product of tensors by using Young projectors.
lr_tensor
Compute the tensor product of two Young tableaux

Spinors and gamma matrices

fierz
Perform a Fierz transformation on a product of four spinors
join_gamma
Work out the product of two generalised Dirac gamma matrices.
split_gamma
Split a Dirac gamma matrix off a generalised product of gamma matrices.
sort_spinors
Sort Majorana spinor bilinears
expand_diracbar
Simplify the Dirac bar of a composite object.
combine
Combine two consecutive indexbracket objects
untrace
Take objects out of traces

Components, numerics and SymPy

evaluate
Evaluate components of a tensor expression.
nevaluate
Numerically evaluate an expression.
nval
Numerically evaluate expressions
ndsolve
Numerically solve ordinary differential equations
map_sympy
Map Sympy algorithms to Cadabra expressions

Properties

Declarations which tell Cadabra what kind of object a symbol is, e.g. A_{m n}::Symmetric.

Symbols and indices

Indices
Declare names to be used as indices.
Symbol
Make an object not count as index when it is a sub- or super-script
Coordinate
Declare a symbol to be a coordinate label.
Integer
Indicates that an object takes integer values.
LaTeXForm
Changes the way in which expressions are displayed.
Accent
Turn a symbol into an accent.
ImplicitIndex
Indicates that an object carries indices which are not written out.
IndexInherit
Make an object inherit all indices from its child objects.
Depends
Makes an object implicitly dependent on other objects.
Weight
Attach a labelled weight to an object
WeightInherit
Make object inherit weights from child nodes

Symmetries

Symmetric
Make an object symmetric in all indices.
AntiSymmetric
Make an object anti-symmetric in all indices.
DAntiSymmetric
Gives object the symmetries of the derivative of a fully antisymmetric tensor.
TableauSymmetry
Gives a tensor a generic Young tableau symmetry.
Tableau
A Young-tableau object with unlabelled boxes.
FilledTableau
A Young-tableau object with labelled boxes.
SatisfiesBianchi
Make an object satisfy the generalised Bianchi identity.
Diagonal
Declares a tensor to only have non-zero diagonal entries.

Commutation and ordering

Commuting
Make components commuting.
AntiCommuting
Make objects anti-commuting.
NonCommuting
Makes components non-commuting.
SelfCommuting
Make tensor components commute.
SelfAntiCommuting
Make components of tensors anti-commute.
SelfNonCommuting
Make tensor components non-commuting.
CommutingAsProduct
Makes an object behave as a product when commuting.
CommutingAsSum
Makes an object behave as a sum when commuting.
SortOrder
Set sorting order of objects.

Metrics and special tensors

Metric
Makes a two-tensor a metric.
InverseMetric
Make a two-tensor an inverse metric.
KroneckerDelta
Turns an object into a generalised Kronecker delta symbol.
EpsilonTensor
A fully anti-symmetric tensor with constant components.
RiemannTensor
Make an object a Riemann curvature tensor.
Determinant
Declares an object to be the determinant of a matrix or metric.
Vielbein
Makes a two-index object a vielbein.
InverseVielbein
Makes a two-index object an inverse vielbein.
Trace
Declares a trace operator

Derivatives and operators

Derivative
Declare an operator to satisfy the Leibnitz rule.
PartialDerivative
Makes an object a partial derivative.
Distributable
Make an operator distributable over its arguments.

Spinors

Spinor
Declares an object to transform as a spinor.
DiracBar
An accent representing the Dirac conjugation operation.
GammaMatrix
A generalised generator of a Clifford algebra.

Packages

Add-on functionality, imported in the usual Python way.

cdb.core.component

Simple access to component expressions

from cdb.core.component import *
get_component
Extract a single component from an expression.
remove_zero_components
Remove all components of an expression that are equal to zero.
components_to_subrule
Turn a component expression into a set of substitution rules

cdb.core.manip

Manipulating equations, inequalities and similar expressions

from cdb.core.manip import *
eq_to_subrule
Create substitution rule from an equation.
multiply_through
Multiply all terms by the same factor.
add_through
Add a factor to both sides of an equation.
apply_through
Apply an operator through both sides of an equation.
get_lhs
Return left-hand side of an expression
get_rhs
Return right-hand side of an expression
swap_sides
Swap the left and right-hand sides of an expression.
get_factor
Get all multiplicative factors of term in node
get_basis_component
Returns the multiplicative coefficients of basis in ex
to_rhs
Move the indicated term of the expression to the right-hand side.
to_lhs
Move the indicated term of the expression to the left-hand side.
isolate
Isolates a term on the left hand side of an equation or inequality

cdb.core.trace

Manipulating Trace objects

from cdb.core.trace import *
combine_traces
Combine separate trace nodes into one sum.

cdb.core.trigrat

Canonical simplification of expressions in sines and cosines

from cdb.core.trigrat import *
trigrat
Bring sines and cosines into canonical form.
trigrat_sympy
Canonical form of a Sympy expression in sines and cosines.

cdb.graphics.plot

Plotting of functions

from cdb.graphics.plot import *
plot
Plot a function of one variable given the range.
parametric_plot
Plot pairs of functions against each other.
plot3d
Plot a function of two variables given their ranges.

cdb.numeric.evaluate

Numeric evaluation of Cadabra expressions

from cdb.numeric.evaluate import *
evalf
Evaluate an expression to a floating point number
lambdify
Create a Python function which evaluates an expression with the given parameters

cdb.relativity.abstract

Core general relativity package, mainly a library of various standard expressions.

from cdb.relativity.abstract import *
riemann_from_christoffel
Generates an equality which determines the Riemann tensor in terms of the Christoffel symbols.
christoffel_from_metric
Generates an equality which determines the Christoffel symbols in terms of the metric.
riemann_to_ricci
Convert contractions of Riemann tensors to Ricci tensors or scalars.

cdb.sympy.calculus

Use SymPy calculus functionality on Cadabra expressions.

from cdb.sympy.calculus import *
diff
Differentiate an expression with respect to one or more variables.
integrate
Integrate a definite or indefinite integral.
limit
Take the limit of an expression.
series
Construct a Taylor series.
factor
Factorise an expression

cdb.sympy.solvers

Access to Sympy solver functions.

from cdb.sympy.solvers import *
dsolve
Solve (system of) ordinary differential equation(s).
linsolve
Solve a linear system for unknowns.
nonlinsolve
Solve a system of non-linear equations.
solve
Solve an equation or system of equations.

cdb.utils.develop

Helper functions to aid development, debugging and testing

from cdb.utils.develop import *
Algorithm
Base class for user defined tree-traversal algorithms
algo
Decorator for creating tree-traversal algorithms
time_algo
Simple function to time the execution of an algorithm with given inputs.
CadabraTestError
Exception derived from AssertionError raised by testing functions when an assertion fails
test_algo
Decorator to aid defining unit tests for algorithms.
inherit_kernel
Find a kernel in the stack.

cdb.utils.indices

Additional functionality to deal with indices

from cdb.utils.indices import *
all_index_positions
Generate all possible combinations of covariant and contravariant indices
replace_index
Rename indices
get_indices
Return a list of all indices inside the given node
get_dummy_indices
Return a list of all dummy indices inside the given node
get_free_indices
Return a list of all free indices inside the given node
symmetrise_slots
Symmetrise or antisymmetrise an expression in the given slots

cdb.utils.node

Helper functions for working with ExNode objects

from cdb.utils.node import *
n_indices
Return the number of first-level indices a node has
nth_index
Gets the nth index of an ExNode object
n_args
Returns the number of first-level arguments a node has
nth_arg
Gets the nth first-level argument of an ExNode object
arg_tuple
Returns a tuple containing the first n arguments of an ExNode object
n_children
Returns the number of first-level children a node has
nth_child
Gets the nth first-level child of an ExNode object
child_tuple
Returns a tuple containing the first n children of an ExNode object
empty_sum
Returns an Ex object with just one sum node with no children
empty_product
Returns an Ex object with just one product node with no children

cdb.utils.types

Determining semantic properties of nodes

from cdb.utils.types import *
is_relational_operator
Returns True for $=$, $<$ and $>$ nodes
is_relational_expression
Returns True for expressions which contain a top node which is a relational operator and exactly two children

A–Z index

Z zoom