[Python-ideas] PEP: Dict addition and subtraction
Guido van Rossum
guido at python.org
Fri Mar 8 19:07:45 EST 2019
On Fri, Mar 8, 2019 at 3:33 PM Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:
> Guido van Rossum wrote:
> > I guess this explains the behavior of removing results <= 0; it makes
> > sense as multiset subtraction, since in a multiset a negative count
> > makes little sense. (Though the name Counter certainly doesn't seem to
> > imply multiset.)
>
> It doesn't even behave consistently as a multiset, since c[k] -= n
> is happy to let the value go negative.
>
> > For sets,
> > union and intersection are distributive over each other.
>
> > Note that this is *not* the case for + and * when used with
> > (mathematical) numbers... So in a sense, SETL (which uses + and *
> > for union and intersection got the operators wrong.
>
> But in another sense, it didn't. In Boolean algebra, "and" and "or"
> (which also distribute over each other) are often written using the
> same notations as multiplication and addition. There's no rule in
> mathematics saying that these notations must be distributive in one
> direction but not the other.
>
I guess everybody's high school math(s) class was different. I don't ever
recall seeing + and * for boolean OR/AND; we used ∧ and ∨.
I learned | and & for set operations only after I learned programming; I
think it was in PL/1. But of course it stuck because of C bitwise operators
(which are also boolean OR/AND and set operations).
This table suggests there's a lot of variety in how these operators are
spelled:
https://en.wikipedia.org/wiki/List_of_logic_symbols
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190308/dcb3c67b/attachment.html>
More information about the Python-ideas
mailing list