sum for sequences?

Albert van der Horst albert at spenarnc.xs4all.nl
Tue Apr 6 09:39:38 EDT 2010


In article <559a2ee3-fb2c-477f-a444-7edbb6da8676 at r1g2000yqj.googlegroups.com>,
Patrick Maupin  <pmaupin at gmail.com> wrote:
>On Mar 29, 10:29=A0pm, Steven D'Aprano
><ste... at REMOVE.THIS.cybersource.com.au> wrote:
>> On Mon, 29 Mar 2010 19:24:42 -0700, Patrick Maupin wrote:
>> > On Mar 29, 6:19=A0pm, Steven D'Aprano <st... at REMOVE-THIS-
>> > cybersource.com.au> wrote:
>> >> How does the existence of math.fsum contradict the existence of sum?
>>
>> > You're exceptionally good at (probably deliberately) mis-interpreting
>> > what people write.
>>
>> I cannot read your mind, I can only interpret the words you choose to
>> write. You said
>>
>> [quote]
>> See, I think the very existence of math.fsum() already violates "there
>> should be one obvious way to do it."
>> [end quote]
>>
>> If sum satisfies the existence of one obvious way, how does math.fsum
>> violate it? sum exists, and is obvious, regardless of whatever other
>> solutions exist as well.
>
>Because sum() is the obvious way to sum floats; now the existence of
>math.fsum() means there are TWO obvious ways to sum floats.  Is that
>really that hard to understand?  How can you misconstrue this so badly
>that you write something that can be (easily) interpreted to mean that
>you think that I think that once math.fsum() exists, sum() doesn't
>even exist any more????

To a mathematician sum(set) suggest that the order of summation
doesn't matter. (So I wouldn't use sum for concatenating lists.)
Harshly, sum() should be used only for operator + both associative and
commutative.

Now for floating point numbers the order of summation is crucial,
not commutative  (a+b)+c <> a+(b+c).
So the obvious thing for someone versed in numerical computing
do is looking whether sum() gives any guarantees for order and
whether there may be a special sum() for floating point.
(This is not very realistic, because such a person would have
skimmed the math library a long time ago, but anyway.)

Met vriendelijke groeten,
Albert van der Horst

--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst


--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list