Fix infinite recursion when Summing a Piecewise.

Fixes github issue #2597.
Add test for github issue #2597.