made deriv work with products and sums of more than 2 elements