Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum > General > > "Slowdown of computation of multiple sums"

Post Reply:
Name:
Email Address:

Please send email when my message is replied to.

Url (optional):
Subject:
Message: view original message?
Attachment (optional):
Please answer this:1+1 =



Original Message (ID '162067') By Bill Simpson:
Sum[function[n],{n,min,max}] where function[n] is defined as function[n_]:=Sum[differentfunction[n,i,j,k],{i,imin,imax},{j,jmin,jmax},{k,kmin,kmax}] Now, when the sum over n is calculated, will it have to run internally in every term for every n all the summations over i,j,k which are in the definition of function[n]? Or will those sums be done at the beginning and then Mathematica will just insert values of n from nmin to nmax? Some of this is only approximately true and the precisely true answer is probably longer and more complicated than you want to see. If you define differentfunction[n_,i_,j_,k_]:=complicatedstuff; then the := tells Mathematica to not evaluate complicatedstuff when you define the function, but instead each time you actually use differentfunction[]. If the number of different n*i*j*k values that you will have is reasonably small, perhaps a few dozen or even up to a thousand, and the resulting evaluated complicatedstuff will be fairly small and simple then there is a way you can tell Mathematica to evaluate the function once for each specific combination of n,i,j,k and save that for future use. That is done this way differentfunction[n_,i_,j_,k_]:= differentfunction[n,i,j,k]= complicatedstuff; But that is still going to evaluate complicatedstuff once for each combination of n,i,j,k, it will use memory to store a copy of every one of these. So if you have millions of different combinations this may be a bad idea. You can Google for Mathematica memoization and read how and why this is sometimes effectively used. It is possible that there are other, perhaps even more effective, optimizations that can be done, but carefully not showing anyone what your calculation really is means that we are extremely limited in what we can confidently and correctly tell you.