Taylor expansion of a not easily differentiable function Context: I'm trying to find the period of a simple pendulum. As is well known, if the initial angle is small the period is approximately constant. I'm trying to do a second order expansion.
I have this function:
$$
f(\theta_0) = \int_0^{\theta_0}\frac{d\theta}{\sqrt{\cos \theta - \cos \theta_0}}
$$
where $0\le\theta_0 \le \pi$. I'm trying to find its second degree Taylor polynomial around $\theta_0 = 0$. The issue is that since the function being integrated goes to infinity when $\theta=\theta_0$ (and as a special case, when $\theta_0=0$), so finding the value of $f$ and its derivatives at $\theta_0=0$ is not very easy.
To find $f(0)$, I assumed that $\theta_0$ was small and replaced both cosines by their second degree Taylor polynomials. I computed the resulting integral and found that for small $\theta_0$, the value of $f$ is $\frac{\pi}{\sqrt2}$ and is independent of $\theta_0$. This is a strong hint that $f'(0)=0$, but I don't think it's good enough.
The problem is that I don't see a way to compute $f'(\theta_0)$, since I can't apply Leibniz's rule for differentiating under the integral sign because of all the infinities involved. Specifically, I can't evalute $\frac1{\sqrt{\cos \theta - \cos \theta_0}}$ at $\theta=\theta_0$. And of course, I can't find the second derivative until I find the first.


*

*Wikipedia mentions that the power series can be found by rewriting $f$ in terms of elliptic integrals. Is there an elementary way to find the second degree Taylor polynomial? What about arbitrary degree polynomials?

*Is there a way to apply differentiation under the integral sign in situations like this?
 A: $$f(\theta_0) = \int_0^{\theta_0}\frac{d\theta}{\sqrt{\cos \theta - \cos \theta_0}}=\int_0^{\theta_0}{\frac{d\theta}{\sqrt{\left(1-2\sin^2\left({\theta\over 2}\right)\right) - \left(1-2\sin^2\left({\theta_0\over 2}\right)\right)}}}$$ $$={1\over \sqrt 2}\int_0^{\theta_0}{\frac{d\theta}{\sqrt{\sin^2(\theta_0/2)-\sin^2(\theta/2)}}}$$ $$\sin\left({\theta\over 2}\right)=\sin\left({\theta_0\over 2}\right)\sin\phi,\;\;{1\over 2}\cos\left({\theta\over 2}\right)d\theta=\sin\left({\theta_0\over 2}\right)\cos\phi d\phi$$  The integrand becomes $$\frac{2\sin\left(\theta_0/2\right)\cos\phi d\phi}{\sqrt{1-\left(\sin\left({\theta_0\over 2}\right)\sin\phi\right)^2}\sqrt{1-\sin^2\phi}\sin(\theta_0/2)}=\frac{2d\phi}{\sqrt{1-\left(\sin\left({\theta_0\over 2}\right)\sin\phi\right)^2}}$$
So the integral is now $$\sqrt 2\int_0^{\pi/2}\frac{d\phi}{\sqrt{1-\left(k\sin\phi\right)^2}},\;\;\;\;k=\sin(\theta_0/2)$$ We have $$(1-x^2)^{-1/2}=1+{1\over 2}x^2+\frac{1\cdot 3}{2\cdot 4}x^4+\cdots$$ and also $$\int_0^{\pi/2}{\sin^n\phi\,d\phi}=\frac{1\cdot 3\cdots (n-1)}{2\cdot 4\cdots n}{\pi\over 2}$$ Therefore we get $${\pi\over \sqrt2}\left[1+\left(\frac{1}{2}\right)^2k^2+\left(\frac{1\cdot 3}{2\cdot 4}\right)^2k^4+\cdots\right]$$ as the final answer.
Sources: Ordinary Differential Equations by Morris Tenebaum and Harry Pollard.
