From: Steven D'Aprano on
On Mon, 29 Mar 2010 23:55:55 -0700, Paul Rubin wrote:

> Steven D'Aprano <steven(a)REMOVE.THIS.cybersource.com.au> writes:
>>>>> ...
>>>> ...
>>> ...
>> "Obvious" doesn't mean you don't have to learn the tools you use....
>
> Geez you guys, get a room ;-). You're all good programmers with too
> much experience for this arguing over stuff this silly.

Yes Mum ;)


You're right of course. I spend too much time being this guy:

http://xkcd.com/386/

and not enough this one:

http://xkcd.com/167/


--
Steven
From: Steve Holden on
Steven D'Aprano wrote:
> On Mon, 29 Mar 2010 23:55:55 -0700, Paul Rubin wrote:
>
>> Steven D'Aprano <steven(a)REMOVE.THIS.cybersource.com.au> writes:
>>>>>> ...
>>>>> ...
>>>> ...
>>> "Obvious" doesn't mean you don't have to learn the tools you use....
>> Geez you guys, get a room ;-). You're all good programmers with too
>> much experience for this arguing over stuff this silly.
>
> Yes Mum ;)
>
>
> You're right of course. I spend too much time being this guy:
>
> http://xkcd.com/386/
>
> and not enough this one:
>
> http://xkcd.com/167/
>
>
Yeah, it can happen to all of us. I've certainly been "that guy" too.
But Steven, surely now it's time to *show us the squirrels*

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/
From: Mel on
Patrick Maupin wrote:

> 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????

floats are nasty -- as evidence the recent thread on comparing floats for
equality. People use floats when they have to. fsum exists because of
this:

mwilson(a)tecumseth:~$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from math import fsum
>>> a=(1.0e200, 156.0, -1.0e200)
>>> sum(a)
0.0
>>> fsum(a)
156.0


You could generalize sum, but after that, there's a case that even fsum
can't handle:


>>> ni=1.0e200+1.0j
>>> nj=1.0+1.0e200j
>>> ai=(ni, nj, 156.0+651.0j, -ni, -nj)
>>> sum(ai)
(-1+0j)
>>> fsum(ai)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float; use abs(z)
>>>


Mel.



From: Patrick Maupin on
On Mar 30, 8:53 am, Mel <mwil...(a)the-wire.com> wrote:
> floats are nasty -- as evidence the recent thread on comparing floats for
> equality.  People use floats when they have to.  fsum exists because of
> this:

....

I understand there are technical reasons for why math.fsum() exists.
I still think that whatever math.fsum() does should probably be a part
of sum().

Regards,
Pat
From: Albert van der Horst on
In article <559a2ee3-fb2c-477f-a444-7edbb6da8676(a)r1g2000yqj.googlegroups.com>,
Patrick Maupin <pmaupin(a)gmail.com> wrote:
>On Mar 29, 10:29=A0pm, Steven D'Aprano
><ste...(a)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...(a)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(a)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(a)spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst