# Integral $S_\ell(r) = \int_0^{\pi}\int_{\phi}^{\pi}\frac{(1+ r \cos \psi)^{\ell+1}}{(1+ r \cos \phi)^\ell} \rm d\psi \ \rm d\phi$

Is there a closed form for $|r|<1$ and $\ell>0$ integer?

The solution for the special cases $\ell=2$ and $4$ would also be interesting if the general case is not available.

Integrating numerically, it seems like it tends asymptotically to $\lim_{\ell\rightarrow\infty} S_{\ell}(r) = s(r)\, \ell^{-1} \ln \ell$ for $\ell\rightarrow \infty$. What is $s(r)$?

This integral gives the interaction energy for vector resonant relaxation between two stellar orbits in astrophysical dynamics.

EDIT

A possibly useful identity $$\tag{1} \int_{\phi}^{\pi}(1 + r \cos \psi )^{\ell} d \psi = \sum_{m=0}^{\ell} \frac{2\, i^m \ell!}{(\ell+m)!} \frac{P_{\ell}^{m}(q)}{q^{\ell+1}} {\rm if}\left(m=0, \frac{\pi - \phi}{2},-\frac{\sin (m\phi)}{m}\right)$$ where $q=1/\sqrt{1-r^2}$ and $P_\ell^m(x)$ are associated Legendre polynomials. Furthermore $$I_{m\ell}=\int_0^{\pi}\frac{\sin(m \phi)}{(1+r \cos \phi)^{\ell}} d \phi$$ can be integrated analytically as shown (more or less) here. However the problem with (1) is that the $m=0$ term grows very quickly with $\ell$ which is cancelled out almost exactly by the $m>1$ terms. For $\ell=20$ and $r=0.8$ the $m=0$ term is $3.4604541\times 10^{15}$, while the sum of the $m>1$ terms is $-3.4604541\times10^{15}$. The two terms have the same magnitude to 15 significant digits, such that their sum is 0.411. This shows that these terms require an extremely accurate numerical calculation. If someone can (i) figure out the underlying reason for this magical cancellation or (ii) give an analytical solution for the $m=0$ term, then the large numbers may be removed and make this calculable. I was hoping that someone can write down a clever solution altogether circumventing the use of (1).

EDIT2: Verify the numerical stability of the answer for $r=0.8$ and $\ell=100$, see if you can reach a desired accuracy $10^{-8}$. Make sure partial sums comprising an answer do not reach $10^{92}$. The identity quoted above and all of the answers up to now fail this test.

$$\int_0^\pi\int_\phi^\pi\dfrac{(1+r\cos\psi)^{\ell+1}}{(1+r\cos\phi)^\ell}d\psi~d\phi$$

$$=\int_0^\pi\int_\phi^\pi\sum\limits_{m=0}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\dfrac{C_{2m}^{\ell+1}r^{2m}\cos^{2m}\psi}{(1+r\cos\phi)^\ell}d\psi~d\phi+\int_0^\pi\int_\phi^\pi\sum\limits_{m=0}^{\left\lceil\frac{\ell+1}{2}\right\rceil}\dfrac{C_{2m+1}^{\ell+1}r^{2m+1}\cos^{2m+1}\psi}{(1+r\cos\phi)^\ell}d\psi~d\phi$$

$$=\int_0^\pi\int_\phi^\pi\dfrac{1}{(1+r\cos\phi)^\ell}d\psi~d\phi+\int_0^\pi\int_\phi^\pi\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\dfrac{(\ell+1)!r^{2m}\cos^{2m}\psi}{(2m)!(\ell-2m+1)!(1+r\cos\phi)^\ell}d\psi~d\phi\\+\int_0^\pi\int_\phi^\pi\sum\limits_{m=0}^{\left\lceil\frac{\ell+1}{2}\right\rceil}\dfrac{(\ell+1)!r^{2m+1}\cos^{2m+1}\psi}{(2m+1)!(\ell-2m)!(1+r\cos\phi)^\ell}d\psi~d\phi$$

