0
$\begingroup$

I want to improve my code to make it working faster even for very large numbers.

fun[n_, a_, b_] := (
  low = n^a;
  low2 = n^b;
  p = Table[Binomial[n, x]*StirlingS2[a, x]*x!/low, {x, 1, a}];
  pp = Table[Binomial[n, x]*StirlingS2[b, x]*x!/low2, {x, 1, b}];
  ListPlot[{p // N, pp // N}, some options]
)

I know that I should use as many built-in functions as I can, so I made it. And also I should not repeat the same thing many times. I want to run this function for values like for example $n = 1000000, a = 800000, b = 800000$. Is it possible to improve the speed of the program? And is it possible to evaluate the function for such huge numbers in a reasonable time (for example less than 2 hours)? Maybe is any way to make working on tables faster?

$\endgroup$
  • $\begingroup$ Try p=Binomial[n,#] StirlingS2[a,#] #!/low/@Range[a], functional programming is often faster than procedural programming in Mathematica. (Map, that is /@, is functional and Table is procedural.) $\endgroup$ – C. E. Jul 11 '14 at 8:54
  • $\begingroup$ @Pickett Are you sure it works good, because when I used that it has problem to understand the sign # and no plot is generated, because the values are not evaluated correctly $\endgroup$ – Ziva Jul 11 '14 at 9:01
  • $\begingroup$ Sorry, there is a typo. It should be &/@Range[a]. Look up "pure functions" in the documentation. $\endgroup$ – C. E. Jul 11 '14 at 9:06
  • $\begingroup$ @Pickett Yes, I found this typo. Thanks, this modification really increased a little bit the speed, but still not enough for huge numbers. $\endgroup$ – Ziva Jul 11 '14 at 9:20
  • $\begingroup$ Do you have some small n,a,b and the picture,so that I can test my code? $\endgroup$ – Apple Jul 11 '14 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.