# How to sort by upper and lower indices? [closed]

Hi,

I have expressions like these

\gamma_{\alpha \gamma} \gamma_{\beta \delta} \gamma^{\epsilon \zeta} \partial_{\epsilon \zeta}(U^{\alpha \beta}) dU^{\gamma \delta} +
\gamma_{\alpha \gamma} \gamma^{\delta \epsilon} \gamma_{\beta \zeta} \partial_{\delta \epsilon}(U^{\alpha \beta}) dU^{\gamma \zeta} +
\gamma^{\gamma \delta} \gamma_{\alpha \epsilon} \gamma_{\beta \zeta} \partial_{\gamma \delta}(U^{\alpha \beta}) dU^{\epsilon \zeta}


Which don't simplify properly, which is because the summands don't canonicalize properly. It would be solved by sorting \gamma^{..} before \gamma_{..} (or vice versa) and then relabelling the indices. I just can't figure out how to do this. Can I declare a SortOrder for this?

(Please feel free to edit my question such that the formulas are displayed with LaTeX, I couldn't figure out how to do that.)

closed with the note: See answer
closed

This depends on how you have declared your indices. Can you post a complete example, or email a notebook to info@cadabra.science ?

Sure:

{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z#}::Indices(fourD, position=independent){a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z#}::Integer(0..3)
{\alpha,\beta,\gamma,\delta,\epsilon,\zeta,\theta,\iota,\kappa,\lambda,\mu,\nu,\rho,\sigma,\tau#}::Indices(threeD, position=independent, parent=fourD)
\gamma_{\alpha \beta}::Symmetric()
\gamma^{\alpha \beta}::Symmetric()
U^{\alpha \beta}::Symmetric()
dU^{\alpha \beta}::Symmetric()
\partial{#}::PartialDerivative()
U{#}::Depends(\partial{#})
dU{#}::Depends(\partial{#})
ex := \gamma_{\alpha \gamma} \gamma_{\beta \delta} \gamma^{\epsilon \zeta} \partial_{\epsilon \zeta}(U^{\alpha \beta}) dU^{\gamma \delta} + \gamma_{\alpha \gamma} \gamma^{\delta \epsilon} \gamma_{\beta \zeta} \partial_{\delta \epsilon}(U^{\alpha \beta}) dU^{\gamma \zeta} + \gamma^{\gamma \delta} \gamma_{\alpha \epsilon} \gamma_{\beta \zeta} \partial_{\gamma \delta}(U^{\alpha \beta}) dU^{\epsilon \zeta};


{\gamma_{p? q?},\gamma^{p? q?}}::SortOrder()

It should have worked with indices declared position=fixed and then using canonicalise and rename_dummies. Don't see why it does not, may be a bug somewhere.