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;
Aμνρ
A_{\mu \nu \rho}
Aμνρ
A_{\mu \nu}^{\rho}
Aμνρ
A_{\mu}^{\nu}_{\rho}
Aμνρ
A_{\mu}^{\nu \rho}
Aμνρ
A^{\mu}_{\nu \rho}
Aμνρ
A^{\mu}_{\nu}^{\rho}
Aμνρ
A^{\mu \nu}_{\rho}
Aμνρ
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(±ikλxλ)test := h_{\mu\nu} = A_{\mu\nu} \exp(i*k_\mu*x^{\mu});
test = replace_index(test,r"\exp",r'\mu',r'\alpha');
hμν=Aμνexp(ikμxμ)
h_{\mu \nu} = A_{\mu \nu} \exp(i k_{\mu} x^{\mu})
hμν=Aμνexp(ikαxα)
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]);
aμ∂σ(bμbλ)δ(pρpρ)+gσλgκgκ=pσpλ
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
{}[σ, λ]
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);
aμ∂σ(bμbλ)δ(pρpρ)
a_{\mu} \partial_{\sigma}(b_{\mu} b_{\lambda}) \delta(p_{\rho} p^{\rho})
{}[μ]
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);
aμ∂σ(bμbλ)δ(pρpρ)+gσλgκgκ=pσpλ
a_{\mu} \partial_{\sigma}(b_{\mu} b_{\lambda}) \delta(p_{\rho} p^{\rho}) + g_{\sigma \lambda} g_{\kappa} g^{\kappa} = p_{\sigma} p_{\lambda}
{}[σ, λ]
symmetrise_slots(ex: Ex, slots: list[int], antisym: bool = False)
Symmetrise
or antisymmetrise an expression in the given slots
Given an expression, iterates over all top level terms and symmetrises the indices in the
given \texttt{slots}, so that e.g. symmetrise_slots($A_{a b c}$, [0,1])
→ Aabc+Abac. For an expression containing a sum of terms,
all terms in the expression are symmetrised.ex1 := R_{a b c d}:
symmetrise_slots(ex1, [0,1], True)
symmetrise_slots(ex1, [2,3], True)
symmetrise_slots(ex1, [0,2])
symmetrise_slots(ex1, [1,3])
sort_sum(ex1);
R_{a b c d}::RiemannTensor.
ex2 := 12 R_{a b c d}:
young_project_tensor(ex2)
sort_sum(ex2);
assert ex1 == ex2
Rabcd−Rabdc−Racdb+Radcb−Rbacd+Rbadc+Rbcda−Rbdca−Rcabd+Rcbad+Rcdab−Rcdba+Rdabc−Rdbac−Rdcab+Rdcba
R_{a b c d}-R_{a b d c}-R_{a c d b} + R_{a d c b}-R_{b a c d} + R_{b a d c} + R_{b c d a}-R_{b d c a}-R_{c a b d} + R_{c b a d} + R_{c d a b}-R_{c d b a} + R_{d a b c}-R_{d b a c}-R_{d c a b} + R_{d c b a}
Rabcd−Rabdc−Racdb+Radcb−Rbacd+Rbadc+Rbcda−Rbdca−Rcabd+Rcbad+Rcdab−Rcdba+Rdabc−Rdbac−Rdcab+Rdcba
R_{a b c d}-R_{a b d c}-R_{a c d b} + R_{a d c b}-R_{b a c d} + R_{b a d c} + R_{b c d a}-R_{b d c a}-R_{c a b d} + R_{c b a d} + R_{c d a b}-R_{c d b a} + R_{d a b c}-R_{d b a c}-R_{d c a b} + R_{d c b a}