Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Pythonic use of logic

Name: Anonymous 2013-06-27 11:43

I have noticed a disturbing trend in the Python community. The basic rule of Python is that there should be only one way to do a thing, and there are several logical operators in use. The proper way to use logic in Python is to only use one operator. To replace them all, we should use the NAND operator ("|").

For instance, consider the statement W↔(X∧(Y∨¬Z)). It is an ugly mess! It uses four different operators when only one should suffice.

This can obviously be reduced to only three operators: (¬W∨(¬(X∧Y)∧¬(X∧¬Z)))∧(((X∧Y)∧(X∧¬Z))∨W)

But this is not nearly far enough. By using the simple rules (A∨B) = (A|A)|(B|B), (A∧B)=(A|B)|(A|B), and ¬A=(A|A) (which should be self-evident, use a truth table to verify), we can reduce this entire expression to a beautiful (((((W|W)|(W|W))|((((X|Y)|((X|(Z|Z))|(X|(Z|Z))))|((X|Y)|((X|(Z|Z))|(X|(Z|Z)))))|(((X|Y)|((X|(Z|Z))|(X|(Z|Z))))|((X|Y)|((X|(Z|Z))|(X|(Z|Z)))))))|((W|W)|(((((X|Y)|(X|Y))|(X|(Z|Z)))|(((X|Y)|(X|Y))|(X|(Z|Z))))|((((X|Y)|(X|Y))|(X|(Z|Z)))|(((X|Y)|(X|Y))|(X|(Z|Z)))))))|((((W|W)|(W|W))|((((X|Y)|((X|(Z|Z))|(X|(Z|Z))))|((X|Y)|((X|(Z|Z))|(X|(Z|Z)))))|(((X|Y)|((X|(Z|Z))|(X|(Z|Z))))|((X|Y)|((X|(Z|Z))|(X|(Z|Z)))))))|((W|W)|(((((X|Y)|(X|Y))|(X|(Z|Z)))|(((X|Y)|(X|Y))|(X|(Z|Z))))|((((X|Y)|(X|Y))|(X|(Z|Z)))|(((X|Y)|(X|Y))|(X|(Z|Z)))))))). This is much more in line with the spirit of python than using multiple things when a single, simple operator will suffice.

Name: Anonymous 2013-06-27 14:31

>>18
On the hardware level, going NAND-only makes economic sense - it's cheaper to produce ICs that only include one type of gate, and the NAND logical operation is the only one all others can be reduced to.

Name: Anonymous 2013-06-28 0:50

>>21

What about NOR?

Name: Anonymous 2013-06-28 1:01

>>25
NOR gates are indeed functionally complete as well. Still pure NOR logic they're mostly slower than NAND logic, thus the former is less prevalent.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List