The Fredkin Gate

The Toffoli gate earns its keep by flipping a bit under a condition. Its great rival — proposed by Ed Fredkin — never flips anything at all. The Fredkin gate, or controlled-SWAP, only ever rearranges: one control bit c decides whether two data bits x and y pass straight through or trade places.

(c, x, y) \;\longmapsto\; \begin{cases} (c, x, y) & \text{if } c = 0 \quad \text{(straight through)}\\[2pt] (c, y, x) & \text{if } c = 1 \quad \text{(swapped)} \end{cases}

Think of a railway switch: two trains (the data bits) roll in on two tracks, and the signalman (the control) sets the points — either each train keeps its own track, or the tracks cross. No train is ever created, destroyed, or altered. Computation as routing — an idea this gate will carry all the way into the next lesson.

The truth table

Writing the outputs with conditional expressions, the middle output is c \mathbin{?} y : x and the last is c \mathbin{?} x : y. All eight rows:

cxy incxy outwhat happened
000000c = 0 — straight through
001001straight through
010010straight through
011011straight through
100100c = 1 — swap (nothing to see: x = y)
101110swap: the 1 moves to the other track
110101swap: the 1 moves back
111111swap (invisible again: x = y)

Every pattern appears once on the right: a permutation — in cycle notation the transposition (\,101\;110\,). And a swap done twice is no swap at all, so the Fredkin gate is self-inverse. But look closer at the table and a new property appears, one the Toffoli gate does not have: every output row contains exactly as many 1s as its input row. Of course it does — swapping two bits can shuffle the 1s between wires but can never mint or melt one. The Fredkin gate conserves the number of 1s, as if they were particles.

The circuit symbol

A filled dot on the control wire, a × on each of the two data wires, one vertical line through all three. Step the figure to see the two settings of the railway switch:

All of logic, from a switch and some constants

A gate that only reroutes sounds too polite to compute. It isn't — feed it constants, exactly as we fed the Toffoli gate an ancilla, and ordinary logic falls out of the routing. Write F(c, x, y) for the gate's three outputs and work each case from the rule "c = 1 means swap":

Check the AND case against the truth table if you like: F(1, 1, 0) is row 110 \to 101, third bit 1 = 1 \wedge 1; and F(1, 0, 0) is row 100 \to 100, third bit 0 = 1 \wedge 0. ✓

Both gates are 3-bit, self-inverse, single-transposition permutations, and both (as the theorem pane says, and the universality lesson proves) can build all of logic from constants. So why keep two? The difference is what they promise physics. The Toffoli gate changes the number of 1s in its word (row 110 \to 111 creates a 1 from nowhere), so a 1 cannot be a conserved physical object. The Fredkin gate never does — which means its 1s can be actual things: charge packets, billiard balls, photons in a rail, trains on a track. That single property opens the door to building logic out of collisions and routing alone, the "conservative logic" of the next lesson. Choose Toffoli and your hardware must make and unmake; choose Fredkin and it need only steer.

The classic slip with Fredkin embeddings is grabbing the wrong wire. In F(x, y, 0) it is the third output that carries x \wedge y; the middle one carries the less famous \bar{x} \wedge y. Swap the two constant positions — F(x, 0, y) — and the roles trade places: now the middle output is x \wedge y. There is no substitute for the two-line sanity check: set c = 0 (no swap) and c = 1 (swap), write out both output triples, and read off which wire behaves like the function you want. Ten seconds of table work beats a memorised formula you half-remember.