For $\int\cos^{2m}\psi~d\psi$ , where $m$ is any natural number,

$$\int\cos^{2m}\psi~d\psi=\dfrac{(2m)!\psi}{4^m(m!)^2}+\sum\limits_{n=1}^m\dfrac{(2m)!((n-1)!)^2\sin\psi~\cos^{2n-1}\psi}{4^{m-n+1}(m!)^2(2n-1)!}+C$$

This result can be done by successive integration by parts, e.g. as shown as http://hk.knowledge.yahoo.com/question/question?qid=7012022000808

For $\int\cos^{2m+1}\psi~d\psi$ , where $m$ is any non-negative integer,

$$\int\cos^{2m+1}\psi~d\psi$$

$$=\int\cos^{2m}\psi~d(\sin\psi)$$

$$=\int(1-\sin^2\psi)^m~d(\sin\psi)$$

$$=\int\sum\limits_{n=0}^mC_n^m(-1)^n\sin^{2n}\psi~d(\sin\psi)$$

$$=\sum\limits_{n=0}^m\dfrac{(-1)^nm!\sin^{2n+1}\psi}{n!(m-n)!(2n+1)}+C$$

$$\therefore\int_0^\pi\int_\phi^\pi\dfrac{1}{(1+r\cos\phi)^\ell}d\psi~d\phi+\int_0^\pi\int_\phi^\pi\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\dfrac{(\ell+1)!r^{2m}\cos^{2m}\psi}{(2m)!(\ell-2m+1)!(1+r\cos\phi)^\ell}d\psi~d\phi+\int_0^\pi\int_\phi^\pi\sum\limits_{m=0}^{\left\lceil\frac{\ell+1}{2}\right\rceil}\dfrac{(\ell+1)!r^{2m+1}\cos^{2m+1}\psi}{(2m+1)!(\ell-2m)!(1+r\cos\phi)^\ell}d\psi~d\phi$$

$$=\int_0^\pi\biggl[\dfrac{\psi}{(1+r\cos\phi)^\ell}\biggr]_\phi^\pi~d\phi+\int_0^\pi\biggl[\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\dfrac{(\ell+1)!r^{2m}\psi}{4^m(m!)^2(\ell-2m+1)!(1+r\cos\phi)^\ell}\biggr]_\phi^\pi~d\phi+\int_0^\pi\biggl[\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\dfrac{(\ell+1)!((n-1)!)^2r^{2m}\sin\psi~\cos^{2n-1}\psi}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+r\cos\phi)^\ell}\biggr]_\phi^\pi~d\phi+\int_0^\pi\biggl[\sum\limits_{m=0}^{\left\lceil\frac{\ell+1}{2}\right\rceil}\sum\limits_{n=0}^m\dfrac{(-1)^n(\ell+1)!m!r^{2m+1}\sin^{2n+1}\psi}{(2m+1)!(\ell-2m)!n!(m-n)!(2n+1)(1+r\cos\phi)^\ell}\biggr]_\phi^\pi~d\phi$$

$$=\int_0^\pi\sum\limits_{m=0}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\dfrac{(\ell+1)!r^{2m}(\pi-\phi)}{4^m(m!)^2(\ell-2m+1)!(1+r\cos\phi)^\ell}d\phi-$$

$$\int_0^\pi\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\dfrac{(\ell+1)!((n-1)!)^2r^{2m}\sin\phi~\cos^{2n-1}\phi}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+r\cos\phi)^\ell}d\phi-$$

$$\int_0^\pi\sum\limits_{m=0}^{\left\lceil\frac{\ell+1}{2}\right\rceil}\sum\limits_{n=0}^m\dfrac{(-1)^n(\ell+1)!m!r^{2m+1}\sin^{2n+1}\phi}{(2m+1)!(\ell-2m)!n!(m-n)!(2n+1)(1+r\cos\phi)^\ell}d\phi$$

$$=\int_0^\pi\sum\limits_{m=0}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\dfrac{(\ell+1)!r^{2m}\phi}{4^m(m!)^2(\ell-2m+1)!(1-r\cos\phi)^\ell}d\phi-$$

