'Evaluate the derivative of the current Integral object by
differentiating under the integral sign [1], using the Fundamental
Theorem of Calculus [2] when possible.
Whenever an Integral is encountered that is equivalent to zero or
has an integrand that is independent of the variable of integration
those integrals are performed. All others are returned as Integral
instances which can be resolved with doit() (provided they are integrable).
References:
[1] http://en.wikipedia.org/wiki/Differentiation_under_the_integral_sign
[2] http://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus
Examples
>>> from sympy import Integral
>>> from sympy.abc import x, y
>>> i = Integral(x + y, y, (y, 1, x))
>>> i.diff(x)
Integral(x + y, (y, x)) + Integral(1, y, (y, 1, x))
>>> i.doit().diff(x) == i.diff(x).doit()
True
>>> i.diff(y)
0
The previous must be true since there is no y in the evaluated integral:
>>> i.free_symbols
{x}
>>> i.doit()
2*x**3/3 - x/2 - 1/6'

def _eval_derivative(self, sym):

    (f, limits) = (self.function, list(self.limits))
    limit = limits.pop((-1))
    if (len(limit) == 3):
        (x, a, b) = limit
    elif (len(limit) == 2):
        (x, b) = limit
        a = None
    else:
        a = b = None
        x = limit[0]
    if limits:
        f = self.func(f, *tuple(limits))
    def _do(f, ab):
        dab_dsym = diff(ab, sym)
        if (not dab_dsym):
            return S.Zero
        if isinstance(f, Integral):
            limits = [((x, x) if ((len(l) == 1) and (l[0] == x)) else l) for l in f.limits]
            f = self.func(f.function, *limits)
        return (f.subs(x, ab) * dab_dsym)
    rv = 0
    if (b is not None):
        rv += _do(f, b)
    if (a is not None):
        rv -= _do(f, a)
    if ((len(limit) == 1) and (sym == x)):
        arg = f
        rv += arg
    else:
        u = Dummy('u')
        arg = f.subs(x, u).diff(sym).subs(u, x)
        rv += self.func(arg, Tuple(x, a, b))
    return rv
