MathGroup Archive 2008

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

Search the Archive

Re: Product

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87558] Re: Product
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Sun, 13 Apr 2008 03:30:22 -0400 (EDT)
  • Organization: University of Bergen
  • References: <ftmtsj$4lf$1@smc.vnet.net> <200804110956.FAA08319@smc.vnet.net> <ftq5gc$n1$1@smc.vnet.net>

Murray Eisenberg wrote:
> But of course Total is also redundant!  Plus @ {1,2,3,4}
> 
> So the issue is one of language design: when does a particular case of a 
> more general construction occur so frequently that a special function
> should be introduced for it.

Total[] and Accumulate[] are not completely redundant.  Total[] is 
faster than Plus @@ # &, and also less precise by default.  When using 
Total[] or Accumulate[], one has the option to choose between a faster 
and a more precise (Method -> "CompensatedSummation") summation method.

Personally I think that the *syntax* Total[list] provides nothing over 
Plus @@ list, so just because summation is a common operation, a new 
syntax should not be introduced for it.  In fact I would consider the 
introduction of too many redundant constructs bad language design.

Note that faster algorithms for special cases *can* be implemented 
without a new syntax/new function.  Mathematica does exactly this for 
many operations.  But the syntax Plus @@ list or FoldList[Plus, 0, list] 
cannot (should not?) be extended to allow for selecting between two 
algorithms just for the special case of summation.  Thus the 
introduction of Total[] and Accumulate[] was legitimate.  These two 
functions do not only provide a new syntax, but also new functionality.


> 
> Szabolcs Horv=E1t wrote:
>> Steven wrote:
>>> Silly beginner's question: is there a function to multiply all elements of a
>>> list, like Total does for addition?
>> No, there isn't.  But it would be redundant anyway because it is very
>> easy to build your own:
>>
>> In[1]:= Times @@ {1, 2, 3, 4, 5}
>> Out[1]= 120
>>
>> Look up Apply in the documentation.
>>


  • Follow-Ups:
  • References:
    • Re: Product
      • From: Szabolcs Horvát <szhorvat@gmail.com>
  • Prev by Date: Re: Tooltip with ListPointPlot3D
  • Next by Date: Re: Documentation - what is the big secret?
  • Previous by thread: Re: Re: Product
  • Next by thread: Re: Re: Product