Cadabra
a field-theory motivated approach to computer algebra

cdb.utils.indices

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}
\(\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})

get_indices(node: ExNode) -> List[Ex]

Return a list of all indices inside \texttt{Node
}
\partial{#}::Derivative. ex := 0 + a_{\mu} \partial_{\sigma}{b_{\mu}b_{\lambda}} \delta{p_{\rho}p^{\rho}} + g_{\sigma\lambda}g_{\kappa}g^{\kappa} = p_{\sigma}p_{\lambda}; try: get_indices(ex); except AssertionError: "Caught error"; get_indices(ex[1]);
\(\displaystyle{}a_{\mu} \partial_{\sigma}\left(b_{\mu} b_{\lambda}\right) \delta\left(p_{\rho} p^{\rho}\right)+g_{\sigma \lambda} g_{\kappa} g^{\kappa} = p_{\sigma} p_{\lambda}\)
a_{\mu} \partial_{\sigma}(b_{\mu} b_{\lambda}) \delta(p_{\rho} p^{\rho}) + g_{\sigma \lambda} g_{\kappa} g^{\kappa} = p_{\sigma} p_{\lambda}
Caught error
{}$\big[$$\sigma$, $\lambda$$\big]$

get_dummy_indices(node: ExNode) -> List[Ex]

Return a list of all dummy indices inside \texttt{Node
}
\partial{#}::Derivative. ex := a_{\mu} \partial_{\sigma}{b_{\mu}b_{\lambda}} \delta{p_{\rho}p^{\rho}}; get_dummy_indices(ex);
\(\displaystyle{}a_{\mu} \partial_{\sigma}\left(b_{\mu} b_{\lambda}\right) \delta\left(p_{\rho} p^{\rho}\right)\)
a_{\mu} \partial_{\sigma}(b_{\mu} b_{\lambda}) \delta(p_{\rho} p^{\rho})
{}$\big[$$\mu$$\big]$

get_free_indices(node: ExNode) -> List[Ex]

Return a list of all free indices inside \texttt{Node
}
\partial{#}::Derivative. ex := 0 + a_{\mu} \partial_{\sigma}{b_{\mu}b_{\lambda}} \delta{p_{\rho}p^{\rho}} + g_{\sigma\lambda}g_{\kappa}g^{\kappa} = p_{\sigma}p_{\lambda}; get_free_indices(ex);
\(\displaystyle{}a_{\mu} \partial_{\sigma}\left(b_{\mu} b_{\lambda}\right) \delta\left(p_{\rho} p^{\rho}\right)+g_{\sigma \lambda} g_{\kappa} g^{\kappa} = p_{\sigma} p_{\lambda}\)
a_{\mu} \partial_{\sigma}(b_{\mu} b_{\lambda}) \delta(p_{\rho} p^{\rho}) + g_{\sigma \lambda} g_{\kappa} g^{\kappa} = p_{\sigma} p_{\lambda}
{}$\big[$$\sigma$, $\lambda$$\big]$
Copyright © 2001-2021 Kasper Peeters
Questions? info@cadabra.science