By parts: How'd we get here?

Byparts integration may seem like it comes out of nowhere, but it is nothing more than a creative usage of the product rule.

Let \( G(x) \) denote the antiderivative of \( g(x) \), then:
\[ \int f(x)g(x) \ dx = f(x)G(x)\int G(x)f'(x) \ dx + C \] 
First, let's check out why this works:
Suppose we want to find the indefinite integral of a product of functions.
\[ \int f(x)g(x) \ dx \]
We can play around with some things and see what shakes out.
Consider this (recall from above that \( G(x) \) is the antiderivative of \( g(x) \))
\[ \frac{d}{dx} \left[ f(x) G(x) \right] = f'(x) G(x) + f(x)g(x) \]
That was just a product rule, no biggie. Let's wiggle it around.
\[ f(x)g(x) = \frac{d}{dx} \left[ f(x)G(x) \right]  f'(x)G(x) \]
Now, if we integrate both sides with respect to \( x \), we will have exactly what we're looking for.
\[ \int f(x)g(x) \ dx = \int \left( \frac{d}{dx} \left[ f(x)G(x) \right]f'(x)G(x) \right) \ dx \]
Of course we can integrate "termbyterm" as always
\[ \int f(x)g(x) \ dx = f(x)G(x)  \int f'(x)G(x) \ dx \]
There it is! So it may seem strange but it doesn't take long to come up with a fast and loose derivation.
I'll now give three examples of some byparts integrals
Suppose we want to find the indefinite integral of a product of functions.
\[ \int f(x)g(x) \ dx \]
We can play around with some things and see what shakes out.
Consider this (recall from above that \( G(x) \) is the antiderivative of \( g(x) \))
\[ \frac{d}{dx} \left[ f(x) G(x) \right] = f'(x) G(x) + f(x)g(x) \]
That was just a product rule, no biggie. Let's wiggle it around.
\[ f(x)g(x) = \frac{d}{dx} \left[ f(x)G(x) \right]  f'(x)G(x) \]
Now, if we integrate both sides with respect to \( x \), we will have exactly what we're looking for.
\[ \int f(x)g(x) \ dx = \int \left( \frac{d}{dx} \left[ f(x)G(x) \right]f'(x)G(x) \right) \ dx \]
Of course we can integrate "termbyterm" as always
\[ \int f(x)g(x) \ dx = f(x)G(x)  \int f'(x)G(x) \ dx \]
There it is! So it may seem strange but it doesn't take long to come up with a fast and loose derivation.
I'll now give three examples of some byparts integrals
\[ \int xe^x \ dx \]
Let's identify: \( f(x) = x \) and \( g(x) = e^x \ dx \) Then \( f'(x) = 1 \ dx \) and \( G(x) = e^x \) We're all set for the formula! \[ xe^x\int e^x \ dx +C \] \[ xe^xe^x +C \] \[ e^x(x1)+C \] Done! 
\[ \int \ln{x} \ dx \]
This one can come over as tricky, because there doesn't appear to be two functions to use here! Remember though that there is always an 'understood 1' constant function you can use. Let's identify: \( f(x) = \ln{x} \) and \( g(x)=1 \ dx \) Then \( f'(x) = \frac{1}{x} \ dx \) and \( G(x) = x \) \[ x \ln{x}  \int x \frac{1}{x} \ dx \] \[ x \ln{x}  x + C \] \[ x( \ln{x}1) + C \] Done! 
\[ \int x \sin{x} \ dx \]
Let's identify: \( f(x) = x \) and \( g(x) = \sin{x} \ dx \) Then \( f'(x) = 1 \ dx \) and \( G(x) = \cos{x} \) Here we go \[ x \cos{x}  \int (1)(\cos{x}) \ dx +C \] \[ x \cos{x} + \sin{x} + C \] \[ \sin{x}x \cos{x} + C \] Done! 
Notice that the resulting integrand is integrable by other means, which is generally the goal. Sometimes it takes multiple iterations of byparts to reach this point. There are times, however, when this never happens and instead results in either an infinite process (at which point you're out of luck) or a cycle that winds back on itself. The final example I am going to give it one of these. 
\[ \int e^x \sin{x} \ dx \]
Let's identify \( f(x) = \sin{x} \) and \( g(x) = e^x \ dx \). Then \( f'(x) = \cos{x} \ dx \) and \( G(x) = e^x \).
Plugging in the formula:
\[ \int e^x \sin{x} \ dx = e^x \sin{x}  \int e^x \cos{x} \ dx \]
But that integral is also a byparts technique.
Let's identify \( f(x) = \cos{x} \) and \( g(x)=e^x \ dx \). Then \( f'(x) = \sin{x} \ dx \) and \( G(x) = e^x \).
Invoking the formula again:
\[ \int e^x \sin{x} \ dx = e^x \sin{x}  \left( e^x \cos{x}  \int e^x \sin{x} \ dx \right) \]
\[ \int e^x \sin{x} \ dx = e^x \sin{x}  e^x \cos{x}  \int e^x \sin{x} \ dx \]
Notice now that we have cycled around again to needing to find the original integral we started out with, and we can add it across.
\[ 2 \int e^x \sin{x} \ dx = e^x \left[ \sin{x}  \cos{x} \right] \]
\[ \int e^x \sin{x} \ dx = \frac{1}{2} e^x \left[ \sin{x}  \cos{x} \right] \]
Let's identify \( f(x) = \sin{x} \) and \( g(x) = e^x \ dx \). Then \( f'(x) = \cos{x} \ dx \) and \( G(x) = e^x \).
Plugging in the formula:
\[ \int e^x \sin{x} \ dx = e^x \sin{x}  \int e^x \cos{x} \ dx \]
But that integral is also a byparts technique.
Let's identify \( f(x) = \cos{x} \) and \( g(x)=e^x \ dx \). Then \( f'(x) = \sin{x} \ dx \) and \( G(x) = e^x \).
Invoking the formula again:
\[ \int e^x \sin{x} \ dx = e^x \sin{x}  \left( e^x \cos{x}  \int e^x \sin{x} \ dx \right) \]
\[ \int e^x \sin{x} \ dx = e^x \sin{x}  e^x \cos{x}  \int e^x \sin{x} \ dx \]
Notice now that we have cycled around again to needing to find the original integral we started out with, and we can add it across.
\[ 2 \int e^x \sin{x} \ dx = e^x \left[ \sin{x}  \cos{x} \right] \]
\[ \int e^x \sin{x} \ dx = \frac{1}{2} e^x \left[ \sin{x}  \cos{x} \right] \]
Be sure to check out the advanced technique of Tabular Integration By Parts, and good luck out there!