$$\int_0^\pi\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\dfrac{(\ell+1)!((n-1)!)^2r^{2m}\sin\phi~\cos^{2n-1}\phi}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+r\cos\phi)^\ell}d\phi-$$

$$\int_0^\pi\sum\limits_{m=0}^{\left\lceil\frac{\ell+1}{2}\right\rceil}\sum\limits_{n=0}^m\dfrac{(-1)^n(\ell+1)!m!r^{2m+1}\sin^{2n+1}\phi}{(2m+1)!(\ell-2m)!n!(m-n)!(2n+1)(1+r\cos\phi)^\ell}d\phi$$

For $\int_0^\pi\sum\limits_{m=0}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\dfrac{(\ell+1)!r^{2m}\phi}{4^m(m!)^2(\ell-2m+1)!(1-r\cos\phi)^\ell}d\phi$ , please refer to Closed form for integral $\int_{0}^{\pi} \left[1 - r \cos\left(\phi\right)\right]^{-n} \phi \,{\rm d}\phi$.

For $\int_0^\pi\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\dfrac{(\ell+1)!((n-1)!)^2r^{2m}\sin\phi~\cos^{2n-1}\phi}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+r\cos\phi)^\ell}d\phi$ ,

$$\int_0^\pi\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\dfrac{(\ell+1)!((n-1)!)^2r^{2m}\sin\phi~\cos^{2n-1}\phi}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+r\cos\phi)^\ell}d\phi$$

$$=-\int_0^\pi\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\dfrac{(\ell+1)!((n-1)!)^2r^{2m}\cos^{2n-1}\phi}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+r\cos\phi)^\ell}d(\cos\phi)$$

$$=\int_{-1}^1\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\dfrac{(\ell+1)!((n-1)!)^2r^{2m}u^{2n-1}}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+ru)^\ell}du$$

$$=\int_{-1}^1\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\dfrac{(\ell+1)!((n-1)!)^2r^{2m-2n+1}(1+ru-1)^{2n-1}}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+ru)^\ell}du$$

$$=\int_{-1}^1\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\sum\limits_{k=0}^{2n-1}\dfrac{(\ell+1)!((n-1)!)^2r^{2m-2n+1}C_k^{2n-1}(-1)^{2n-k-1}(1+ru)^k}{4^{m-n+1}(m!)^2(\ell-2m+1)!(2n-1)!(1+ru)^\ell}du$$

$$=\int_{-1}^1\sum\limits_{m=1}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\sum\limits_{n=1}^m\sum\limits_{k=0}^{2n-1}\dfrac{(-1)^{k-1}(\ell+1)!((n-1)!)^2r^{2m-2n+1}(1+ru)^{k-\ell}}{4^{m-n+1}(m!)^2(\ell-2m+1)!k!(2n-k-1)!}du$$

which should have closed form solution

so does for $\int_0^\pi\sum\limits_{m=0}^{\left\lceil\frac{\ell+1}{2}\right\rceil}\sum\limits_{n=0}^m\dfrac{(-1)^n(\ell+1)!m!r^{2m+1}\sin^{2n+1}\phi}{(2m+1)!(\ell-2m)!n!(m-n)!(2n+1)(1+r\cos\phi)^\ell}d\phi$

In fact this approach works well for small $\ell$ but may not work well for large $\ell$ , even we clearly know that all terms excluding for $\int_0^\pi\sum\limits_{m=0}^{\left\lfloor\frac{\ell+1}{2}\right\rfloor}\dfrac{(\ell+1)!r^{2m}\phi}{4^m(m!)^2(\ell-2m+1)!(1-r\cos\phi)^\ell}d\phi$ should have closed form solution.

