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?
p=Binomial[n,#] StirlingS2[a,#] #!/low/@Range[a]
, functional programming is often faster than procedural programming in Mathematica. (Map
, that is/@
, is functional andTable
is procedural.) $\endgroup$#
and no plot is generated, because the values are not evaluated correctly $\endgroup$&/@Range[a]
. Look up "pure functions" in the documentation. $\endgroup$