esolang

bff

Brainfuck with two heads and no I/O, poured into a soup of random tapes. Nobody writes a replicator; after thousands of collisions, one appears and takes over.

Blaise Agüera y Arcas et al., 2024 · Turing complete: with unbounded memory · ●●○ moderate

Tested with 1 known program · Test method

Run it

The idea

bff comes from the 2024 paper "Computational Life: How Well-formed, Self-replicating Programs Emerge from Simple Interaction" by Blaise Agüera y Arcas, Jyrki Alakuijala, James Evans, Ben Laurie, Alexander Mordvintsev, Eyvind Niklasson, Ettore Randazzo and Luca Versari.

Read the story

The question: do self-replicators need a designer, or a fitness function? Their answer is no. Take many tapes of random bytes. Pick two at random, glue them together, and run the result as a program that can read and write its own tape. Cut it apart again and put both halves back. Repeat. There is no selection anywhere, no reward, no seed.

For a long time nothing visible happens. Then, suddenly, one program that copies itself into its partner appears, and within a few hundred epochs it and its descendants fill the soup. The paper calls this a state transition.

bff is the language they used most: Brainfuck where the code, the data and both heads share one tape, and input and output are replaced by copying between the heads. They also saw replicators arise in Forth and in real Z80 and 8080 machine code, and, as a counterexample, never in SUBLEQ, whose smallest hand-written replicator is 60 bytes.

The machine

One tape of bytes (two glued 64-byte programs, so 128). An instruction pointer starts at 0, and two heads, head0 and head1, also start at 0. Of 256 byte values, 10 are instructions; everything else is a no-op.

ByteDoes
< >Move head0
{ }Move head1
- +Change the byte at head0
.Copy the byte at head0 to head1
,Copy the byte at head1 to head0
[ ]Brainfuck loops, testing the byte at head0

A run stops at an unmatched bracket, when the pointer leaves the tape, or after 2¹³ = 8,192 steps.

The paper's soup: 2¹⁷ programs of 64 random bytes, random pairs every epoch, and a tiny background mutation rate (0.024% of bytes per epoch). With those settings, about 40% of runs transitioned within 16,000 epochs, and about the same without any mutation.

Example

A hand-written replicator first.

A hand-written replicator first. This 64-byte program copies itself backwards into its partner, and since it is a palindrome, the backward copy is exact:

8192 steps
A: "{[.>{]                                                    ]{>.[{"
B: "{[.>{]                                                    ]{>.[{"

{ moves head1 back from 0 to 127, the last byte of the partner. Then [.>{] copies the byte at head0 to head1, moves head0 forward and head1 backward, and loops while head0 sees a nonzero byte. The spaces are bytes too (value 32), so the loop never meets a zero and runs until the step limit. The second half of the program is never executed; it is there so the mirror image comes out the same.

Now the real thing: a soup with no seed.

shib run bff -e 2 --mode soup --steps 70000000   # 8,192 programs, seed 2; about 5 minutes
epoch 0  compressed to 1.000  most common program x1: "                                        ,    > -                "
epoch 500  compressed to 0.937  most common program x1: "                                        ,    > -                "
...
epoch 15000  compressed to 0.903  most common program x1: "     <.       <                  >                            } "
epoch 15500  compressed to 0.316  most common program x75: " [[     {.,    >               ]]               >    ,.{     [[ "
takeover at epoch 15500

"Compressed to" is the size of the whole soup after zlib, relative to its raw size: random bytes do not compress (1.0), copies do. After an early dip to about 0.9 it barely moves for 15,000 epochs. Between epoch 15,250 and 15,500 it drops to 0.32. The most common program now has 75 byte-for-byte copies, and many more programs share its pattern of instructions. Only the instructions are shown; spaces stand for other bytes. Read its instructions backwards: they are the same. The soup found the hand-written replicator's mirror trick with no help.

The odds are low at this small size. With 8,192 programs and 16,000 epochs, 1 of the 4 seeds I tried transitioned (seed 2; two runs at the default mutation rate, two at 0.1%). With 4,096 programs, 0 of 6 did. The paper's soups are 16 times bigger. A smaller soup has fewer collisions per epoch, so expect a longer wait.

Patterns it teaches

  • Self-replication: replicators from nothing, with no fitness function.
  • Artificial life: the cleanest modern version of the "primordial soup" experiment.
  • Open-ended evolution: after the transition the soup keeps changing; the paper reports more complex dynamics, not a frozen end state.
  • Self-modifying code and code as data: a program can only copy itself because its code is bytes on the tape its heads walk over.
  • Every text runs: 246 of 256 byte values are no-ops, so random tapes mostly run harmlessly. Unmatched brackets are the one way to stop early.

Try this

  1. Replace the spaces in the hand-written replicator with zero bytes (edit the script, since a shell cannot pass them). Why does it stop copying, and what does the partner end up holding?
  2. Run shib run bff -e 3 --mode soup --steps 70000000 and shib run bff -e '2 8192 16000 0' --mode soup --steps 70000000 (no mutation). Does seed 2 still transition without noise? It need not: the noise also changes which programs meet.
  3. Hard: add a cheap rule that kills replicators (for example, zero a random tape now and then) and see whether the soup still transitions.

Further

  • Agüera y Arcas et al., "Computational Life: How Well-formed, Self-replicating Programs Emerge from Simple Interaction" (2024): arXiv:2406.19108
  • The authors' code is linked from the paper; it runs the full-size soup much faster than this script.
  • Brainfuck, the language bff is built on.

Also in Artificial life

Write your own in Run Convert a program from bff

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run bff -e '{[.>{]                                                    ]{>.[{' --input 'hello world'
shib manual bff

Source

Module
langs/museum/ports.js
Interpreter
langs/museum/bff.js, langs/museum/seed.js, langs/museum/push.js, langs/common.js

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