# converting partial derivative to covariant derivative

Hi,

After a computation I ended up in expression that involves partial derivatives. I want to simplofy that to covariant derivative expression . I am expressing a prototype of the problem here

Suppose after a computation i ended up in a expression like

\begin{align} \partial_{a}A^{b} + \frac{1}{2}A^{c} q^{b d}\partial_{a} q_{d c} + \frac{1}{2} A^{c} q^{b d}\partial_{c}q_{a d} - \frac{1}{2} A^{c} q^{b d}\partial_{d}q_{a c} \end{align}

I want to simplify this to $\nabla_{a}A^{b}$. For this I used the following code

{u, r, z1 , z2}::Coordinate;
{a , b , c , d , e , f , g , h , i , j , k , l , m , n#}::Indices(values={(z1),(z2)}, position=fixed);
\partial{#}::PartialDerivative;
\nabla{#}::Derivative;
q_{a b}::Metric;
q^{a b}::InverseMetric;
q^{a}_{b}::KroneckerDelta;
q_{a}^{b}::KroneckerDelta;
q{#}::Depends(u , a , b , c , d , e , f , g , h , i , j , k , l , m , n# ,\partial{#});
\delta{#}::KroneckerDelta;
\Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2});
A_{a}::Depends(u, r , a , b , c , d , e , f , g , h , i , j , k , l , m , n#);

rule:={\partial_{a}{A^{b}} -> \nabla_{a}{A^{b}} - \Gamma^{b}_{a c} A^{c} , \partial_{a}{q_{b c}} -> \Gamma^{d}_{a b} q_{d c} + \Gamma^{d}_{a c} q_{b d}}  };

test:=\partial_{a}{A^{b}} + (1/2)*A^{c} q^{b d}\partial_{a}{q_{d c}} + (1/2)*A^{c} q^{b d}\partial_{c}{q_{a d}} - (1/2)*A^{c} q^{b d}\partial_{d}{q_{a c}};

substitute(test, rule);
distribute(test);
canonicalise(_);

But i ended up in a completely different expression . I think the issue might be that CHristoffel symbols are raised and lowered w.r.t metric. Can you please help me out to simplify such expressions.

If you want to prevent canonicalise from raising or lowering indices, declare those indices with the position=independent property (not position=fixed). That seems to work in your example.
You will still need some eliminate_metric, eliminate_kronecker and sort_product after that.