Gates of Gates

Gates of Gates

Each square belongs to one gate, G, sitting at its origin in the top-left corner. Along the x axis (left to right) are the 16 gates as the first input, X. Down the y axis are the 16 gates as the second input, Y. Each cell is G(X, Y): the gate you get by feeding X and Y into G, row by row of their truth tables. In lambda terms that is λp.λq. G (X p q) (Y p q). The result is always one of the same 16 gates.

Each cell shows its result's truth table as four squares: top row p = TRUE, bottom row p = FALSE; left column q = TRUE, right q = FALSE. Filled means TRUE. The example is Q, 1010.
Gates are numbered 0 to 15 in the same order as lambda16.txt and boolean16.py, so gate i and gate 15 − i are complements. Hover or tap a cell for the full result.
Axis order
Complement pairs: gates in the boolean16.py order, where gate i and gate 15 − i are complements. Axis numbers are the gate numbers.
Cells show

All 16 squares

Click a square to open it above as a full table with gate names on both axes.

The 506 programs

Every cell is itself a lambda term: λp.λq.λa.λb. G (X p q) (Y p q) a b, with the three gates' terms plugged in. Reducing all 4,096 of these terms gives 506 different normal forms. Each one behaves exactly like one of the 16 gates, so there are only 16 different behaviours, but 506 different programs that produce them.

4,096cell terms as written
506normal forms (different programs)
16behaviours (the gates)

For each gate, one program is exactly its term in lambda16.txt, marked below. 2,064 cells reduce to one of those; the other 2,032 reduce to a longer program with the same truth table. Programs are shown in short form, with the four inputs named p, q, a and b as in the file. Hover a cell above to see its program.

Patterns to look for

Every square makes one of four kinds of pattern, depending on how its gate uses the two inputs:

PatternGatesWhy
Blank or solidFALSE, TRUEthe output ignores both inputs
StripesP, Q, NOT P, NOT Qthe output follows one input
TrianglesAND, OR, NAND, NOR, p∧¬q, q∧¬p, p→q, q→peach is AND with its inputs or output flipped, so each square is AND's triangle reflected or inverted
CheckerboardsXOR, XNORthe output compares the two inputs: same or different

Checkerboards. XOR's pattern is spread across the four quarters of each cell, so look at one quarter at a time with the One quarter view. In one quarter, X's values run in stripes down the columns and Y's across the rows, and XOR is TRUE where a TRUE stripe crosses a FALSE one: a checkerboard. In Truth-table value order the four quarters are checkerboards with squares 8, 4, 2 and 1 cells wide. In complement order the rows and columns are shuffled, so the same crossing looks like plaid. XNOR is the same with TRUE and FALSE swapped. XOR and XNOR are also Latin squares: every row and column contains all 16 gates exactly once. XOR's diagonal is all FALSE and XNOR's all TRUE.

Every cell was computed by lambda reduction, 16,384 reductions in all, and each one agrees with plain bitwise arithmetic on the truth tables. The patterns described here, including the four checkerboards, the Latin squares and the triangle family, were each checked across all cells before the page was built.