esolang

Bitwise Cyclic Tag

Two strings of bits. Read the front of one, maybe write to the back. That is the whole language, and it is universal.

r.e.s., 2005 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 2 examples and 2 known programs · Test method

Run it

Example

Expected output

101

Output


The idea

Tag systems are one of the oldest models of computation (Emil Post, 1920s). You have a queue of symbols. Each step, look at the front, delete it, and append something to the back that depends on what you saw. Cyclic tag is a simpler variant whose rules are used in a fixed rotation.

Read the story

Bitwise Cyclic Tag (BCT), designed in 2005 by the esolangs.org user r.e.s., squeezes cyclic tag into pure bits. Both the program and the data are bitstrings, and the program has only two commands. Any cyclic tag system can be rewritten as a BCT program, so BCT inherits their universality.

Cyclic tag also matters far outside esolangs. Matthew Cook's proof that the cellular automaton Rule 110 is universal works by showing that Rule 110 can run a cyclic tag system.

The machine

A program (a bitstring, read in a loop forever) and a data string (a bitstring that grows and shrinks).

CommandDoes
0Delete the leftmost data bit
1xIf the leftmost data bit is 1, append the bit x to the right end of the data

1x is one command that takes two program bits. The program pointer wraps around at the end, even in the middle of a 1x. The machine halts when the data string becomes empty.

Converting a cyclic tag system is mechanical: write each rule followed by ;, then replace 0 with 10, 1 with 11 and ; with 0.

Example

The cyclic tag rules "10, then nothing" become 11 10 0 0.

The cyclic tag rules "10, then nothing" become 11 10 0 0. Start the data at 1.

data     next command
1        11   front is 1: append 1
11       10   front is 1: append 0
110      0    delete
10       0    delete
0        11   front is 0: nothing          (the program has wrapped round)
0        10   front is 0: nothing
0        0    delete
(empty)       halt
Expected: spaces are comments
Expected: this one never halts: it cycles

The interpreter prints the data after each command, up to a step limit (default 20).

Checked examples

Example

Expected output

10

Output


Quirks

  • A run stops after 3,000,000 steps.

Try this

  1. Trace 00111 on data 101 by hand for eight commands, then check with the interpreter. Watch the wrap-around split a 1x across the end of the program.
  2. Find a program that makes the data grow forever.
  3. Convert the cyclic tag rules 011, 10, 101 to BCT and run them from data 1.

Patterns it teaches

  • Tag systems: the clearest small example. A queue, a rule table, and nothing else.
  • Turing completeness: universal through a chain of simulations, Turing machine → tag system → cyclic tag → BCT.
  • Cellular automata: the same cyclic tag machinery is what makes Rule 110 universal.
  • Turing tarpit: two commands over the alphabet {0, 1}.

Further

Queue-based

Write your own in Run Convert a program from Bitwise Cyclic Tag

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: bct.

Command line

shib run bct -e '0' --input '101'
shib manual bct

Source

Module
langs/classic.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org