esolang

Nanopond

Tierra shrunk to one C file: a pond of 4-bit, Brainfuck-like genomes where replicators arise from random noise and then evolve.

Adam Ierymenko, 2005 · Turing complete: with unbounded memory · ●●○ moderate

The idea

Adam Ierymenko wrote Nanopond in 2005 as the smallest artificial-life system he could make that still did something interesting. It is one C file, a few hundred lines of real code. It is a system, not a language: the "programs" are cell genomes, and nobody writes them. The pond writes them at random.

Read the story

Every so often, Nanopond fills a random cell with a random genome and some energy. Almost all of these are junk. But now and then a random genome happens to copy itself into a neighbour. Ierymenko calls this random genesis. From then on, copiers spread, compete for space and energy, mutate, and evolve.

The instruction set is based on Brainfuck, and it is built to be exceptionless: no instruction can fail, and none has an operand that a mutation could break. Any sequence of 4-bit values runs.

The machine

The pond is a wrapping 2D grid of cells (800 × 600 by default). Each cell has some energy and a genome of up to 1,024 four-bit codons. The first codon is the cell's logo; execution starts after it.

Every tick, one random cell runs until it hits STOP or runs out of energy (one unit per instruction). Its VM has one 4-bit register, a pointer into its genome, a direction it faces, and an output buffer.

CodeNameDoes
0ZEROReset register, pointer and facing
1 / 2FWD / BACKMove the pointer
3 / 4INC / DECChange the register
5 / 6READG / WRITEGRead / write the genome at the pointer
7 / 8READB / WRITEBRead / write the output buffer at the pointer
9 / ALOOP / REPBrainfuck's [ and ], testing the register
BTURNFace the direction in the register
CXCHGSwap the register with the next codon, and skip it
DKILLWipe the neighbour I face, if allowed (a failed try costs energy)
ESHARESplit energy evenly with that neighbour, if allowed
FSTOPEnd execution

Reproduction. When a cell stops, if its output buffer holds anything, the buffer replaces the genome of the neighbour it faces, if it is allowed in. Access is allowed if the neighbour has no energy, or was a random cell (no parent), or its logo matches the register: a guess, like a password.

Mutation. Rarely, while a cell runs, its next instruction or its register is replaced by a random value. Because copying is something the cell does step by step, one such slip can cause a point mutation, a deletion, an insertion, or a duplicated stretch.

Example

A first try at a copier, written by hand (illustrative; it has a bug):

A first try at a copier, written by hand (illustrative; it has a bug):

ZERO        register, pointer and facing to 0
INC         register := 1, so the loop is entered (LOOP skips ahead when the register is 0)
LOOP
  READG     register := my codon at the pointer
  WRITEB    write it into the output buffer at the same place
  FWD       next codon
REP         back to LOOP while the register is not 0
STOP        whatever is in the buffer now goes into the cell I face

The loop copies codons until it copies a codon whose value is 0. But ZERO is codon 0, and it is the second codon of this very genome. So the "copier" copies its logo and one more codon, and stops. Fixing that (end on a different value, count instead, or never use ZERO) is the kind of puzzle evolution solves blindly. Run Nanopond and dump the genomes with the highest generation counts to see what it found.

Patterns it teaches

  • Self-replication: copying is an explicit read-genome, write-buffer loop.
  • Artificial life: energy, space, predation (KILL) and cooperation (SHARE) in under a thousand lines.
  • Every text runs: an exceptionless instruction set, so a mutation is never a crash.
  • Open-ended evolution: the author reports that the pond does not get stuck on one form as easily as other systems; that is a claim, not a measurement.

Try this

  1. Write a Nanopond genome by hand that copies itself, then count how many single-codon mutations still leave a working copier.
  2. Why does the logo-guess rule make "kin" possible? What does a cell gain by never guessing its own logo?

Further

Also in Artificial life