Question: How to fix for-loop slowdown

Hello,

     I have a very large expression I'm tring to average (by doing limit(1/L*int(<expr>,t=-L..L),L=infinty) ). However, given that this expression is so large (sum of 11k terms), I'm was looking for ways to speed up the calculation and use less RAM.

     I found that applying the lim@int seperately to each term of the sum helps. Also, since my integrand has various functions of other variables (eg. f(x), g(y), etc), Maple seems to go faster if I freeze those functions using frontend.

     However, the problem I'm running into is that, as I'm running through my for-loop to apply lim@int to each term, Maple starts running slower and slower, as well as taking more and more RAM. Additionally, it doesn't go to completion because it runs out of stack space.

     Is there an optimization trick to avoid this problem? I've tried garbage collecting after each iteration; that helps the RAM problem (at a cost of speed), but it still slows down over time.

      I've attached my code: MWE.maple. Fair warning: on a non-server computer, it is liable to run very slow.

Please Wait...