Fixes simplification of more than two summations

Fixes #8596 

you could use temp variable before isinstance call to be more efficient