MathGroup Archive 2007

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

Search the Archive

Re: "Accumulate" in Mathematica 6

  • To: mathgroup at
  • Subject: [mg82877] Re: "Accumulate" in Mathematica 6
  • From: Szabolcs Horvát <szhorvat at>
  • Date: Fri, 2 Nov 2007 03:27:03 -0500 (EST)
  • References: <> <fg9o2k$lv7$> <fgc95m$7ub$>

Oskar Itzinger wrote:
> Taken - so it's speed. Does that imply we can expect in the future a whole
> bunch of
> speed-optimized functions for doing a similar thing for, say, Times, Divide,
> or
> any other function one can dream of?
> BTW, your mileage may vary - but in my code I've certainly much more
> occasions to
> use Fold/FoldList with other functions than Plus [as per the new
> Accumulate]. So,
> since Fold/FoldList plays a reasonably important role in functional
> programming,
> wouldn't speeding *them* up be more useful in general than providing just
> individually
> optimized functions?

Speeding them up for the general case is probably not at all simple, 
otherwise it would have already been done.

Or do you mean that FoldList should check if its first argument is Plus, 
and switch to the fast algorithm used by Accumulate if necessary?  This 
might not be such a good idea, because Accumulate and 
Rest@FoldList[Plus, 0, #]& differ in more than just speed.  The fast 
algorithm used by Accumulate results in reduced precision, so Accumulate 
takes an (unfortunately undocumented) option Method that allows for 

In[1]:= x = ConstantArray[.1, 10^5];

In[2]:= Last@Accumulate[x]-10^4
Out[2]= -1.81899*10^-12

In[3]:= Last@Accumulate[x,Method->"CompensatedSummation"]-10^4
Out[3]= 0.

(example taken from the doc page of Total)

This option could not be included in the more general FoldList.


  • Prev by Date: Re: Re: datelistplot - log axis for values
  • Next by Date: Re: Mathematica 6 Graphics Options
  • Previous by thread: Re: Re: Re: "Accumulate" in Mathematica 6
  • Next by thread: Can you get a package back to a notebook easily?