Most efficient way of calculating a multidimensional complex function many times

The quickest thing you can try is using CommonSubexpressions and then F_cse(X, Y, T) = @cse 15*(T^2/2+1)*cis(T)*(1-X)*sin(X)*..., which will pull out repeated functions. Also, you can replace exp(im*T) with cis(T) [as @giordano says!] Doing this in test2 makes it about 5x faster.

But this still seems quite wasteful. At different values of i, you re-do a lot of the same exp(X) etc. calculations. Storing and re-using those might help a lot.

3 Likes