On Fri, 05 Sep 2008 22:20:06 -0400, Manu Hack wrote: > On Fri, Sep 5, 2008 at 1:04 PM, castironpi <[EMAIL PROTECTED]> wrote: ... >>> >The reason sum([]) is 0 is that sum( [ x ] ) - x = 0. >>> >>> It doesn't make sense to me. What do you set x to? >> >> For all x. > > But then how can you conclude sum([]) = 0 from there? It's way far from > obvious.
I think Castironpi's reasoning is to imagine taking sum([x])-x for *any* possible x (where subtraction and addition is defined). Naturally you always get 0. Now replace x by *nothing at all* and you get: sum([]) "subtract nothing at all" = 0 I think that this is a reasonable way to *informally* think about the question, but it's not mathematically sound, because if you replace x with "nothing at all" you either get: sum([]) - = 0 which is invalid (only one operand to the subtraction operator), or you get: sum([0]) - 0 = 0 which doesn't involve an empty list. What castironpi seems to be doing is replacing "nothing at all" with, er, nothing at all in one place, and zero in the other. And that's what makes it unsound and only suitable as an informal argument. [The rest of this is (mostly) aimed at Mensanator, so others can stop reading if they like.] Fundamentally, the abstract function "sum" and the concrete Python implementation of sum() are both human constructs. It's not like there is some pure Platonic[1] "Ideal Sum" floating in space that we can refer to. Somewhere, sometime, some mathematician had to *define* sum(), and other mathematicians had to agree to use the same definition. They could have decided that sum must take at least two arguments, because addition requires two arguments and it's meaningless to talk about adding a single number without talking about adding it to something else. But they didn't. Similarly, they might have decided that sum must take at least one argument, and therefore prohibit sum([]), but they didn't: it's more useful for sum of the empty list to give zero than it is for it to be an error. As I mentioned earlier, mathematicians are nothing if not pragmatists. [1] Or was it Aristotle who believed in Ideal Forms? No, I'm sure it was Plato. -- Steven -- http://mail.python.org/mailman/listinfo/python-list