Hi,

I want to do a diffrentiation w.r.t r variable of a particular expression, which i am typing below. Unfortunately i am getting some problem in the expressions. below is my code

def post_process(ex): sort_product(ex) canonicalise(ex) collect_terms(ex)

{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);

q*{a b}::Metric;
q^{a b}::InverseMetric;
A1*{a}::Depends(u,z1,z2);
A2*{a}::Depends(u,z1,z2);
A*{a}::Depends(u,r,z1,z2);
B1*{a}::Depends(u,z1,z2);
B2*{a}::Depends(u,z1,z2);
B_{a}::Depends(u,r,z1,z2);

aexp:=A*{a}=((A1*{a})/r) + ((A2*{a})/r**2);
bexp:=B*{a}=((B1*{a})/r) + ((B2*{a})/r**2);
S:=A*{a} B*{a};

substitute(S,aexp);
substitute(_,bexp);
distribute(S);
collect*factors(*);
S*($r**4$);
distribute(_);
collect*factors(*);
diff(_,$r$);

after this i am getting an output as

$2rA*{1}(DNa)B*{1}(DNa)+A*{1}(DNa)B*{2}(DNa)+A*{2}(DNa)B*{1}(DNa)$

I was expecting to get

$2rA1*{a}B1*{a}+A1*{a}B2*{a}+A2*{a}B1*{a}$

Is this just a display issue or am i doing something wrong?