#!/usr/bin/env cadabra2 {\mu,\nu,\rho,\sigma,\lambda,\kappa,\alpha,\beta,\gamma,\xi}::Indices. {\mu,\nu,\rho,\sigma,\lambda,\kappa,\alpha,\beta,\gamma,\xi}::Integer(0..3). \eta_{\mu\nu}::KroneckerDelta. \delta{#}::KroneckerDelta. e_{\mu\nu\lambda\rho}::EpsilonTensor(delta=\delta). J_{\mu\nu}::AntiSymmetric. J_{\mu\nu}::SelfNonCommuting. { J_{\mu\nu}, P_{\mu}, W_{\mu} }::NonCommuting. {J_{\mu\nu}, P_{\mu}, W_{\mu} }::Depends(\commutator{#}). def post_process(ex): unwrap(ex) eliminate_kronecker(ex) canonicalise(ex) rename_dummies(ex) collect_terms(ex) poincare:= { \commutator{J_{\mu\nu}}{P_{\rho}} -> \eta_{\mu\rho} P_{\nu} - \eta_{\nu\rho} P_{\mu}, \commutator{J_{\mu\nu}}{J_{\rho\sigma}} -> \eta_{\mu\rho} J_{\nu\sigma} - \eta_{\mu\sigma} J_{\nu\rho} - \eta_{\nu\rho} J_{\mu\sigma} + \eta_{\nu\sigma} J_{\mu\rho} }; Psq:= \commutator{J_{\mu\nu}}{ P_{\rho}P_{\rho} }; product_rule(_); substitute(_, poincare); distribute(_); Wsq:=\commutator{J_{\mu\nu}}{W_\mu W_\mu}; substitute(_, $W_\mu -> e_{\mu\nu\lambda\rho} P_\nu J_{\lambda\rho}$); epsilon_to_delta(_); expand_delta(_); product_rule(_); substitute(_, poincare); distribute(_);