Boolean circuits: NAND gates, decision trees, a cycle of implications
Four identities from the Boole Lab library that you can see with the naked eye. Flip the inputs and watch the values flow through the gates, trees and graph — then prove each of these equations in Boole Lab, where the kernel from Lecture 3 checks the proof.
Notation as in Boole Lab: + is “or”, * is “and”, n(x) is the complement (negation), 1 is true and 0 is false. Two abbreviations: nand(x, y) = n(x * y), the Sheffer stroke, also written x | y, and ite(p, a, b) = p * a + n(p) * b (“if p then a, else b”). The browser computes every value on this page from the formulas, and at load it checks on all inputs that the drawn circuits, trees and graph compute exactly these formulas.
wire with value 1wire with value 0
Sh1: six NAND gates act as a wire
nand(nand(x, nand(nand(y, x), x)), nand(y, nand(z, x))) = y
(x | ((y | x) | x)) | (y | (z | x)) = y
The circuit of 6 NAND gates always returns y, whatever x and z are — it acts like a wire running from the input y. McCune, Veroff, Fitelson, Harris, Feist and Wos (Journal of Automated Reasoning 29, 2002) showed that this single equation, written with the Sheffer stroke, is an axiom for the whole of Boolean algebra: every law of Boolean algebra written with the stroke follows from it. Its length is 15 (8 occurrences of variables, 6 strokes and the equals sign), and no single axiom for the stroke is shorter. In Boole Lab you prove the converse: that Sh1 is a law of Boolean algebra.
The diagram is wide — scroll it sideways.
The two halves
Why: A * B = (n(x) + n(y)) * (n(y) + z * x). After expanding, the term n(x) * z * x is zero, and the sum of the others, n(x) * n(y) + n(y) + n(y) * z * x, is n(y) (absorption). Clicking the circle with an input’s value in the diagram also toggles that input.
Truth table
Four gates and a basis of two equations
nand(nand(x, y), nand(x, nand(y, z))) = x
(x | y) | (x | (y | z)) = xand commutativityx | y = y | xThis time 4 NAND gates form a wire from the input x: the half P = x | y computes n(x * y), the half Q = x | (y | z) computes n(x) + y * z, and their product is n(x). Together with commutativity, this equation is a basis for Boolean algebra in the language of the Sheffer stroke, of total length 18 (11 + 7), and R. Veroff (Journal of Automated Reasoning 31, 2003) showed that no basis of two equations is shorter.
The diagram is wide — scroll it sideways.
The two halves
Truth table
Swapping the order of tests
ite(p, ite(q, a, b), ite(q, c, d)) = ite(q, ite(p, a, c), ite(p, b, d))The left tree asks about p first and then about q; the right one the other way round. Both split the values of (p, q) into the same four regions and in each region end in the same leaf: p * q → a, p * n(q) → b, n(p) * q → c, n(p) * n(q) → d. That is why both sides equal the sum p * q * a + p * n(q) * b + n(p) * q * c + n(p) * n(q) * d. The leaves a, b, c, d can have any values — toggle them together with the tests, or click the nodes of the trees.
ite(p, ite(q, a, b), ite(q, c, d))ite(q, ite(p, a, c), ite(p, b, d))The four regions
Both sides
A solid line is the branch 1 (the test holds), a dashed one the branch 0; the bold path leads to the leaf that the tree returns.
The same test twice
ite(p, ite(p, a, b), ite(p, c, d)) = ite(p, a, d)In the branch p = 1 the second question about p already has a known answer, so the leaf b is unreachable; in the branch p = 0 the leaf c is unreachable. Removing the redundant tests leaves ite(p, a, d). Reduced ordered binary decision diagrams (ROBDDs; R. E. Bryant, IEEE Transactions on Computers C-35(8), 1986) test the variables in a fixed order, each at most once, and merge identical subtrees — and the size of such a diagram can depend very strongly on the chosen order of the variables.
ite(p, ite(p, a, b), ite(p, c, d))ite(p, a, d)A cycle of implications
(n(x) + y) * (n(y) + z) * (n(z) + x) = x * y * z + n(x) * n(y) * n(z)
(n(x) + y) * (n(y) + z) * (n(z) + w) * (n(w) + x) = x * y * z * w + n(x) * n(y) * n(z) * n(w)
The factor n(x) + y is the implication “if x then y”: it is false only when x = 1 and y = 0. In the cycle x → y → z → x a one therefore flows along the arrows and a zero against them: the product of all the implications equals 1 only when all the variables have the same value. Algebraically: expanding the product of n factors gives 2n choices (one term from each parenthesis), and every mixed choice contains some xi together with n(xi), so it is zero — only the two uniform choices remain.