Newbie: Truth values (three-valued logic)

mgutierrez at mgutierrez at
Fri Jun 18 11:30:53 CEST 1999

In article <000201beb946$b9c99e00$969e2299 at tim>,
  "Tim Peters" <tim_one at> wrote:
> [Olaf Delgado]
> > ...
> > It came to my mind, though, that redefining negation alone will not
> > help. Next time I'll want to redefine 'and' and 'or'. So, unless
> > python 2 implements three-valued logic <hint, hint :)>, I'll have
> > to come up with a routine for myself to handle these truth values
> > consistently.
> Well, "and" and "or" do short-ciruit evaluation (i.e., they don't
> their right-hand operand at all if the value of their left-hand
> suffices to determine the result).  For that reason, they're more
> viewed as control structures than operators, and so unlikely to get
> up" to user intervention.
> But in the spirit of overloading "~" instead of "not", consider
> "&" and "|" instead of "and" and "or".  Then you can do whatever you
> If I were you I'd consider not overloading anything, and using ~ & |
> directly with a naming trick, like so:
> f, t, m = 0, -1, 42
> name = {0: 'false', -1: 'true', 42: 'maybe', ~42: 'maybe'}

"Not maybe" equals to "not".
Imagine this case:
Maybe, I'll go to the cinema tomorrow.
If you say, not "maybe, I'll go to the cinema tomorrow", then you are
saying not to go the cinema. Imagine:
Johan: Maybe, we could go to the cinema tomorrow.
Anthony: No
Johan : ok, let's go to the zoo, to see that python.

I'd propose another solution, if we currently have:

class a:
  def __init__():
  def __add__(c,d):

e=a(); f=a()
h = e + f

why not :
class a:
  def __or__(c,d):
  def __and__(e,f):

you could even include three logic behaviour in the operator,
so if c = true d= true then __or__ returns true if it has certain
if c = true d= false returns true if a random value is greater than
0.34 ,...


Sent via
Share what you know. Learn what you don't.

More information about the Python-list mailing list