WIP: zeros in products

It's surprisingly tricky to compute derivatives of product terms correctly when one of the terms is zero. It's a bit of a corner case, but still needs to be correct in case it happens to be part of an optimal solution.

Added some tests below that should pass when this is fixed.