Getting different answers when integrating using different techniques

Short Answer

It is entirely possible to correctly evaluate an indefinite integral using different methods and arrive at functions which look different. However, once the constant of integration is taken into account, the functions will agree. The moral of the story is to be mindful of the constants of integration.


Antiderivatives

When working with indefinite integrals, it is important to remember that the symbol $\int f(x) \,\mathrm{d}x$ does not represent a single function, but rather an entire family of antiderivatives of $f$. Phrasing things a little bit more formally:

Definition: Suppose that $f$ is integrable on the on interval $(a,b)$. An antiderivative of $f$ is a function $F$ such that $$ F'(x) = f(x) $$ for all $x \in (a,b)$.

With respect to this definition, antiderivatives are not unique. For example, both $$ F(x) = \frac{1}{2} x^2 \qquad\text{and}\qquad G(x) = \frac{1}{2} x^2 + 1 $$ are antiderivatives of the function $f(x) = x$, since $$ F'(x) = x = G'(x). $$ Thus any particular integrable function may have many, many distinct antiderivatives. However, it can be shown that if $F$ and $G$ are both antiderivatives of a function $f$ (in the sense defined above), then $F$ and $G$ differ by at most a constant.

Since antiderivatives differ from each other by at most a constant, it is common to adopt a notation for "the" antiderivative of a function which captures this typically inessential distinction. Thus $$ \int f(x)\,\mathrm{d}x $$ represents the entire collection antiderivatives. Moreover, as antiderivatives differ by at most a constant, we also often write $$ \int f(x) \,\mathrm{d}x = F(x) + C, $$ where $F$ is any particular antiderivative, and $C$ is a "constant of integration."


Error Detection

As noted above, it is entirely possible to tackle a single indefinite integral in multiple ways and get entirely different looking results. However, the primary motivation for doing a problem in more than one way is to detect mistakes. Hence the fact that antiderivates are not unique may be troublesome. Therefore, from a pedagogical or learning point of view, detecting antiderivatives which differ by a constant might be helpful.

In general, one wants to show that if $F$ and $G$ are both purported antiderivatives of a given function, then $F - G$ is a constant function. Showing that $F-G$ is constant might not be trivial, but there are a couple of strategies which come to mind:

  1. Inspection: Sometimes, it is obvious that two functions differ by only a constant. For example, in example (1), above, the two polynomials differ by $\frac{32}{5}$. This can be seen without doing too much work. Thus if either function is an antiderivative of the given function, then both are.

  2. A Little Algebra: Other times, it is not immediately obvious that two functions differ by a constant. In example (2), above, it might require a little work: \begin{align} &\left[\frac{-2}{(x+1)} - \ln|x+1|\right] - \left[\frac{x-1}{(x+1)} - \ln|x+1| \right] \\ &\qquad\qquad= \frac{-2}{x+1} - \frac{x-1}{x+1} \\ &\qquad\qquad= \frac{-2 - x + 1}{x+1} \\ &\qquad\qquad= \frac{-(x+1)}{x+1} \\ &\qquad\qquad= -1, \end{align} which is a constant.

  3. Differentiate: One possibility is to simply differentiate the two results and see if they are the same. However, one might be able to save a little work: if two functions differ by a constant, then their difference will have derivative $0$. In example (3), above: \begin{align} &\frac{\mathrm{d}}{\mathrm{d}x} \left[ \frac {\sec^2(\pi x)}{4\pi} - \frac {\tan^2(\pi x)}{4\pi} \right] \\ &\qquad\qquad= \frac{1}{4\pi} \left( 2\sec(\pi x)\cdot \sec(\pi x)\tan(\pi x)\cdot \pi - 2\tan(\pi x) \cdot \sec(\pi x)^2 \cdot \pi \right) \\ &\qquad\qquad= 0. \end{align} As the derivative of the difference is zero, the original functions differ by (at most) a constant.

Of course, in this example, one could also use trig identities (as suggested in one of the linked answers), but then I wouldn't get to discuss this alternative. ;)

More generally, it is helpful to keep various identities in mind. In particular, if two different procedures give seemingly different results, think about the kinds of functions which are involved, and search out relevant identities. For example, $$ \cos(x)^2 + \sin(x)^2 = 1 \qquad\text{and}\qquad \tan(x)^2 = 1 - \sec(x)^2 $$ for real $x$ such that the functions involved are defined, and $$ \log(xy) = \log(x) + \log(y), $$ for all positive $x$ and $y$. Different substitutions or integration by parts steps may lead