Cadabra
a field theory motivated approach to computer algebra

# substitute

Generic substitution algorithm.
Generic substitution algorithm. Takes a rule or a set of rules according to which an expression should be modified. If more than one rule is given, it tries each rule in turn, until the first working one is encountered, after which it continues with the next node.
ex:=G_{\mu \nu \rho} + F_{\mu \nu \rho}; substitute(_, $F_{\mu \nu \rho} -> A_{\mu \nu} B_{\rho}$ );
$$\displaystyle{}G_{\mu \nu \rho}+F_{\mu \nu \rho}$$
$$\displaystyle{}G_{\mu \nu \rho}+A_{\mu \nu} B_{\rho}$$
ex:= A_{\mu \nu} B_{\nu \rho} C_{\rho \sigma}; substitute(_, $A_{m n} C_{p q} -> D_{m q}$ );
$$\displaystyle{}A_{\mu \nu} B_{\nu \rho} C_{\rho \sigma}$$
$$\displaystyle{}D_{\mu \sigma} B_{\nu \rho}$$
This command takes full care of dummy index relabelling, as the following example shows:
{m,n,q,r,s,t,u}::Indices(vector). ex:= a_{m} b_{n};
$$\displaystyle{}a_{m} b_{n}$$
substitute(_, $a_{q} -> c_{m n} d_{m n q}$ );
$$\displaystyle{}c_{q r} d_{q r m} b_{n}$$
By postfixing a name with a question mark, it becomes a pattern. You do not need this for indices (as the examples above show) but it is necessary for other types of function arguments.
ex:= \sin{ x }**2 + 3 + \cos{ x }**2; substitute(ex, $\sin{A?}**2 + \cos{A?}**2 = 1$);
$$\displaystyle{}\sin{x}^{2}+3+\cos{x}^{2}$$
$$\displaystyle{}4$$
Copyright © 2001-2017 Kasper Peeters
Questions? info@cadabra.science