Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
0 votes

Hi Troops, The following code returns a big round Zero. Is this correct? I think it should return a list with elements like dAxx, dAxy, etc. Cheers, Leo

{a,b,c,d,e,f#}::Indices(values={x,y,z}).
{x,y,z}::Coordinate.

D_{#}::PartialDerivative.

A_{a}::Depends(D{#}).

ex := D_{a}{A_{b}};

rl1 := {A_{x}=Ax, A_{y}=Ay, A_{z}=Az}.
rl2 := {D_{x}{A_{x}}=dAxx, D_{x}{A_{y}}=dAyx, D_{x}{A_{z}}=dAzx,
        D_{y}{A_{x}}=dAxy, D_{y}{A_{y}}=dAyy, D_{y}{A_{z}}=dAzy,
        D_{z}{A_{x}}=dAxz, D_{z}{A_{y}}=dAyz, D_{z}{A_{z}}=dAzz}.

evaluate (ex,rl1+rl2)
in Bug reports by (1.8k points)

1 Answer

0 votes
 
Best answer

Known bug (though it would have been nice if you had received a warning, I agree).

The issue is that the evaluation works depth-first, so that it first replaces e.g.

D_{x}{A_{y}} -> D_{x}{ Ay }

and then at the next step it uses the fact that Ay has not been declared to depend on x to get rid of the term altogether.

These kind of things should evaluate 'in the opposite direction' but I have not yet found the time to implement that.

I thought things should work if you declare

{Ax, Ay, Az}::Depends(D{#});

and then change rl2 so that it refers to Ax instead of A_{x} and run rl2 as

evaluate(ex, rl1);
substitute(ex, rl2);

But that doesn't work, for reasons I don't know (yet).

by (82.5k points)
selected by

My workaround was to first use a substitute rule replace all partials with an ordinary symbol, e.g., $\partial{a}{A{b}} -> dA_{b a}$ then use the evaluate algorithm.That worked fine.

...