[Python-Dev] Re: PEP 285: Adding a bool type

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Thu Apr 4 14:49:01 EST 2002


[GvR]
>The textbooks that say that a Boolean value does not support
>arithmetic operations.  In tis discussion several people have tried to
>argue for such bools and claimed that that is the textbook definition.

Textbooks on algebra usually define algebra as sets with certain operations
and certain rules.  They do not say what operations an algebra cannot have,
except in cases of theorems showing certain operations as incompatible.

Regarding Python bools as subtype of ints, the boolean algebra and the ring
of int arithmetic are not incompatible.  They are just completely
independent.  There will only be conflict if one tries to associate the
operators + - * with 'and' 'or', etc.

>
>> FWIW, I was talking about the text books students use to learn boolean 
>> algebra.
>
>I don't think Boolean algebra is a big subject.  I bet that most
>people only learn about it explicitly when they learn computer
>programming.

I think the textbook definition of algebra fits perfectly in this situation.
The set of all Python objects with the logical operators forms an algebra.
It is not boolean because the operators are not commutative, among others.
The operator.truth is a homomorphism of this algebra to a boolean subalgebra
on the set of two elements (previously 0 and 1, now False and True).  It is
a subalgebra since it is the range of 'not'.

BTW, many people mistake boolean algebra with two-element boolean algebra,
which is only its most trivial example.  The set operations (union, joint,
complement) on all subsets of a given set is a more generic example of
boolean algebra.

Huaiyu



More information about the Python-list mailing list