# Leibniz integration rule applied twice

I want to apply the Leibniz integration rule twice to this integral:

$$\frac{\textrm d^2}{\textrm d^2 x}\int_a^x g(s)(x-s)ds$$

The first application gives:

$$\frac{\textrm d}{\textrm d x}\int_a^x g(s)(x-s)ds = \int_a^x\frac{\partial}{\partial x}\left(g(s)(x-s)\right)ds = \int_a^x g(s)ds$$

But the next one troubles me:

$$\frac{\textrm d}{\textrm d x}\int_a^x g(s)ds = \int_a^x\frac{\partial}{\partial x}g(s)ds =$$

The result should be

$$g(x)$$

But I cannot see why $$g(x)$$ is the result.

Any ideas?

What you wrote is not correct: $$\frac{d}{dx}\int_a^x g(s) \mathrm ds\ne\int_a^x \frac{d}{dx}g(s)\mathrm ds$$ The result follows from the regular fundamental theorem of calculus $$\frac{d}{dx}\int_a^xg(s)\mathrm ds=g(x)$$ You may have gotten lucky in the first term and not been clear on how this rule works. In general, $$\frac{d}{dx}\int_{a(x)}^{b(x)}f(t,x)\mathrm dt=f(b(x),x)b'(x)-f(a(x),x)a'(x)+\int_{a(x)}^{b(x)}f_x(t,x)\mathrm dt$$ So in the first differentiation, you have $$\frac{d}{dx}\int_a^x g(s)(x-s)\mathrm ds=g(x)(x-x)+\int_a^x g(s)\mathrm ds= \int_a^x g(s)\mathrm ds$$