MathGroup Archive 2007

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

Search the Archive

Re: "Accumulate" in Mathematica 6

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82784] Re: "Accumulate" in Mathematica 6
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Wed, 31 Oct 2007 06:05:28 -0500 (EST)
  • References: <fg72li$kkr$1@smc.vnet.net>

Oskar Itzinger wrote:
> Very sadly, Mathematica 6 is not supported under Irix - so I can't play with
> it practically - but I noticed in the online
> 
> documentation that there is a new function "Accumulate[list]", defined to be
> equivalent to "Rest[FoldList[Plus, 0, list]]",
> 
> giving a list of the successive accumulated totals of the elements in
> <list>.
> 
> Funny. While it was considered obsolete and superseded by "FoldList" in
> Mathematica 2, Mathematica 1 (!) already did
> 
> have a function "Accumulate", defined as
> 
> Accumulate[f, g[e1, e2, e3, ...]] <==> g[e1, f[e1, e2], f[f[e1, e2], e3],
> ....]
> 
> so that
> 
> Accumulate[Plus, Range[5]] <==> {1, 3, 6, 10, 15}
> 
> However, "Accumulate" in Mathematica 1 clearly was not restricted to "Plus"
> but rather specifically intended for dealing
> 
> with functions that take exactly two arguments - so, I believe that
> "Accumulate" in Mathematica 6 is much less usable
> 
> than the former in Mathematica 1.
> 
> Maybe I'm missing something here - but what was the rationale behind
> re-implementing "Accumulate" in such a restricted
> 
> version now?

The old Accumulate[], as you described it, does exactly the same thing 
as FoldList[] (but the syntax is slightly different).

The new Accumulate[] is a specialization of FoldList[] with the function 
Plus.  I can only guess, but I think that it was introduced because it 
can be faster than the general FoldList[]:

In[6]:= Timing[Accumulate[Range[3000000]];]
Out[6]= {0.812, Null}

In[7]:= Timing[FoldList[Plus, 0, Range[3000000]];]
Out[7]= {1.766, Null}

The same question could be asked about the functions Total[] or Norm[]. 
  They are mostly redundant too.

-- 
Szabolcs


  • Prev by Date: Simplifying polynomial and rounding problems
  • Next by Date: Re: : Polar Plot
  • Previous by thread: Re: "Accumulate" in Mathematica 6
  • Next by thread: v6: Sloppy eps/pdf vector-format export compared to v5?