UT6: a six-symbol 2-tag system
A very small universal 2-tag system. This page explains it and runs its proven compiler.
Program inputs
Syntax
Declare registers and labelled blocks. The first label is the entry. A block can have several inc and dec actions, followed by a goto, a zero or positive branch with a fallback goto, or halt. Each action takes a separate machine step. At joins with overlapping incoming edges, the compiler records which edge was taken in a history register, which can make the queue grow quickly.
Syntax
Declare initial values with reg Y = 0. Each if X == 0: Y += 1 line occupies 24 sweeps. Separate multiple updates with commas. # starts a comment. The assembler reserves a zero-valued register when it needs a guard that always fires.
Use I, D, z, e, a, b. Whitespace is ignored.
Program execution
- Steps
- Sweeps
- Queue length
Macro queue
0 Even lane 1 Odd lane · A split color marks a flip.
Block roles and lane changes
| Block | Encoding | Lane in → out |
|---|
Counter encoding and commands
W = aaaeaeae. A register written W24+4v holds logical value v at a period boundary. The +4 gives it four halvings of room. Four doublings add one to the logical value. Inside a command sequence the queue shows the current physical exponent.
Each compiled command has two sweeps. On the first, lane 0 selects increment (four bs per W) and lane 1 selects decrement (one b per W). On the second, each selected b appends a W. An even run selects half on either lane. A singleton b flips the downstream lane and regenerates W if it is read on lane 0.
A zero guard combines these commands to leave another register unchanged, increment it, or decrement it if the tested register is zero.
How the clocks work
C₀, C₁, and so on label the clocks in queue order. The sweep number tells you which bit of each clock’s repeating pattern to expect. Every clock is processed on every sweep. Its current cell words encode the phase directly.
D₀ = DDez, D₁ = DDeze. A differentiator remembers its incoming lane.
I₀ = ezII, I₁ = eezII. An integrator remembers its outgoing lane.
Each subscript is the cell’s length parity. An odd cell flips the lane and an even cell passes it through. A clock starts with an even D bank followed by an I bank whose odd cells are placed to encode the pattern. Moving an odd cell can change future flips even if the overall parity stays the same on the current sweep.
The D and I banks cancel each other’s effect on the incoming signal. The seeded I cells add the scheduled flips. For the zero guard, the 12 two-sweep commands take 24 sweeps, then two cancelling command pairs pad the period to 32.
The outgoing lane equals the incoming lane XOR the scheduled bit. At the end of the sweep, the outgoing lane becomes the next cut. Cut 1 means the first symbol of the nominal queue has already been deleted.
Literal queue
Period checkpoints
FizzBuzz output
This run starts from the same queue and advances independently. The data run is stored as a power of two so even enormous queues can be swept.
1. Sweeps, lanes, and the “cut”
A 2-tag system reads the first symbol of a queue, deletes the first two, and appends a word at the back. Processing the whole queue once is a sweep. Because two symbols are deleted at a time, a sweep only reads every second symbol:
Step by step
s0 s1 s2 s3): reads s0, then s2 → finishes cleanly. The next sweep starts at index 0 (0 lane 0).s0 s1 s2): reads s0, then s2 deletes s2 plus the first symbol of the new output. That leftover bite is a cut: the next sweep starts 1 symbol in, reading odd positions (1 lane 1).In general, passing through an even-length block preserves the lane (0→0, 1→1), while an odd-length block flips it (0→1, 1→0). That bit (even or odd positions) is the only control wire in the machine.
2. Counters and clocks
A counter stores a number by repeating a tile W. There is no separate CPU executing instructions on it: a counter reacts directly to whichever lane sweeps over it, taking two sweeps (one command) to complete an update:
- Sweep 1 (choose direction): The incoming lane decides the sign: 0 lane 0 turns each
Wintobbbb(growing), while 1 lane 1 turns eachWintob(shrinking). - Sweep 2 (rebuild): Every pair
bbturns back into oneW, leaving either twice as manyWtiles (+1) or half as many (−1).
There is no “do nothing” command: every command must push every counter either +1 or −1. To hold a counter constant, we pair opposite commands: + − or − + cancels to 0, while + + gives +2 and − − gives −2.
Encoding the program in clock bitmasks
Between the counters sit clocks, alternating down the queue as C0 X C1 Y C2. Each clock stores a fixed, repeating bitmask of 0s and 1s (one bit per sweep) and XORs its current bit onto the passing lane. The whole program lives in these bitmasks: they decide which lane reaches each counter on each sweep.
+ or 1 = − from the lane it sees.Step by step
X and Y (sweep 1 of each command, starting on lane 0):X: −, Y: +): C0 flips 0→1 (X gets −), C1 flips 1→0 (Y gets +), C2 keeps 0.X: +, Y: −): C0 keeps 0 (X gets +), C1 flips 0→1 (Y gets −), C2 flips 1→0 so the sweep ends cleanly on lane 0.Together, Cmd 1 and Cmd 2 cancel out (− + on X, + − on Y). Adding a counter widens each sweep by one counter + one clock; adding more instructions lengthens the clocks’ repeating bitmasks.
Annex: how W = aaaeaeae implements ±1 in 2 sweeps
Exponent E is stored as 2E copies of W = aaaeaeae (always even input length 8 · 2E, so Sweep 1 never flips the lane). On Sweep 1 (W → b), each W outputs bbbb (×4) on lane 0 and b (×1) on lane 1, producing an even run of bs whenever E > 0. On Sweep 2 (b → W), any even run b2k turns into Wk on either lane without flipping it, giving E + 1 or E − 1.
3. Micro scale: branching with an underflow cut
So far, the clock bitmasks only play back a fixed, repeating script of + and −. How can the machine branch on a counter’s value? Through one special case: underflow.
Decrementing a counter at its minimum (E = 0, a single W1) turns it into a singleton b (odd length 1). The two sweeps handle this as follows:
- On Sweep 1 (
W → b):W1still has even length 8, so the lane does not flip yet, so downstream counters likeYstill execute their normal Sweep 1 sign. - On Sweep 2 (
b → W, pure reconstruction): ReadingX’s singletonbon lane 0 rebuildsW1and flips the lane to 1. Every other counter holds an even number ofbs, and even runs reconstruct identically on either lane, so the flip passesYunchanged and leaves as a sign-flip carry (a cut) into the next command.
Same two commands, both sweeps materialized (a 2-command probe)
Replay Cmd 1 and Cmd 2 from Section 2 when X starts at E = 0, now showing their Sweep 2 clock bits as well (all clocks keep on Cmd 1’s Sweep 2; C0 and C1 both flip on Cmd 2’s Sweep 2):
X at E = 0. A filled purple sign was inverted by the incoming carry.Step by step
C0 flips 0→1 (X gets − → becomes b1); C1 flips 1→0 (Y still gets +); C2 keeps 0.X’s singleton b1 is read on lane 0, rebuilding W1 and flipping 0→1; Y reconstructs harmlessly on lane 1 → exits with a sign-flip carry (1).C0 keeps 1 (X gets − instead of + → b1 again); C1 flips 1→0 (Y gets + instead of −); C2 flips 0→1.C0 flips 1→0 so X’s b1 is read on lane 0 (on lane 1, the cut would eat the lone b and destroy X), rebuilding W1 and flipping 0→1; C1 flips 1→0; Y reconstructs → exits cleanly on 0 (the carry is cancelled).With the carry, Y’s cancelling pair (+ −) turned into a doubling pair (+ +, net +2), while X, despite receiving − −, clamps at W1 (E = 0) both times. If X > 0, no underflow occurs and no carry is created, and C0/C1 flipping on Cmd 2’s Sweep 2 is a harmless no-op because X’s even run of bs reconstructs identically on lane 1 before C1 flips back to 0, so both commands cancel to 0.
Putting it together: the 12-command Guard gadget
One probe forces every other counter to move either +2 or −2 when X == 0. Running two probes back-to-back lets an unchanged counter move +2 then −2 (net 0), while an incremented counter moves +2 + 2 = +4 (and a decremented one mirrors it with −2 − 2 = −4). That’s why logical value v is stored at exponent 4 + 4v: the 4v matches the ±4 step size, and the +4 safety bias keeps non-tested counters at logical 0 safely above E = 0 so they never accidentally underflow during − steps in no-op pairs or probe halves. Four commands before and after the two probes strip and restore only X’s +4 bias, giving 12 commands (24 sweeps) in total. Because X has to sit at E = 0 for both probes, a guard cannot conditionally modify the counter it tests.
Below is a full trace of if X == 0: Y += 1 while a third counter Z stays unchanged:
| Cmd | Cut in | X (tested) |
Y (Y += 1) |
Z (unchanged) |
Cut out |
|---|
− sign inverted by an incoming cut of 1: the clock programmed the opposite sign.
4. Macro scale: how does the program counter advance?
The clocks only march forward in a fixed loop and can’t jump. So instead of moving a program counter inside the clocks, we store the program’s state in ordinary counters and run every guard in the program on every full clock cycle (a period), movfuscator-style.
Each state gets a state flag counter (0 = currently here, 1 = elsewhere), and each transition gets an edge latch counter (0 = chosen, 1 = idle). One period simulates one machine step in three phases:
-
Choose the edge
For each edge, temporarily bump
state_srcif its condition is false (for anX == 0test, bump unconditionally then undo viaif X == 0: state_src -= 1), run:if state_src == 0: edge_k -= 1
then undo the bump. Only the single enabled edge drops to
0. -
Execute the edge
Scan all edges; only the one with
edge_k == 0updates the state flags and data:if edge_k == 0: state_src += 1, state_dst -= 1, X += 1
-
Clear the latch
Every latch must return to
1for the next period. Because a guard can’t testedge_kto modifyedge_kitself, Clear runs Phase 1 in reverse fromstate_dstto reset the taken edge’s latch.
Annex: how the clocks are built from symbols
Each clock is L zeroed differentiators (DDez/DDeze) followed by L seeded integrators (ezII/eezII), where L is the power-of-two period (≥ 24 × #guards). Letting S be the 1-sweep shift operator over GF(2), (1 + S)L(1 + S)−L = 1 cancels on the incoming lane so flips pass unsmeared, while choosing L to be a power of two gives (1 + S)L = 1 + SL, making the seeded integrators emit an L-periodic bitmask m—giving outgoing lane lane_in ⊕ mt mod L.
5. Joins & exact repetition
Phase 3 (Clear) has to recognize which incoming edge just fired purely from the destination state and registers:
- Easy joins (free): One incoming edge, or two edges with disjoint post-conditions (e.g. one checked
X == 0, the other raninc XsoX > 0). - Ambiguous joins: Two edges can land in the same state with the same register values. Clear can’t tell which latch to reset unless we record which path arrived.
Recording ambiguous joins as a base-k stack
Suppose two edges, left and right, both arrive at join with X = 1. To remember which one arrived (even across loops), we keep a history counter and push a nonzero digit onto it: left pushes 2 and right pushes 1, updating history ← 2 · history + digit (in general, for k incoming edges indexed 0 ≤ i < k, edge i pushes k − i, giving k · history + (k − i)). Keeping the digit nonzero guarantees that every subsequent step in the chain enters with history > 0, cleanly separated from a fresh entry where history == 0.
Since a counter machine only has +1, −1, and == 0, multiplying by k is done with a scratch counter history_work (initially 0) in three steps:
- Drain old history: Each incoming edge redirects to its own private entry state and moves
historyintohistory_workone unit at a time untilhistory == 0. - Push the new digit: Enter a shared chain of k
inc historystates at offseti, soleft(i = 0) runs both increments (+2), whileright(i = 1) skips the first and runs one (+1). - Multiply back by k: While
history_work > 0, decrementhistory_workand loop back through all k increments onhistory. Whenhistory_work == 0, exit intojoin.
Why doesn’t this create new ambiguous joins? Every state inside the loop has at most two incoming edges separated by a clean zero/positive test (history == 0 vs. > 0, or history_work == 0 vs. > 0), and join itself now has a single incoming edge. The trade-off is that history grows by a factor of k each time an ambiguous join is crossed, which makes its exponential counter grow fast.
Halting as exact repetition
Eliminating ambiguous joins gives every step a unique predecessor, making the entire machine reversible. Pairing a forward copy of the machine with a backward copy then makes halting runs bounce in a bounded loop forever (forcing the entire queue to repeat identically), whereas non-halting runs that keep advancing (growing a register or crossing an ambiguous join) grow without bound and never repeat.