Since any two boolean expressions with the same truth table are equivalent we
can enumerate all the boolean expressions of a given number of variables. For
instance with two variables, a and b there are four
different combinations of possible values (i.e. 22) In other words,
if we wrote out the truth table for an expression involving those two
variables we would need four rows. For instance here's the truth table
for a && b:
| a | b | a && b |
|---|---|---|
| false | false | false |
| false | true | false |
| true | false | false |
| true | true | true |
And since the value in each row of the final column is either true or false, there are only 24 possible unique truth tables. Thus any boolean expression of two variables must be equivalent to one of just sixteen distinct boolean expressions.
The table below shows the canonical form of those sixteen expressions with the corresponding final column from the truth table flipped into a row. If applicable, the “DeMorgan'd” column contains the equivalent obtained by applying one of DeMorgan’s Laws. Note also that some of the expressions don't actually use both variables; two of them don't use them at all! But these are all the possible truth tables for two-variable expressions. Thus if you ever have a boolean expression of just two variables that is more complicated than the expressions here, you can definitely simplify it as it must be equivalent to one of these.
| Expression | DeMorgan’d | a = false b = false |
a = false b = true |
a = true b = false |
a = true b = true |
Name |
|---|---|---|---|---|---|---|
false |
|
false | false | false | false | Contradiction |
a && b |
!(!a || !b) |
false | false | false | true | And |
a && !b |
!(!a || b) |
false | false | true | false | |
a |
|
false | false | true | true | |
!a && b |
!(a || !b) |
false | true | false | false | |
b |
|
false | true | false | true | |
a != b |
!(a == b) |
false | true | true | false | XOR (Exclusive Or) |
a || b |
!(!a && !b) |
false | true | true | true | Or |
!(a || b) |
!a && !b |
true | false | false | false | NOR (Not Or)* |
a == b |
!(a != b) |
true | false | false | true | Logical Equality or XNOR (Exclusive NOR) |
!b |
|
true | false | true | false | |
a || !b |
!(!a && b) |
true | false | true | true | |
!a |
|
true | true | false | false | |
!a || b |
!(a && !b) |
true | true | false | true | |
!(a && b) |
!a || !b |
true | true | true | false | NAND (Not AND)* |
true |
|
true | true | true | true | Tautology |
*Fun fact about NAND and NOR: all boolean operators can be built from some combination of NANDs or from some combination of NORs. In digital circuits (which are built out of “logic gates” that correspond to the basic boolean operators) this means that any computer circuit can be built entirely out of exclusively NAND gates wired together into an appropriate configuration or exclusively from NOR gates.