esolang

Wireworld

A cellular automaton that is secretly an electronics kit: draw wires, send electrons, build gates, and eventually a computer.

Brian Silverman, 1987 · Turing complete: yes · ●○○ easy

Tested with 1 known program · Test method

Run it

Three loops, each with one electron, are three clocks. Every lap sends a pulse down its wire; the longer the loop, the slower the beat.

The idea

Brian Silverman devised Wireworld in 1987, as part of his program Phantom Fish Tank. A. K. Dewdney made it widely known in his "Computer Recreations" column in Scientific American in January 1990.

Read the story

It is a cellular automaton with four states, designed so that signals behave like electrons in wires. What plays the role of the program is the circuit: the layout of wire you draw. Electrons are the data. The layout never changes; only the electrons move.

Because signals have a direction (a head followed by a tail), you can build diodes, clocks and logic gates with a few cells each. People have built whole computers from them. The best known, by Mark Owen and others, computes prime numbers and shows them on a display made of wire.

The machine

A square grid; each cell sees its eight neighbours (the Moore neighbourhood).

CellBecomes
EmptyEmpty, always
Electron head (H)Electron tail
Electron tail (t)Wire
Wire (#)Electron head, if exactly 1 or 2 neighbours are heads; otherwise wire

The tail is what gives a signal its direction: the cell behind a head is a tail, so it cannot turn back into a head in the next step. The "1 or 2" rule is what makes gates possible: a wire cell that sees three heads at once stays quiet.

Example

A diode: a wire with a one-cell gap, bridged by two 2-cell blocks.

A diode: a wire with a one-cell gap, bridged by two 2-cell blocks. The same diode twice: on the top the electron comes from the right, on the bottom from the left.

gen 0
          ##
 ######### ######Ht
          ##

          ##
 tH####### ########
          ##

gen 8
          t#
 ########H ########
          t#

          H#
 ########t ########
          H#

gen 16
          ##
 Ht####### ########
          ##

          ##
 ######### ########
          ##

At generation 8 the top electron has already crossed the gap, and it runs on to the left end. The bottom electron has reached the gap and split into two heads, one in each block. One step later the three cells on the far side of the gap (the wire and both blocks) all light up together, so the next wire cell sees three heads at once and stays wire. The signal dies. One shape, two directions, two outcomes: geometry alone makes a one-way valve.

Patterns it teaches

  • Cellular automata: a rule designed backwards from what it should simulate.
  • Turing completeness: gates plus wires plus memory loops, and you have a computer; the Wireworld computer is a complete, if slow, example.

Try this

  1. Make a loop of wire with one electron in it. That is a clock. What is its period, and how does it depend on the loop's length?
  2. Draw your own circuit in a text file and run shib run wireworld circuit.txt --input 12. Build an OR gate: two input wires merging into one.
  3. Hard: build an XOR gate. Hint: use the "three heads stays quiet" rule.

Further

Also in Artificial life

Write your own in Run Convert a program from Wireworld

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run wireworld -e ' tH##### ' --input '3'
shib manual wireworld

Source

Module
langs/museum/ports.js
Interpreter
langs/museum/wireworld.js, langs/common.js

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