Re: Re: "Accumulate" in Mathematica 6
- To: mathgroup at smc.vnet.net
- Subject: [mg82949] Re: [mg82837] Re: "Accumulate" in Mathematica 6
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 4 Nov 2007 06:12:42 -0500 (EST)
- References: <200710301049.FAA20459@smc.vnet.net> <fg9o2k$lv7$1@smc.vnet.net> <200711011009.FAA07420@smc.vnet.net>
It is in the nature of things that specialized tools can be better optimized than more general ones. In particular, this is true of computer programs. As for usefulness: I will give just one example. This graphic represents one of the most important objects in mathematics. With[{m = 500, n = 20}, ListPlot[ Accumulate /@ Map[Prepend[#, 0] &, RandomReal[NormalDistribution[0, N[Sqrt[1/m]]], {n, m}]], Joined -> True, DataRange -> {0, 1}]] I think the speed of generating this alone justifies the existence of Accumulate. Andrzej Kozlowski On 1 Nov 2007, at 19:09, 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? > > Thanks. > > /oskar > > "Andrzej Kozlowski" <akoz at mimuw.edu.pl> wrote in message > news:fg9o2k$lv7$1 at smc.vnet.net... >> On 30 Oct 2007, at 19:49, 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? >>> >>> Thanks. >>> >>> /oskar >>> >>> >>> >>> >> >> You are missing just one thing - performance. Accumulate in this >> restricted sense is incredibly fast - and extremly useful. >> >> Andrzej Kozlowski >> > > >
- References:
- Re: "Accumulate" in Mathematica 6
- From: "Oskar Itzinger" <oskar@opec.org>
- Re: "Accumulate" in Mathematica 6