where function[n] is defined as
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
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
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.