Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+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!

in General questions by (250 points)

1 Answer

+2 votes

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.

by (82.5k points)
...