• This solution is not in a closed form and suffers from the numerical instability described in the question. – bkocsis Nov 27 '13 at 22:26
• @bkocsis .... I'm upvoting because look at it, it's amazing! – Alec Teal Nov 28 '13 at 21:02
• Sure, I agree it is amazing. only if it would be in a closed form or could be used in practice, it would be even better.. – bkocsis Nov 29 '13 at 0:54
• Did you try to see if this solution can be used in practice without a floating point error? Try using it for $\ell=100$ and $r=0.8$! A numerical double integral gives 0.11632. Using your formula, the first two sums add up to $10^{92}$, and the latter two sums add up to $-10^{92}$. You cannot add these extremely large absolute value numbers using double precision! – bkocsis Dec 4 '13 at 22:46
• @bkocsis I have not read his answer in detail. If we can use doraemonpaul's answer, to compute to your accuracy within a "reasonable amount" of time, I believe it is closed form. But here are my questions, I wonder why would you need a tolerance of $10^{-92}$ for the following reasons: (contd) – user17762 Dec 4 '13 at 23:23

Using the identity stated in the question $$S_{\ell}(r) = \int_0^\pi\frac{\int_{\phi}^{\pi}(1 + r \cos \psi )^{\ell+1} d \psi}{(1+r\cos\phi)^{\ell}} d\phi \\ = \sum_{m=0}^{\ell+1} \frac{i^m (\ell+1)!}{(\ell+m+1)!} \frac{P_{\ell+1}^{m}(q)}{q^{\ell+1}} {\rm if}\left(m=0, \int_0^\pi \frac{\pi - \phi}{(1+r\cos\phi)^{\ell}}d\phi, -\frac{2}{m}\int_0^\pi\frac{\sin (m\phi)}{(1+r\cos\phi)^{\ell}}d \phi \right)\\ = \sum_{m=0}^{\ell+1} \frac{i^m (\ell+1)!}{(\ell+m+1)!} \frac{P_{\ell+1}^{m}(q)}{q^{\ell+1}} {\rm if}\left(m=0, \int_0^\pi \frac{\phi}{(1-r\cos\phi)^{\ell}}d\phi, -\frac{2}{m}\int_0^\pi\frac{\sin (m\phi)}{(1+r\cos\phi)^{\ell}}d \phi \right)$$ where $q=\sqrt{(1-r)/(1+r)}$, $P_\ell^m(x)$ are associated Legendre polynomials, and ${\rm if}(b,f,g)$ denotes the conditional function which takes the value $f$ if $b=$true, otherwise if $b=$false it takes the value $g$.

Denote the first and second integrals in the parenthesis by $I_{\ell 0}$ and $I_{\ell m}$. $$S_{\ell}(r) = \frac{P_{\ell+1}(q)}{q^{\ell+1}}I_{\ell 0}(r) - \sum_{m=1}^{\ell+1} \frac{i^m (\ell+1)!}{(\ell+m+1)!} \frac{P_{\ell+1}^{m}(q)}{q^{\ell+1}} \frac{2}{m} I_{\ell m}(r)$$ For the former see here $$I_{\ell 0}(r) = \int_0^\pi \frac{\phi}{(1-r\cos\phi)^{\ell}}d\phi =(1-r)^{-\ell} \left\{ 4\,a(q) [\chi_2(q) - {\rm arctanh(q)}\ln q] +b(q)\ln q + c(q)\right\}$$ where $q=\sqrt{(1-r)/(1+r)}$, $\chi_2(x)$ is the Legendre chi function, and $$a(q)=\sum_{K=0}^{\ell-1}\frac{q^{2K+1}}{4^{\ell-1}} \frac{(2K)!}{(K!)^2} \frac{[2(\ell-1-K)]!}{[(\ell-1-K)!]^2}\,,$$ $$b(q)=\sum_{K=0}^{\ell-2}\frac{q^{2K+2}}{4^{\ell-2}} \sum_{s=0}^{K}\frac{(2s)!}{(s!)^2}\frac{[2(K-s)]!}{[(K-s)!]^2} \sum_{j=K}^{\ell-2}\frac{[2(j-K)]!}{[(j-K)!])^2}\frac{[2(\ell-2-j)]!}{[(\ell-2-j)!]^2}\frac{2}{j-s+1}\,,$$ $$c(q)=\sum_{K=0}^{\ell-3}\frac{q^{2K+4}}{4^{\ell-3}} \sum_{J=0}^{K} \frac{4^{K-J}}{1+K-J} \sum_{s=0}^{J}\frac{(2s)!}{(s!)^2}\frac{[2(J-s)]!}{[(J-s)!]^2}\\ \quad\times \sum_{j=K}^{n-3}\frac{[2(j-K)]!}{[(j-K)!])^2}\frac{[2(\ell-3-j)]!}{[(\ell-3-j)!]^2}\frac{1}{\ell-1-j+s+K-J}\\ \quad+\sum_{K=0}^{\ell-3}\frac{q^{2K+2}}{4^{\ell-3}} \sum_{J=K}^{L-3} \frac{-4^{J-K}}{1+J-K}\sum_{s=0}^{K}\frac{(2s)!}{(s!)^2}\frac{[2(K-s)]!}{[(K-s)!]^2}\\ \quad\times \sum_{j=J}^{\ell-3}\frac{[2(j-J)]!}{[(j-J)!])^2}\frac{[2(\ell-3-j)]!}{[(\ell-3-j)!]^2}\frac{1}{\ell-1-j+s+J-K}\,.$$

