Skip to content

Instantly share code, notes, and snippets.

@melopilosyan
Last active May 22, 2019 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melopilosyan/3c12d181faa2d8b521db3d09fa3a518a to your computer and use it in GitHub Desktop.
Save melopilosyan/3c12d181faa2d8b521db3d09fa3a518a to your computer and use it in GitHub Desktop.
Booleans are Easy - True or False?

Boolean Transformations

x || !x == true                         # Tautology
x && !x == false                        # Contradiction
true && x == x                          # Identity law
false || x == x                         # Identity law
true || x == true                       # Nullification law
false && x == false                     # Nullification law
x && x == x                             # Idempotent law
x || x == x                             # Idempotent law
x || y == y || x                        # Commutative law
x && y == y && x                        # Commutative law
x || (y || z) == (x || y) || z          # Associative law
x && (y && z) == (x && y) && z          # Associative law
(!x || !y) == !(x && y)                 # De Morgan's law
(!x && !y) == !(x || y)                 # De Morgan's law
x && (y || z) == (x && y) || (x && z)   # Distributive Law
x || (y && z) == (x || y) && (x || z)   # Distributive Law

De Morgan's Laws

(!x || !y) == !(x && y)
(!x && !y) == !(x || y)
x && y == !(!x || !y)
x || y == !(!x && !y)

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment