Integration by parts: is this legitimate way of using? Is it legitimate to write 
$$\int_0^a\mathrm{d}x\,f(x)g(x)=\left[f(x)\int_0^x\mathrm{d}x\,g(x)\right]_0^a-\int_0^a\mathrm{d}x\,\frac{\mathrm{d}f(x)}{\mathrm{d}x}\int_0^x\mathrm{d}x\,g(x)$$
Thanks.
 A: It's good, if read correctly; you are less likely to make errors with this if you set
$$
G(x)=\int_0^xg(t)\,dt
$$
and write
$$
\int_0^af(x)g(x)\,dx=
\Bigl[f(x)G(x)\Bigr]_0^a-\int_0^a f'(x)G(x)\,dx
$$
If you prefer not to use $G$, you can write
$$
\int_0^af(x)g(x)\,dx=
\left[f(x)\int_0^x g(t)\,dt\right]
-
\int_0^a f'(x)\left(\int_0^x g(t)\,dt\right)\,dx
$$
A: Yes!It is correct
Let $u=f(x)$, $dv=g(x)dx$, 
$du=f'(x)dx, v=\int_{0}^{a}g(x)dx$
so
$\int_{0}^{a}f(x)g(x)dx=[f(x)\int_{0}^{x}g(x)dx]_{0}^{a}-\int_{0}^{a}[\int_{0}^{x}g(x)dx]f'(x)dx $
Next, integrate by parts a second time,
$u=f'(x)dx, dv=\int_{0}^{a}g(x)dx$
$du=f''(x)dx, v=\int_{0}^{a}\int_{0}^{a}g(x)(dx)^{2}$
$\int_{0}^{a}f(x)g(x)dx=[f(x)\int_{0}^{x}g(x)dx]_{0}^{a}-[f'(x)\int_{0}^{x}\int_{0}^{x}g(x)(dx)^{2}]_{0}^{a}+\int_{0}^{a}[\int_{0}^{x}\int_{0}^{x}\int_{0}^{x}g(x)(dx)^{3}]f''(x)dx $
A: Almost, but not quite.  I'm seeing a lot of notational issues and other issues around here which could lead to trouble.  Instead, say:
$u = f(x), \qquad dv = g(x) \, dx$
$du = f'(x)\, dx, \qquad v = \displaystyle \int_0^x g(t) \, dt + v(0)\qquad $ (this $v$ is explained later in the post)
Then we have
$$ \int_0^a f(x) g(x) \, dx = \left[f(x) \left(\int_0^x g(t)\, dt + v(0)\right)\right]\Bigg|_{x=0}^{x=a} - \int_0^a \left(\int_0^x g(t)\, dt + v(0)\right) f'(x) \, dx $$
Here's a breakdown of what's what in the formula:
$$ \overbrace{\int_0^a \underbrace{f(x)}_{\color{red}{u}} \underbrace{g(x) \, dx}_{\color{red}{dv}}}^{\color{blue}{\int_{x=0}^{x=a} u \, dv}} = \overbrace{\left[\underbrace{f(x)}_{\color{red}{u}} \underbrace{\left(\int_0^x g(t)\, dt + v(0)\right)}_{\color{red}{v}}\right]\Bigg|_{x=0}^{x=a}}^{\color{blue}{uv\big|_{x=0}^{x=a}}} - \overbrace{\int_0^a \underbrace{\left(\int_0^x g(t)\, dt + v(0)\right)}_{\color{red}{v}} \underbrace{f'(x) \, dx}_{\color{red}{du}}}^{\color{blue}{\int_{x=0}^{x=a} v \, du}} $$

Some explanations:
We already know that $dv = g(x) \, dx$.  Therefore $v'(x) = g(x)$, and the FTC tells us that $\int_0^x v'(t) \, dt = v(x) - v(0)$.  Well, since $v'(t)$ is $g(t)$, then we have $v(x) - v(0) = \int_0^x g(t) \, dt$, which gives us $v = \int_0^x g(t) \, dt + v(0)$.  Notice how I'm using $t$ as the variable of integration.  This is because $x$ is a limit of integration, and in general it's very bad form (and personally I would say incorrect) to have a limit of integration be the same as the variable of integration.  And we need the variable of integration to be $x$ because $v$ is a function of $x$.
Note that the $f'(x) \, dx$ in the integral on the RHS above is ok, because it's the inner integral that has $x$ as a limit, but the $f'(x) \, dx$ is for the outer integral.  In fact, this actually has to be $f'(x)\, dx$ because if we were to evaluate $\int_0^x g(t) \, dt + v(0)$, we would get a function of $x$.  Therefore the outer integral needs to be $dx$, which means we must have $f'(x) \, dx$ in order for this to work out.

Example:  $ \displaystyle \int_0^{\pi/2} x \cos x \, dx$
I'll run through this twice.  Once how we would do it in practice, and then again in a manner similar to how I explained above.
In practice:
$u = x, \qquad dv = \cos x \, dx$
$du = dx, \qquad v = \int \cos x \, dx = \sin x$
Note the lack of arbitrary constant of integration on $v$.  It's because it always cancels out in the end anyway, so for simplicity we just don't bother with it.  Anyway, plugging everything into the formula gives us:
$$\int_0^{\pi/2} \underbrace{x}_{\color{red}{u}} \underbrace{\cos x \, dx}_{\color{red}{dv}} = \underbrace{x}_{\color{red}{u}}\underbrace{(\sin x)}_{\color{red}{v}}\bigg|_0^{\pi/2} - \int_0^{\pi/2} \underbrace{\sin x}_{\color{red}{v}} \, \underbrace{dx}_{\color{red}{du}}$$
Similar to my explanation above:
$u = x, \qquad dv = \cos x \, dx$
$du = dx, \qquad v = \int_0^x \cos t \, dt + v(0)$
Let's take a closer look at $v$.  We have
\begin{align}
  v &= \int_0^x \cos t \, dt + v(0)\\[0.3cm]
    &= \underbrace{\sin t}_{\color{blue}{\text{this is $v(t)$}}}\bigg|_0^x + \underbrace{v(0)}_{\substack{\color{blue}{\text{therefore}} \\ \color{blue}{v(0) = \sin 0}}}\\[0.3cm]
    &= \underbrace{\sin x - \sin 0 + \sin 0}_{\color{blue}{v(x) - v(0) + v(0)}}\\[0.3cm]
    &= \sin x
\end{align}
Notice how the $+v(0)$ is necessary to cancel out the $-v(0)$. And yes, in this case it wouldn't have mattered because $v(0) = 0$ anyway, but that won't be true in general so we do need to be careful.  But again, in practice what we do is actually much simpler, and I only wrote my answer this way to show what's really happening behind the scenes and so I could avoid notational issues in the double integral near the end.
