From murdoch at stats.uwo.ca  Mon Jan  9 03:34:33 2006
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Sun, 08 Jan 2006 21:34:33 -0500
Subject: [Rd] prod(numeric(0)) surprise
In-Reply-To: <43C1C973.8080702@zoo.ufl.edu>
References: <43C1C973.8080702@zoo.ufl.edu>
Message-ID: <43C1CBB9.7090307@stats.uwo.ca>

On 1/8/2006 9:24 PM, Ben Bolker wrote:
>    It surprised me that prod(numeric(0)) is 1.
> I guess if you say (operation(nothing) == identity
> element) this makes sense, but ??

What value were you expecting, or were you expecting an error?  I can't 
think how any other value could be justified, and throwing an error 
would make a lot of formulas more complicated.

> 
>     Looking in the code, this makes sense:
> basically (s=1; for i=0 to length(x),
> multiply s by x[i]) -- which comes out to 1.
> 
>    What *should* prod(numeric(0)) produce?
> I couldn't find the answer documented anywhere.
> 
>    (And how about sum(numeric(0))==0,
> which for some reason makes more intuitive sense
> to me, but is really exactly the same thing --
> consider exp(sum(log(numeric(0)))) ... ?)

That's a fairly standard mathematical convention, which is presumably 
why sum and prod work that way.

Duncan Murdoch



[Rd] prod(numeric(0)) surprise
Duncan Murdoch