# Memoization of built in function

What is the best way to let mathematica memoize built-in function like e.g.

SphericalHarmonicY[l,m,th,ph]


One possibility would be for sure:

 sphericalHarmonicY[l_,m_,th_,ph_]:= sphericalHarmonicY[l,m,th,ph]=SphericalHarmonicY[l, m, th, ph]


But is there some function that works like:

 Memoize[SphericalHarmonicY]


And I can still use the original definition and Mathematica will store the values in the memory and access already calculated values later on?

• Try looking up Once. Just make sure the values you want to memoize get Withed into the Once (otherwise it will just remember SphericalHarmonicY[l,m,th,ph] symbolically rather than any particular numeric value for it). – Sjoerd Smit Oct 9 '17 at 15:00
• I assume this question is mainly about improving performance, and Once hardly seems efficient to me. The speed-up is about half what you get with memoization (based on repeated evaluation at many different points), the initial overhead is significant, and it's not really easier to code.... – Michael E2 Oct 9 '17 at 16:39