# Providing a Weight to a Derivative

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).
\nabla{#}::Derivative.
h_{i j}::Depends(x, y, \nabla{#}).
\delta{#}::KroneckerDelta:
\nabla{#}::Weight(label=order, value=1);


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 The zeroth order is Ok, but the first and second yield problems.

### Question

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

+1 vote

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).

answered by (48.6k 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}$.