# drop_weight before distribute

+1 vote

Hi,

When running the following example:

\epsilon::Weight(label=field, value=1);

Exp:=\epsilon**4+\epsilon*(\epsilon**3+5);

drop_weight(_, $field=4$);

distribute(_);

drop_weight(_, $field=4$);


The first term between brackets is only dropped at the second occurrence of the algorithm drop_weight, i.e. once distributed - while the first term of the expression is rightly dropped at the first occurrence.

Is there a way to make drop_weight recognize it as a weighted term (of weight 4) before distributing?

Thank you for any help!

The logic here is intentional: drop_weight only acts on terms with a well-defined weight, and the $\epsilon (\epsilon^3 + 5)$ term is not of that type. So at the moment the answer is 'no'.

However, if your problem is that doing distribute is going to mess up too many other terms, you can try zooming into the expression and only distributing terms which match a certain pattern. E.g.

\epsilon::Weight(label=field, value=1);
Exp:=(A+B)*\epsilon**2+\epsilon*(\epsilon**3+5);
zoom(_, $\epsilon Q??$);
distribute(_);
unzoom(_);
drop_weight(_, $field=4$);


would produce $(A+B)\epsilon^2 + 5\epsilon$, with the brackets in the first term intact.