efficient mathematica code to reduce computational time I have code to compute a sum over a product of two functions, and it is taking an unacceptably long time to calculate in Mathematica (a day). I am wondering if there is a mathematical way to restructure the problem that will reduce the computational time.  The sum I am trying to compute is
$$ \sum_{1 \leq i,j,k, l \leq 25} f(i,j,k,l)\cdot  g(i,l,t)$$
where $t = \{ x[-3.0], x[-2.9], x[-2.8], \ldots, x[6.0]\}$.
The code I am using in Mathematica is as follows:
Solve = ParallelSum[f[i_,j_,k_,l_]*g[i_,l_,t_],{i,1,25},{j,1,25},{k,1,25},{l,1,25}]

where t=Table[x,{x,-3,6,0.1}].

What are $f$ and $g$? Are they arrays of values that you are accessing, or are they functions that are evaluated at each call (and if so, how computationally difficult are they to compute)?
I don't really work with Mathematica, but I can give some general computational guidelines that you can implement. Right now, you are computing
$$\sum_{i,j,k,l} f(i,j,k,l)\cdot g(i,l,t)$$
so, for each of the $25^4$ quadruples $(i,j,k,l)$, you are making a call to both $f$ and $g$.  But $g$ doesn't change each time (since $g$ does not depend on $j$ and $k$). So you can instead compute
$$\sum_{i,l} \left( g(i,l,t) \cdot \left(\sum_{j,k} f(i,j,k,l) \right)\right).$$
This will help; you are now calling $f$ $25^4$ times still, but only calling $g$ $25^2$ times. If $g$ is an expensive function to compute, this will help a lot.
