# Fast approximate evaluation of Fourier-Legendre series

Suppose I know that a function from $$[0,\pi] \to \mathbb{R}$$ may be written as

$$\sum_{k=0}^\infty A_l \frac{2l+1}{4\pi} P_l(r)$$

where $$A_l$$ all are known. Is there a way in which I may very quickly approximate the value of the function? My naive implementation is very slow and also suffers problems with numerical issues stemming from adding the very small numbers for certain $$l$$ and $$r$$ to large numbers.

A package or something in whatever language, Python, Julia, Fortran, etc, anything goes really, would be really appreciated.

• Do you know the original function? Also, did you try computing the summation in reverse order? – nicoguaro Nov 26 '19 at 12:56
• nope, that's the point is that I only know the coefficients $A_l$, and yes, but the evaluation kind of breaks for large L – eja Nov 26 '19 at 12:57
• Does the problem for large $l$ arises from $A_l$ or $P_l$? – nicoguaro Nov 26 '19 at 14:56
• oh, sorry for being unclear. In my naive attempts, P_l becomes impossible to evaluate for large l, even without $A_l$. Moreover, it is very, very slow. I am going to have to evaluate it in several points on the interval $[0,\pi]$, and I have to include a lot of terms, so it will be less than efficient... – eja Nov 26 '19 at 15:41
• I think that those details might be important enough to be included in the question. Maybe what you need is a fast and reliable way of evaluating $P_l$ for large $l$. – nicoguaro Nov 26 '19 at 15:49