I encountered a strange issue with the associated Legendre polynomials implemented with LegendreP[l,m,z]. Quite simply, the time used for the numerical computation of those quantities depends on whether m is odd or even :)
For m even and z a real number, LegendreP[l,m,z] evaluate in a few milliseconds quite consistantly across a wide range of order l. For m odd and z a real number, LegendreP[l,m,z] evaluate an order of magnitude slower and it gets worse with increasing order l.
I know that m odd means that LegendreP[l,m,z] involve the manipulation of square roots. If this is the reason, can anyone think of a workaround to get m odd evaluating as efficiently as m even ?
I use Mathematica 10.0.2 on Max OSX 10.10.4.
Thanks in advance.
time0 = Table[Timing[LegendreP[l, 0, 2.]][[1]], {l, 1, 100}]; time1 = Table[Timing[LegendreP[l, 1, 2.]][[1]], {l, 1, 100}]; time2 = Table[Timing[LegendreP[l, 2, 2.]][[1]], {l, 1, 100}]; time3 = Table[Timing[LegendreP[l, 3, 2.]][[1]], {l, 1, 100}]; Show[ListPlot[{time0, time1, time2, time3}, PlotLegends -> Automatic], PlotRange -> All]
{}button above the edit window. The edit window help button?is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful $\endgroup$