Boolean algebra: laws, normal forms and truth tables
Boolean algebra is algebra with two values, 0 and 1, and three basic operations: and, or and not. It describes logic, digital circuits, search queries and the conditions in every program. This page covers the laws, the normal forms, and how to simplify, with a truth-table generator to check every step.
On this page
Values and operations
A Boolean variable takes the value 0 (false) or 1 (true). The basic operations are defined by their truth tables:
| A | B | ¬A (not) | A ∧ B (and) | A ∨ B (or) | A ⊕ B (xor) | A → B (implies) | A ↔ B (iff) |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
Two rows deserve a second look. “Or” is inclusive: . And an implication is only false when is true and is false. “If it rains, the ground is wet” is not broken by a dry day without rain. You may see the same operations written as or for and, for or, and or for not, especially in circuit design.
A truth table for any expression
With variables there are combinations of values, and listing the expression’s value for each one settles every question about it. The generator below builds that table, with a column for each sub-expression so you can follow the evaluation. It also classifies the expression: a tautology is always 1, a contradiction always 0, and anything else is a contingency.
The expression it starts with is De Morgan’s law written as a single formula. Its final column is all 1s, which is exactly what it means for the two sides to be equivalent.
The laws
Every law below can be checked with a truth table, and each has a dual: swap ∧ with ∨ and 0 with 1, and you get another law.
| Law | “And” form | “Or” form (the dual) |
|---|---|---|
| Identity | ||
| Domination | ||
| Idempotence | ||
| Complement | ||
| Double negation | — | |
| Commutativity | ||
| Associativity | ||
| Distributivity | ||
| Absorption | ||
| De Morgan |
Most of these match ordinary arithmetic if you read ∧ as multiplication and ∨ as addition. Two don’t. Idempotence () has no arithmetic counterpart, and the second distributive law, , would say , which is false for numbers.
Worked example: simplifying with the laws
Simplify .
- Distributivity, read right to left: .
- Complement: , giving .
- Identity: .
Whatever is, the expression equals . Paste it into the generator to confirm: its minimal form is just A.
Normal forms
Every Boolean function can be written in two standard shapes.
- Disjunctive normal form (DNF) is an OR of ANDs: . To get it from a truth table, take one AND-term (a minterm) for each row where the function is 1, matching that row exactly, and OR them together.
- Conjunctive normal form (CNF) is an AND of ORs: . Take one OR-clause (a maxterm) for each row where the function is 0, ruling that row out, and AND them together.
Worked example: the majority function
“At least two of are 1” is true on rows 3, 5, 6 and 7 (writing the rows as binary numbers ). The canonical DNF has one minterm per true row:
Combining minterms that differ in one variable (rows 3 and 7 differ only in , so they merge into ) gives the minimal form
The generator finds this automatically with the Quine–McCluskey method: it repeatedly merges terms that differ in one variable to find the prime implicants, then picks the fewest of them that cover every true row.
CNF matters well beyond textbooks. SAT solvers, which decide whether a formula can be made true and power hardware verification, scheduling and package managers, take their input in CNF. Deciding satisfiability of CNF formulas was the first problem shown to be NP-complete.
Fewer operations are enough
A set of operations is functionally complete if it can express every Boolean function. {∧, ∨, ¬} is, because of the DNF construction. So is {∧, ¬}, because De Morgan gives . Remarkably, NAND alone is enough:
That is why a chip can be built from a single kind of gate. Check any of these identities in the generator: type A nand A or (A nand B) nand (A nand B).
References
- C. E. Shannon, “A symbolic analysis of relay and switching circuits”, Transactions of the AIEE 57(12), 1938. doi:10.1109/T-AIEE.1938.5057767
- E. J. McCluskey, “Minimization of Boolean functions”, Bell System Technical Journal 35(6), 1956. doi:10.1002/j.1538-7305.1956.tb03835.x
- G. Boole, An Investigation of the Laws of Thought, Walton and Maberly, 1854.
- “Boolean algebra”, Wikipedia.