On Wed, Feb 24, 2021 at 12:51:24PM -0500, Richard Damon wrote:
> Of the unary, python implements them all, the possible opererators for
> op a are:
>
> True
>
> False
>
> a
>
> not a
Those who have read my posts over the years will realise that I enjoy
being pedantic as much as the next guy, but the trick to being pedantic
is that you have to be *correct* in your pedantry :-)
The only operator in your list is `not`. True and False are values, not
operators: you can't say "True x" to ignore the value of x and return
True. And likewise `a` has no operator at all.
I'm sure that philosophers would like to debate whether the absense of
an operator counts as an operator, but from the point of view of a
programmer, it's hard to google for an operator that isn't there :-)
Of course, as you pointed out in another post, it's unlikely for any
practical programming language to define such operators, although that's
the sort of thing that esoteric languages might do. For the record, here
are the four unary operators defined as functions:
def contradiction(a): return False
def tautology(a): return True
def identity(a): return a
def negation(a): return not a
> Of the 16 binary operators a op b you can get:
[...]
There is no question that we can get the results of calling all sixteen
boolean operators, but whether Python defines them or not. Although I'll
grant you that using the comparison operators is a very nice trick,
e.g. using `==` to spell the "material biconditional" operator. I
totally forgot that you could do that, so thank you. I guess Python does
define more than `and` and `or` after all :-)
Speaking of esoteric languages, one can define the complete set of
boolean 1- and 2-argument operators using only two functions, plus a
third helper to display the results:
def true(x, y):
return x
def false(x, y):
return y
def print_bool(b):
print b("true", "false")
print_bool(true)
print_bool(false)
Using just those two functions, we can define all boolean operators.
def And(a, b):
return a(b, a)
def Or(a, b):
return a(a, b)
The others are left as an exercise :-)
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/CBP6VEZMULPKSQ2OFOSAQJTS425EIW6Y/
Code of Conduct: http://python.org/psf/codeofconduct/