def _forward_mode(self, *args):
        """Forward mode differentiation for a sum"""
        # (f+g)(x) = f(x) + g(x)
        f_val, f_diff = self.f._forward_mode(*args)
        g_val, g_diff = self.g._forward_mode(*args)
        # The function value and derivative is the sum of f and g
        val = f_val + g_val
        diff = f_diff + g_diff
        return val, diff
Forward mode differentiation for a sum