sum for sequences?

Albert van der Horst albert at
Tue Apr 6 15:39:38 CEST 2010

In article <559a2ee3-fb2c-477f-a444-7edbb6da8676 at>,
Patrick Maupin  <pmaupin at> wrote:
>On Mar 29, 10:29=A0pm, Steven D'Aprano
><ste... at> 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-
>> >> 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

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

Economic growth -- like all pyramid schemes -- ultimately falters.
albert at spe&ar& &=n

Economic growth -- being exponential -- ultimately falters.
albert at spe&ar& &=n

More information about the Python-list mailing list