Python's simplicity philosophy

Terry Reedy tjreedy at udel.edu
Fri Nov 14 13:17:36 EST 2003


"Douglas Alan" <nessus at mit.edu> wrote in message
news:lcvfpn46f6.fsf at gaffa.mit.edu...
> > Even without any algebra, any kid can tell you that 1 + 2 is the
same
> > as 2 + 1. Replace 1 and 2 by a and b and you get the same result.
>
> Yes, but they are still two *different* ways to to get to that
result.
> Starting with a and adding b to it, is not the same thing as
starting
> with b and adding a to it.

I disagree.  Number addition (like several other functions) is a bag
(multiset) reduction operator that reduces a (possibly empty)
collection of similar items to one of the same type.  Abstractly, the
reduction is simultaneous.  One appropriate notation for such
operators is a simple labelled loop (in 2D) containing the items to be
collected together.  In linear text, such loops can be represented by
matched symbols, such as ( ), [ ], { }, which then represent the
intersection of a closed loop with a 'too-narrow'  text band (which
thereby chops off the top and bottom of the loop).  When operands
scattered in the loop interior are projected down to a 1+D band for
text representation, they gain an ordering that is an artifact of that
limited representation.

(+ item item ...) and sum(item, item, ...) are both labelled loops
with items arbitrarily but necessarily ordered for linear text
representation.

>  It is only the commutative law of arithmetic,
>  as any good second grade student can tell you,
>  that guarantees that the result will be the same.

Well, second graders are mislead by the representation of an n-ary bag
operation with infix notation that implies binarity and order
relevance.  Learning about reduce should help one unlearn these
implications ;-).

Even with infix notation, there is a choice between making the default
interpretation be order relevance or order irrelavance.  If
mathematicians had made the second choice, therr would be no need for
a 'commutative law'  One would say that a+b == b+a because that is the
way it normally is, while a-b != b-a because of the OrderRelevance Law
of subtraction.

<  On the other hand, not all mathematical groups are albelian,
< and consequently, a + b != b + a for all mathematical groups.

Yes, there are order-relevant binary-only operations.  Number addition
is not one of them.

[Having written the above, I am less enthralled with the overloading
of '+' and operator.add to also mean ordered concatenation of
sequences.  The fact that operator.add becomes O(n**2) (usually
unnecessarily) instead of O(n) for such overloadings, to the point
that sum() specially excludes such overloadings for strings,
reinforces this doubt.  Perhaps there should be at least be an
operator.cat that would generalize ''.join(strseq)]

Terry J. Reedy








More information about the Python-list mailing list