I have an expression like (1-xy)(1-yz) which becomes
1 - yz - xy + xyyz
. I have to apply a rule on the expanded expression to get rid of duplicate parameters in each term. The last term is filtered and the resulting expression will become
1 - yz - xy + xyz
This would be easy for 2 term expression. If it becomes, for instance 40 terms, it would be really hard for python to computer this and save the result for the next processes. I have implemented a similar manner in python and it crashes after a while. Is there any easier and smarter way to calculate such an expression and apply a rule on each term in math or python?