bool behavior in Python 3000?
Rustom Mody
rustompmody at gmail.com
Wed Jul 11 07:35:49 CEST 2007
Considering bools as ints --
Pros: The ALU of any computer uses boolean gates to build an
arithmetic functions. Therefore considering the base type of ints and
bools to be (strings of) bits seems natural
Cons: This comes from the pioneering work of Dijkstra and his coworkers)
The distributive law (one of them) in boolean algebra looks like this:
a /\ (b \/ c) = (a/\b) \/ (a/\c)
which becomes simpler to read and type and more familiar as
a(b+c) = ab + ac
So far so good. However its dual is
a\/(b/\c) = (a\/b) /\ (a\/c)
which in arithmetic notation becomes
a + bc = (a+b)(a+c)
This is sufficiently unintuitive and unnatural that even people
familiar with boolean algebra dot get it (so Dijkstra, Gries etc
claim)
Boolean algebra is perfectly dual, arithmetic is not. That is why we
need logical connectives 'and' and 'or' and dont somehow fudge along
with + and *. Therefore True and False should belong with 'and', 'or'
and 0,1 should belong with +,*
More information about the Python-list
mailing list