2
$\begingroup$

In my test, I found that the built-in function LegendreP of MMA is not as fast as the user-defined function. MMA should have already compiled and optimized the built-in function. Why is it not as fast as the user-defined function?

p[l_, x_] := 
 Sum[(-1)^k ((2 l - 2 k)!)/(2^l*k!*(l - k)! (l - 2 k)!) x^(l - 
      2 k), {k, 0, Floor[l/2]}]
(LegendreP[100, x] - p[100, x]) // FullSimplify
p[100, x]; // AbsoluteTiming
LegendreP[100, x]; // AbsoluteTiming
$\endgroup$
1
  • 2
    $\begingroup$ presumably because, as per the documentation, "LegendreP is defined to be Hypergeometric2F1Regularized[...]...". $\endgroup$ Commented Feb 27, 2020 at 2:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.