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

I tried to isolate terms with a certain order of derivation by defining a Weight property to the derivative.

(x, y)::Coordinate.
(i, j)::Indices(values={x, y}, position=fixed).
h_{i j}::Depends(x, y, \nabla{#}).
\nabla{#}::Weight(label=order, value=1);
\nabla{#}::WeightInherit(label=order, type=additive);

Then, a test expression

test := A \delta_{i j} + h_{i j} 
+ \nabla_{x}{h_{i j}} 
+ B \nabla_{y}{h_{i j}} 
+ C \nabla_{x}{ \nabla_{y}{ h_{i j} } } 
+ \nabla_{x}{ \nabla_{x}{ h_{i j} } };

Finally, I'd like to define terms with a certain order on derivatives,

term0 := @(test).
keep_weight(_, $order=0$);
term1 := @(test).
keep_weight(_, $order=1$);
term2 := @(test).
keep_weight(_, $order=2$);

It results in the following

The zeroth order is Ok, but the first and second yield problems.


What is the right way (if any) of providing Weight to a derivative operator?

P.D.: The same occurs with the PartialDerivative or by changing the WeightInherit type to multiplicative.

related to an answer for: Extending zoom() function
in Feature requests by (9.7k points)

1 Answer

+1 vote
Best answer

If you want a derivative to inherit a weight and have a weight of that same type itself, you need to use the self parameter to WeightInherit. So

\nabla{#}::WeightInherit(label=order, self=1, type=multiplicative);

(and drop the Weight property). The type should be multiplicative, which is a confusing way to say that the weights of the child node of the derivative should be combined as if they had been sitting in a product, that is, they should be added up.

(type=additive means that the weights of the children are handled as if the children are sitting in a sum, that is, they should all be equal).

by (70.8k points)
selected by

Thank you for the answer @kasper. I have notice, however, that the solution does not work properly when the derivative is a PartialDerivative. I assume that is due to the fact that higher order partial derivatives are denoted as $\partial{xy}$ or $\partial{xx}$.