Integral That Requires Differentiating Under the Integral Sign Twice? Is it "legal" to differentiate under the integral twice? Are there problems where there this is actually useful? If I were to differentiate under the integral sign twice, I would need to integrate the function with respect to the inserted variable twice too to get the original function, but in the process, I would need to find two different constants of integrations too. Does this make sense? Are there problems that actually simplify better by differentiating under the integral twice? Or is this completely not allowed by some definition or theorem that I'm unaware of?
Hopefully, this was not too incoherent to understand, 
thanks in advance.

Here's an integral (actually two) I did with double-differentiation:
$$\int_0^\infty \frac{sin(x)^2}{x^2(x^2+1)}dx$$
$$f(a)=\int_0^\infty \frac{sin(ax)^2}{x^2(x^2+1)}dx$$
$$f'(a)=\int_0^\infty \frac{2cos(ax)sin(ax)}{x(x^2+1)}dx$$
$$f'(a)=\int_0^\infty \frac{sin(2ax)}{x(x^2+1)}dx$$
$$f''(a)=\int_0^\infty \frac{2cos(2ax)}{(x^2+1)}dx$$
using $cos(2x)=1-2sin(x)^2$ we can make it look more like our original integral by rewriting this as
$$f''(a)=\int_0^\infty \frac{2(1-2sin(ax)^2)}{(x^2+1)}dx$$
$$f''(a)=\int_0^\infty \frac{2}{(x^2+1)}dx - \int_0^\infty \frac{4sin(ax)^2}{(x^2+1)}dx$$
$$f''(a)=\pi - 4\int_0^\infty \frac{sin(ax)^2}{(x^2+1)}dx$$
notice that $\frac{sin(ax)^2}{(x^2+1)}$ is the original integrand multiplied by $x^2$. If we add the original integrand, for a factor of $x^2+1$, it will cancel the $\frac{1}{1+x^2}$:
$$f''(a)-4f(a)=\pi - 4\int_0^\infty \frac{sin(ax)^2}{(x^2+1)}dx - 4\int_0^\infty \frac{sin(ax)^2}{x^2(x^2+1)}dx$$
$$f''(a)-4f(a)=\pi - 4\int_0^\infty \frac{x^2sin(ax)^2+sin(ax)^2}{x^2(x^2+1)}dx$$
$$f''(a)-4f(a)=\pi - 4\int_0^\infty \frac{sin(ax)^2}{x^2}dx$$
if we can calculate that integral to the right, we can (hopefully) solve this differential equation for $f(a)$. We can't differentiate it two times with respect to $a$ because then we'd get a divergent integral. Instead, we introduce another parameter:
$$g(t) = \int_0^\infty e^{-tx}\frac{4sin(ax)^2}{x^2}dx$$
differentiating twice yields
$$g''(t) = \int_0^\infty e^{-tx}4sin(ax)^2dx$$
which can be solved easily (albeit tediously) with an antiderivative to yield:
$$g''(t)=\frac 2t - \frac{2t}{t^2+4a^2}$$
Because of the $e^{-tx}$, $g(\infty)=0$ and $g'(\infty)=0$. Thus we can integrate to obtain
$$g'(t) - g'(\infty) = \int_\infty^t \frac 2t - \frac{2t}{t^2+4a^2} dt$$
$$g'(t) = 2ln(t) - ln(t^2+4a^2)$$
We can obtain the desired $g(0)$ by integrating again (with integration by parts, which I'll leave as an exercise to the reader):
$$g(0) - g(\infty) = \int_\infty^0 2ln(t) - ln(t^2+4a^2)dt$$
$$g(0) = 2\pi |a|$$
Now we can put this into the differential equation:
$$f''(a)-4f(a)=\pi - 2\pi |a|$$
$$f''(a) = 4f(a) + \pi - 2\pi |a|$$
which is straightforward (but tedious) to solve, using the facts that $f(0) = 0$ and $f'(0) = 0$ to solve for the constants. This can be done more easily by solving for $ a >= 0$ with $a$ instead of $|a|$. Then the absolute value can be substituted again since $f(-a) = f(a)$ according to the integral. Once this is done, you get:
$$f(a) = -\frac{\pi}{4} + \frac{\pi}{2} |a| + \frac{\pi}{4} e^{-|2a|}$$
$$f(1) =  \frac{\pi}{4} (1+e^{-2})$$