For the other integral in $S_{\ell}$ we can use Chebysev polynomials as shown here. Explicitly, $$I_{\ell m}(r) = \int_0^\pi\frac{\sin (m\phi)}{(1+r\cos\phi)^{\ell}}d \phi \\ =\frac{-(-1)^m}{m (1-r)^{\ell}} + \frac{1}{m (1+r)^{\ell}} + \frac{\ell}{2}\sum_{k=0}^{[m/2]}\sum_{j=0}^{m-2k}(-1)^{k+m-j} \frac{(m-k-1)!}{k! j! (m-2k -j)!} \left(\frac{2}{r}\right)^{m-2k} X_{j-\ell}\\ = \sum_{j=0}^{m-1} \dbinom{m-1}j \left(\frac{2}{r}\right)^{m} \frac{X_{j-\ell+1}}{2} {}_2 F_{1} \left(\frac{1+j-m}{2}, 1+ \frac{j-m}{2}; 1-m; r^2\right)$$ where $${}_2 F_{1} \left(\frac{1+j-m}{2}, 1+ \frac{j-m}{2}; 1-m; r^2\right)=\\ = \frac{(m-j-1)!}{(m-1)!}\sum_{k=0}^{[(m-j-1)/2]} \frac{(m-k-1)!}{(-4)^k k!(m-j-1-2k)!} r^{2k}$$ and where $[m/2]$ is the integer part of $m/2$ and $$X_{0} = \ln \frac{1+r}{1-r},\quad X_{n\neq0} = \frac{(1+r)^{n} - (1-r)^{n}}{n}.$$

We can now address where the numerical inaccuracy comes from. The hypergeometric function $_{2}F_1$ in this case is a finite sum which varies monotonically between 0 and $1$ as a function of $j$ between $0$ and $m-1$. This is a well behaved term. The nastiness is due to $X_{j-\ell+1}$, which approaches $-(1-r)^{j-\ell+1}/(j-\ell+1)$. For $\ell=100$, $m\ll \ell$ and $r=0.8$ , $I_{\ell m}\sim 10^{68}$ due to this term. For $I_{\ell 0}$, we can verify that $\chi(q)$ is well behaved, it increases monotonically from 0 to 1.233 between $q=0$ and 1. Similarly $a(q)$ , $b(q)$, $c(q)$ are order unity. The large number here is due to the $(1-r)^{-\ell}$ factor. Interestingly, these factors add up to almost exactly cancel to give a small result for the integral.

I am not sure how to obtain $$\lim_{\ell\rightarrow \infty} \frac{S_\ell(r)}{\ell^{-1}\ln \ell}.$$

• In fact $\text{if}(~,~,~)$ is not the formal expression. Please clarify. – doraemonpaul Dec 7 '13 at 3:30
• @doraemonpaul: added definition of if( , , ) and the explicit closed form solution. The magical cancellation of large numbers is still unclear. – bkocsis Dec 17 '13 at 19:36