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


When running the following example:

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


drop_weight(_, $field=4$);


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!

asked in General questions by (220 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);
zoom(_, $\epsilon Q??$);
drop_weight(_, $field=4$);

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

answered by (46.2k points)