For an expression like
Max @ Table[f[i, j], {i, 1, 1000}, {j, 1, 1000}]
does Mathematica first materialize the entire 1000x1000 matrix and then compute the max on it, or is it capable of rewriting the expressions so as to incrementally perform the reduction (the equivalent of using two nested for loops in an imperative language), needing only O(1)
space?
If it only does the former, is there instead an alternate suggested approach to achieve result with O(1)
space only (using two For
constructs would work, but is quite clunky).