memoize factorial example (was Re: decorators ?)
Fernando Perez
fperez528 at yahoo.com
Tue Dec 7 22:24:40 EST 2004
Terry Reedy wrote:
>
> "Daniel 'Dang' Griffith" <google0 at lazytwinacres.net> wrote in message
> news:1102458244.004fc0dc548f5536ec77f769e501ff1e at teranews...
>> But the factorial example on the wiki has a defect. It incorrectly
>> calculates factorial(0) as 0, when it should be 1.
>
> This is a matter of definition, and definitions apparently differ. fact(0)
> == 0 is a backward projection from the definition f(1) = f(2) = 1 in
> 1-based systems, which is the context for the rabbit problem in which the
> first year is year 1, not year 0. Disagreement is not defect.
No, fact(0)==1 simply because any proper definition of a factorial has to match
up with the gamma function (offset by one) at all non-negative integers. So
there's no room for any ambiguity here.
Regards,
f
More information about the Python-list
mailing list