1

I would like to evaluate $$ f(x,y)=\sum_{i=1}^{N} X_i(x)\,Y_i(y) $$ where $X_i(x)$ and $Y_i(y)$ are known functions for all $i=1,\ldots,N$, and $x$ and $y$ are from the rectangle $[0,A]\times[0,B]$, $A,B>0$. The obvious thing to do is to pick say $M_x$ values of $x$ from the interval $[0,A]$ and $M_y$ values of $y$ from the interval $[0,B]$, then form two matrices $\boldsymbol{X}=\{X_{i}(x_j)\}$, $1\le i\le N$ and $1\le j\le M_x$, and $\boldsymbol{Y}=\{Y_{i}(y_j)\}$, $1\le i\le N$ and $1\le j\le M_y$, and finally multiply them as $\boldsymbol{X}^{\top}\boldsymbol{Y}$ or $\boldsymbol{Y}^{\top}\boldsymbol{X}$ using Mathematica's Dot function. The problem is that in my case $N=500$ and $M_x=M_y=10000$, and I would like the result to have 400 decimal places of accuracy. This seemingly simple task causes my Mathematica to pretty much freeze. Is there a way to overcome this somehow?

Alex
  • 755
  • 5
  • 12
  • If Mathematica freezes rather than just taking a long time to finish then it is probably a memory limitation. You may be able to overcome this by blocking your matrices, processing the blocks separately to limit memory consumption, and accumulating the partial results on disk. – Oleksandr R. Oct 31 '15 at 16:13
  • In any case, why not show your code (for a much smaller problem) and try to optimize there. – bill s Oct 31 '15 at 17:06
  • What you wrote does not look like an equivalent formulation. You are taking sums of products evaluated at different (x_j,y_k) pairs whereas the original tsk calls for evaluating a sum of X_iY_i at one fixed (x,y) pair. Supposing you want to set up a grid of 10^4x10^4 values, this should only require O(N(10^4)^2) operations, whereas the matrix product you propose would do O(N*(10^4)^3) ops. – Daniel Lichtblau Oct 31 '15 at 18:25
  • @DanielLichtblau Multiplication of a k by l matrix by an l by m matrix requires l multiplications and l-1 additions per entry, and times k*m entries. Where did you get the 3rd power from? – Alex Oct 31 '15 at 19:01
  • I probably misunderstood your specs. I thought both were 10^4x10^4. – Daniel Lichtblau Nov 01 '15 at 02:51
  • The problem still remains that you are going into some very large and time-consuming computations. Both arithmetic operations and size requirements are on the order of 10^(4+4+3). Bit complexity for the operations makes the speed aspect somewhat worse than that (ballpark two orders of magnitude). Add to that (no, actually multiply that by) the fact that you are in a realm where software arithmetic is necessary; that costs another order of magnitude in speed at a minimum, and more likely two orders. A 10^4x10^4 (dense) matrix is unwieldy on a desktop even with machine numbers. – Daniel Lichtblau Nov 01 '15 at 03:00

0 Answers0