MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Particular structure

Here is a solution, simpler than the one one I posted Re: Particular
structure[2] and that you report below.
It seems to hold out more hop of generalizing.


    x= y=Table[1,{400}];f=Plus;F= Times;

    Table[ReleaseHold[F@@#],{j, Length[y]}]&[

        {7.41 Second,Null}

    MaxMemoryUsed[ ]


As you note, the problem with using Outer is that a very large matrix is
constructed, using lots of memory, before the function F is used. The method
above, and my previous one, uses the fact that Table evaluates step by step,
building up a list of *values* of F[...], these may use much less memory
than the expressions F[...]. Of course if the values of F[...] were bigger
than the expression then nothing would be gained.
I have used Table for generating {f[..],f[...] ....} in case there is some
benefit here also, and for uniformity. We could use f[...]&/@x as in my
previous code.

Incidentally, the use of  Hold[ y[[i]] ] , and the subequent release with
ReleaseHold is to prevent Mathematica reacting to y[[i]] with a symbolic
input i,  it generates messages and this slows down the evaluation
considerable - even if we turn the messages off.

GENERAL PRINCIPLE: avoid messages if possible - even if you turn them off
they slow down evaluation.


Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Yas" <yast at> wrote in message
news:a8g36d$b2s$1 at
> Hi,
> Thanks to all the replies to the problem I posted earlier on achieving a
> particular structure. All the solutions provided deal with the problem
> adequately but because my lists are fairly large I find myself running
> out of memory. For example, using Outer on lists where x > 500 and y >
> 100 gets me into trouble very quickly. The other draw back is that the
> time for calculation gets long.
> In an effort to overcome these undesirable properties, Allan Hayes has
> suggested the following construct,
>    x = y = Table[i + 1, {i, 1, 400}]; f = Plus; F = Times @@ # &;
>     Table[Function[kk, ReleaseHold[#]][y[[i]]], {i, Length[y]}] &[
>        Hold[F][f[#, kk, z] & /@ x]]; // Timing
> {5.81667 Second, Null}
> This construct is more efficient than the ones I've constructed
> previously in that the MaxMemoryUsed is reduced by a whopping 93% and
> the time for evaluation reduced by half compared to those using Outer
> and Map[Map...
> I wonder if there are any other suggestions to speeding things up even
> more?
> Cheers
> Yas

  • Prev by Date: Re: problems with ContourPlot
  • Next by Date: Re: problems with ContourPlot
  • Previous by thread: Re: Particular structure
  • Next by thread: LiveGraphics 3D, Browsers and MacOS X