Applying the chain rule and product rule