a field-theory motivated approach to computer algebra


Additional functionality to deal with indices

all_index_positions(ex: ExNode) -> Generator[Ex]

Generate all possible combinations of covariant and contravariant indices
ex := A_{\mu \nu \rho}. for var in all_index_positions(ex): var;
\(\displaystyle{}A_{\mu \nu \rho}\)
A_{\mu \nu \rho}
\(\displaystyle{}A_{\mu \nu \rho}\)
A_{\mu \nu \rho}
\(\displaystyle{}A_{\mu \nu}\,^{\rho}\)
A_{\mu \nu}^{\rho}
\(\displaystyle{}A_{\mu}\,^{\nu \rho}\)
A_{\mu}^{\nu \rho}
\(\displaystyle{}A^{\mu}\,_{\nu \rho}\)
A^{\mu}_{\nu \rho}
\(\displaystyle{}A^{\mu \nu}\,_{\rho}\)
A^{\mu \nu}_{\rho}
\(\displaystyle{}A^{\mu \nu \rho}\)
A^{\mu \nu \rho}

replace_index(ex: Ex, top_name: str, old_index: str, new_index: str) -> Ex

Rename indices
Renames with \texttt{new_index} all occurences of indices named \texttt{old_index} in any subtree whose top node is named \texttt{top_name} \textbf{Note:} This is useful for avoiding triple index-repeated errors due to the presence of tensor idnices in the argument of the exponential function i.e. $\exp(\pm i k_\lambda x^\lambda)$
test := h_{\mu\nu} = A_{\mu\nu} \exp(i*k_\mu*x^{\mu}); test = replace_index(test,r"\exp",r'\mu',r'\alpha');
\(\displaystyle{}h_{\mu \nu} = A_{\mu \nu} \exp\left(i k_{\mu} x^{\mu}\right)\)
h_{\mu \nu} = A_{\mu \nu} \exp(i k_{\mu} x^{\mu})
\(\displaystyle{}h_{\mu \nu} = A_{\mu \nu} \exp\left(i k_{\alpha} x^{\alpha}\right)\)
h_{\mu \nu} = A_{\mu \nu} \exp(i k_{\alpha} x^{\alpha})
Copyright © 2001-2021 Kasper Peeters