Wolfram Computation Meets Knowledge

Mathematica Q&A Series: Surprises in Differentiation and Integration

Got questions about Mathematica? The Wolfram Blog has answers! We’ll regularly answer selected questions from users around the web. You can submit your question directly to the Q&A Team.

This week’s question comes from Kutha, a math lecturer:

Why doesn’t differentiating after integrating always return the original function?

Read below or watch this screencast for the answer (we recommend viewing it in full-screen mode):

The derivative of a definite integral with respect to its upper bound (with a constant lower bound) is equal to the integrand:

D[Integrate[Sin[t], {t, 0, x}], x]


This is a consequence of the fundamental theorem of calculus. (Note that sin(x) is equivalent to sin(t) up to renaming of the variable x or t.)

In complicated cases, it can appear that Mathematica is not giving back the original function:

D[Integrate[Sin[t^3], {t, 0, x}], x]

Result of D[Integrate[Sin[t^3], {t, 0, x}], x]

However, this result is mathematically equivalent to the integrand sin(x3). You can often discover this fact by using Simplify or FullSimplify:



That won’t necessarily work if you didn’t give the original integrand in its simplest form:

f[x_]: = 2 Sin[x^3] Cos[x^3]

result = D[Integrate[f[t], {t, 0, x}], x]

integrand sin(x^3)

Here, the simplified result is different from the integrand:



In this case, you can try simplifying the integrand as well as the result:

{FullSimplify[f[x]], FullSimplify[result]}

{Sin[2x^3], Sin[2x^3^]}

Or take the easiest option and ask Mathematica to try to prove they are equal:

FullSimplify[f[x] = result]


Another calculus-related question concerns differentiation followed by indefinite integration. For this sequence of operations, the result is not necessarily mathematically equivalent to the original function, since an arbitrary constant of integration may be added (or subtracted):

Integrate[D[x^2 + 5, x], x]


In this case, it’s obvious that the original function and the result differ by the constant 5. In more complicated cases, it may not be immediately obvious what the differing constant of integration is:

Integrate[D[Sin[x]^2, x], x]


Once again, you can use Simplify or FullSimplify to discover the difference:

Simplify[-(1/2)Cos[2x] - Sin[x]^2]


For functions with branch cut discontinuities, indefinite integrals can be trickier:

Integrate[D[Log[-x], x], x]


Here, since log(x) and log(-x) have different branch cuts (from -∞ to 0 and from 0 to ∞, respectively), a consistent constant of integration isn’t possible. Instead, you get a “piecewise” constant of integration.

In the top half of the complex plane, log(x) and log(-x) differ by the constant i π:

FullSimplify[Log[x] - Log[-x], Im[x] > 0]


While in the bottom half, they differ by –i π:

FullSimplify[Log[x] - Log[-x], Im[x] < 0]


You can avoid ambiguities related to branch cuts by specifying a definite integral from some point in the complex plane:

Integrate[D[Log[-t], t], {t, 1, z}]

ConditionalExpression[Log[z], Re[z] >= 0 || z ∉ Reals]

The condition in the second argument of ConditionalExpression restricts the result to straight integration paths (from t = 1) that don’t intersect the branch cut running from z = -∞ to z = 0.

Depending on your starting point, the condition to avoid intersecting branch cuts can be quite complicated. For example, starting with t = 1 + i:

Integrate[D[Log[-t], t], {t, 1 + I, z}]

Result of condition to avoid intersecting branch cuts

That condition represents the following set of valid integration endpoints:

Integration endpoints from 1 + i avoiding the branch cut

Click here to download this post as a Computable Document Format (CDF) file, including the RegionPlot command used to generate the diagram above.

If you have a question you’d like answered in this blog, you can submit it to the Q&A Team. For daily bite-sized Mathematica tips, follow our @MathematicaTip Twitter feed.


Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.


  1. Hello! I really appreciate your youtube videos.

    You use FullSimplify here to compare expressions. However I discovered something that is bothering me. If I define f[x_] = (x!)^(1/x), then f'[x] and FullSimplify[f'[x]] are different functions (just plot them). How would I know when FullSimplify is tricking me?

  2. @Nikolaj:

    In addition, the problem doesn’t appear when you use Simplify (mostly because it doesn’t get any further than finding a common denominator) – only when using FullSimplify.

    The issue seems to arise in the “simplification” from
    -Log[Gamma[1 + x]] + x PolyGamma[0, 1 + x]
    x (HarmonicNumber[x] + EulerGamma) + Log[Gamma[1 + x]]

    I think the first expression should simplify to x (HarmonicNumber[x] – EulerGamma) – Log[Gamma[1 + x]] so it isn’t clear at all to me where the second expression comes from.

    I’d be interested to know the reason for this too.

  3. a triangle with the following dimensions 456 m by 616 m was to be fenced give the maximum number of posts to be used