How do I numerically approximate the following function to high precision?
$$ \log\left(\int_0^x \sin(t)^n dt\right)$$
$n$ is around $1000$ and $x\in (0,\pi)$.
One way is to just estimate the integral and compute the log of the result, but I am concerned about the precision of this approach since $n$ is so large.
Is there any way to re-represent this function as something more tractable?
For $x>\frac{\pi}{2}$ the integral will be dominated by the maximum of the integrand at $x = \frac{\pi}{2}$, the saddle point method will give you a good approximation. For $x<\frac{\pi}{2}$ the integral will get its dominant contribution from a small region near the upper limit of $x$. In the first case, it's convenient to write:
$$\int_0^x \sin^{n}(t) dt = \int_{-\frac{\pi}{2}}^{x-\frac{\pi}{2}}\cos^{n}(t) dt$$
Expanding the logarithm of the integrand around its maximum at $t = 0$ leads to a Gaussian approximation:
$$n \log\left[\cos(t)\right] = n\log\left(1-\frac{t^2}{2}+\frac{t^4}{24}+\cdots\right) = -\frac{n}{2}t^2-\frac{n}{12}t^4 +\cdots$$
Exponentiating and expanding gives:
$$\cos^n(t) = \exp\left(-\frac{nt^2}{2}\right)\left(1-\frac{nt^4}{12}+\cdots\right)$$
Substituting $t = \sqrt{\frac{2}{n}}u$, makes it clear that this yields an expansion in powers of $\frac{1}{n}$.
A more efficent way to get to a systematic expansion, is to define a new integration variable $u$ as
$$\cos^n(t) = \exp(-u^2)$$
right from the start. The Jacobian $\left|\frac{dt}{du}\right|$ of this transform is:
$$\left|\frac{dt}{du}\right| = \frac{2|u|}{n}\exp\left(-\frac{u^2}{n}\right)\left[1-\exp\left(-\frac{2u^2}{n}\right)\right]^{-\frac{1}{2}}$$
We then need to expand the Jacobian in powers of $u$:
$$\left|\frac{dt}{du}\right| = \sqrt{\frac{2}{n}}\left(1-\frac{u^2}{2n} + \frac{u^4}{24 n^2} + \frac{u^6}{48 n^3} - \frac{u^8}{640 n^4}-\frac{19 u^{10}}{11520 n^5}+\cdots\right)$$
The lower limit of the integral is exactly minus infinity, the upper limit can be replaced by infinity with exponentially small error, this approximation will break down when $x$ nears $\frac{\pi}{2}$ to within a few times $\frac{1}{\sqrt{n}}$
Computing the integral term by term then yields the expansion:
$$I = \int_0^x \sin^{n}(t) dt = \sqrt{\frac{2\pi}{n}}\left(1-\frac{1}{4n}+\frac{1}{32 n^2}+\frac{5}{128 n^3}-\frac{21}{2048 n^4}-\frac{399}{8192 n^5}+\cdots\right)$$
Taking the logarithm of this expansion yields:
$$\log(I) = -\frac{1}{2}\log(n) + \frac{1}{2}\log(2\pi) -\frac{1}{4n} + \frac{1}{24 n^3} -\frac{1}{20 n^5} + \cdots $$
The integral for $x<\frac{\pi}{2}$ is going to be exponentially small, it can be computed by expanding the integrand around the upper limit. This answer will be updated later to include this expansion (unless someone else is going to do that sooner). Also the case of $x$ within a region of a size of order $\frac{1}{\sqrt{n}}$ from $\frac{\pi}{2}$ must be treated separately.
Update: The case $\frac{\pi}{2}-x \gg \frac{1}{\sqrt{n}}$:
We can write the integral as:
$$I = \int_0^{x}\sin^n(x-t)dt$$
we can then expand the logarithm of the integrand around $t=0$ to get to an approximation in terms of an exponential function. Anticipating the expansion we then get, we can go about that in a systematic way by defining a new variable $u$ by putting:
$$\sin^n(x-t) = \sin^n(x)\exp(-u)$$
The integral then becomes:
$$I = \frac{\sin^{n+1}(x)}{n}\int_0^{\infty}\exp(-u)\frac{\exp(-\frac{u}{n})}{\sqrt{1-\sin^2(x)\exp(-\frac{2u}{n})}}du$$
Expanding the term multiplying $\exp(-u)$ in the integrand in powers of $u$ and integrating term by term yields an expansion in powers of $\frac{1}{n}$:
$$ \begin{split} I = \frac{\sin^{n+1}(x)}{n\cos(x)}&\left[ 1-\frac{1}{\cos^2(x)}\frac{1}{n}+\left(\frac{3}{\cos^4(x)}-\frac{2}{\cos^2(x)}\right)\frac{1}{n^2}\right.\\ &\left. -\left( \frac{15}{\cos^6(x)}-\frac{18}{\cos^4(x)}+\frac{4}{\cos^2(x)}\right)\frac{1}{n^3}+\cdots\right] \end{split} $$
Finding the large n expansion of the logarithm of this expression is straightforward, but unlike in the case $x-\frac{\pi}{2}\gg \frac{1}{\sqrt{n}}$, the expansion of $\log(I)$ does not yield a simpler expression than that of $I$.