If you modify the tree, you are required to leave the tree in an internally consistent state. One of the conditions is that the multiplier of a \sum
node is not allowed to be anything except 1.
On the C++ side there are various functions in Cleanup.cc|hh
which help to turn an inconsistent tree into a consistent one, but these are not exported to Python. It should not be too hard to export these as it's all individual functions.
The reason why ex2:=@(ex)
works is that any new expression input will run the cleanup routines.
(In all honesty, apart from Dom, you are the first person I am aware of who has done some serious work like this on the Python side, so there are bound to be other missing pieces).