Step through the gadgets that embed Boolean circuits into the synchronous
majority rule on the square lattice. Every frame below is an exact state of the original
two-dimensional dynamics, checked against a direct simulation of the rule; the elementary pieces and the square blocks are the configurations drawn in the paper's figures. The circuit compiler lays any Boolean circuit out on the paper's grid of square blocks and gives
the configuration that evaluates it.
From The Two-Dimensional Majority Rule is P-Complete,
by Pedro Montealegre and Martín Ríos-Wilson (Facultad de Ingeniería y Ciencias,
Universidad Adolfo Ibáñez).
The rule and the code
The rule
Each cell is in state +1 or −1 and all cells update simultaneously. A cell adopts
the majority state of its four nearest neighbors and keeps its current state on a tie;
equivalently, it takes the strict majority of five votes, its own and its neighbors'.
Signals are times
A logical 1 is an early signal: the port is +1 at its reading time T. A logical 0 is
a late signal: the port is still −1 at T and becomes +1 by T + 2. A zero is a late
signal, not an absent source.
Reading the figures
All cells obey the same rule; colors only distinguish roles. Outlined cells are the
ports, and an output port is highlighted at its reading time.
+1, background
+1, signal
−1
port
Gadget
t = 0
Keyboard: ←→ step, Space play/pause,
Home/End first/last frame.
Initial configuration (t = 0) of this case:
Circuit compiler
Describe a Boolean circuit by its adjacency matrix, or as a list of gates.
The compiler lays it out on the paper's grid of square blocks and returns the exact initial
configuration of the majority rule that evaluates it.
Nodes
Adjacency matrix (a checked cell means: row feeds column)
Paste a 0/1 matrix
One row per line, entries separated by spaces or commas (JSON also works).
If the size changes, columns without incoming edges become inputs and the others gates;
then choose each gate type.
Syntax: inputs: a=1, b=0, c, then one gate per line such as
g = AND(a, b) or m = OR(g, c, a), and finally output: m.
Types: AND, OR, NOT, NAND, NOR, XOR, XNOR. Gates with more than two inputs are split into binary gates.
Inputs
Grid
Gate gi is computed by block (i, i) on the diagonal; its value travels east along
row i and south along column i. Each block reads a from the north and b from the west. Edge marks show the
value of each output for the chosen inputs (teal = 1). Select a block to see its cells at its reading time.
AND
OR
CROSS
DUP (west or north copy)
border: SRC, R0, R1, L0
Exact cells
Drag to move; zoom with the wheel or the − / + buttons. The amber square is the output port of
the last block, read at T; the outlined square is the fuse memory M. The spiral to the right of the last
block is the clock of the fuse, which burns one cell per step from its center.
Download
The RLE file and the 0/1 matrix hold the initial configuration (t = 0) for the chosen inputs,
on the n × n torus. In Golly the rule is B34/S234V, the strict majority of the cell and its four
neighbors. The matrix is the whole torus, with 1 for +1 and 0 for −1; row r and column c are the Golly cell
(c − n/2, r − n/2). Both files give the cells to read and their expected values: the output port at T and
T + 2, and the fuse memory M from T + 7 on.
How the compiler works
The circuit is first rewritten with AND and OR gates only: negations are pushed to the inputs, and XOR and XNOR
are expanded. The inputs, with their values, become constant gates g1, …, and the remaining gates
follow in order, each computed from two earlier ones. With m gates in all, the compiler builds the grid of the
paper's Lemma "grid": (m + 1) × (m + 1) square blocks of side k = 153.
Block (i, i) computes gi with an AND or an OR block, or copies a constant down from the top row.
Above the diagonal, column i carries values south; below it, row i carries them east. CROSS blocks let them
pass; a DUP block turns the value that gate gi needs into its row or column.
The top row and the left column are the border. The corner SRC holds the only source. The top-row blocks
send a constant down each column: R1 for 1, R0 for 0. The left-column blocks L0 send a 0 along each row.
Every block reads its inputs at the same time and answers 298 steps later; crossing into the next block takes
one more step. A 1 is a signal that arrives on time and a 0 one that arrives two steps late. The output of the
circuit leaves block (m, m) to the east at T = 302 + 2m · 299.
A temporal fuse then makes the result permanent. The output enters a short capped wire whose end feeds the
fuse, and the fuse is driven by a clock: a wire of T + 7 cells wound as a square spiral, with three empty rows
or columns between its turns. Each cell of the wire has exactly two neighbors on the wire and no other cell has
more than two, so the wire burns exactly one cell per step from its free end, at the center, and nothing grows
around it. When the burn reaches the fuse, at time T + 7, the fuse memory M keeps the output: +1 for a 1, −1 for
a 0, forever.
AND, OR, CROSS and the west duplicator are the four square blocks of the paper. This site adds the pieces that
the grid also needs, all built from the paper's duplicator without changing it:
duplicators whose ignored input enters a short capped wire, so that the neighbor's output is continued and
absorbed (the north input for a west copy, the west input for a north copy);
R1, the duplicator itself; R0, the duplicator with a south route two cells longer, so that its south copy is
a 0; L0, R0 reflected;
SRC, the duplicator fed by a short source just west of the grid, as in the paper's tests;
capped wires after the outputs of the last row and column.
The fuse and its spiral clock are those of the project's earlier compiler, attached after the output of the
last block.
For the chosen inputs, the page computes the exact evolution and checks that every block output carries its
value at its reading time. Every piece was also checked alone against a direct simulation of the rule, as were
complete grids with their fuse: all 970 monotone circuits with up to four gates, cell by cell, on the full
torus.
How the pieces fit
From gadgets to circuits
Wires and turns carry signals; the duplicator copies them; AND and OR compute. The crossover lets
two signals pass through one region, which is the central difficulty in two dimensions. Packed into
square blocks of side 153 with a common interface, the pieces tile a grid that evaluates any monotone
circuit: the paper's reduction from the monotone circuit value problem.
Reproducibility
The data in data/gadgets.js are produced by tools/build_data.py
from a copy of the project's generators (tools/generator/, with SHA-256 provenance).
The crossover, AND and OR are the configurations drawn in the paper's figures, read from the PDF by
tools/extract_figures.py; the build simulates the rule from their initial panels and
requires every panel of each figure to be reproduced exactly. For the other pieces it re-runs the
generators' own checks against a direct simulation of the majority rule. For the elementary pieces and
the fuse, it then simulates the rule again, independently, for every displayed frame
(all frames). It also checks the reading times and the output
values stated in the paper.
python3 -B tools/build_data.py # regenerate and verify the data
python3 -B tools/build_standalone.py # single-file version in dist/
The circuit compiler has its own tests. One checks every piece of the grid alone, and complete grids
for all 970 monotone circuits with up to four gates, against a direct simulation of the rule. Another
runs the page's compiler on example circuits, for every input assignment, with an independent
simulation of the rule on the full torus. Two scripts check downloaded files, in Golly and from the
0/1 matrix.
python3 -B tools/test_grid.py --direct # pieces and the 970 circuits, against the rule
node tools/test_grid.cjs --all # the page's compiler, with the fuse, on the examples and the 970 circuits
python3 -B tools/check_rle_golly.py --bgolly <bgolly> file.rle
python3 -B tools/check_matrix.py file.txt
Embed a gadget
Any gadget can be shown alone, for example inside another page, with
?embed=<gadget>. Optional parameters: case (such as
10 or early), t and autoplay=1.