How Can Tiny Rules Build Complex Worlds?

Page content

Cellular Automata From First Principles 00: How Can Tiny Rules Build Complex Worlds?

A cellular automaton begins with almost nothing.

You need:

  • a collection of cells,
  • a state for each cell,
  • a neighborhood,
  • and a rule that tells each cell what to become next.

That is enough.

There is no central controller.

There is no object that knows what the final pattern should look like.

There is only local state changing through time.

And yet local rules can produce stripes, fronts, oscillators, moving structures, traffic waves, cave systems, self-repairing patterns and systems rich enough to perform computation.

That is what makes cellular automata such a useful subject for programmers: they force us to study a deep engineering question in an unusually clean form.

How much global behaviour can emerge from repeated local decisions?

This book is going to answer that question by building the systems ourselves.


The smallest useful model

Imagine a row of cells.

Each cell is either off or on:

0 0 0 1 0 0 0

At the next step every cell examines itself and its immediate neighbors:

left | centre | right

The three bits form one of eight possible neighborhoods:

111
110
101
100
011
010
001
000

A rule assigns a new bit to each neighborhood.

That is the entire mechanism behind an elementary cellular automaton.

We can represent the global update as:

state_t
   |
local neighborhoods
   |
shared update rule
   |
state_t+1

The important phrase is shared update rule.

Every cell follows the same law.

Complexity does not come from giving every cell different code. It comes from interaction between identical local rules and different local states.


A cellular automaton has four parts

We will keep returning to four concepts throughout the book.

1. Space

The cells need somewhere to live.

That space might be:

1D line
2D square grid
hexagonal grid
3D lattice
graph
continuous field

Classical cellular automata usually use a regular discrete grid, but later we will relax almost every assumption.

2. State

A cell might contain one bit:

0 or 1

Or several discrete states:

empty
burning
burned

Or a vector of continuous values:

[r, g, b, alive, hidden_1, hidden_2, ...]

The last form will become important when we reach neural cellular automata.

3. Neighborhood

A cell cannot normally inspect the whole world.

It sees only nearby cells.

For a 2D grid two common neighborhoods are:

Von Neumann

  x
x o x
  x

and:

Moore

x x x
x o x
x x x

That locality is the constraint that makes the subject interesting.

4. Update rule

The rule maps local information to a new state:

new_state = rule(neighborhood)

Classical rules are handwritten.

Later we will make them stochastic, continuous and eventually learned.


Why programmers should care

Cellular automata sit at the intersection of several useful ideas.

Simulation

Local rules can model processes such as:

  • spreading fire,
  • traffic flow,
  • diffusion,
  • infection,
  • erosion,
  • crowd-like movement.

The goal is not always physical accuracy. Often the value comes from understanding what behaviour a simple interaction model can generate.

Procedural generation

Games and generative systems use cellular-style rules to create:

  • caves,
  • islands,
  • terrain masks,
  • textures,
  • rooms and corridors,
  • organic-looking boundaries.

A few smoothing rules can turn random noise into surprisingly plausible structure.

Emergence

Cellular automata make emergence visible.

Instead of saying that a system is “complex,” we can watch complexity appear generation by generation.

Computation

Some automata can support persistent signals and interactions between those signals.

This means the grid itself can become a computational substrate.

Artificial life

Later systems such as continuous cellular automata and neural cellular automata let us explore growth, persistence, regeneration and self-organisation.

That gives us a path from:

bit rule
  -> pattern
  -> moving structure
  -> computation
  -> self-organisation
  -> learned local behaviour

Build before theory

We are going to use Python because it lets us move rapidly between ideas and experiments.

Our first implementation will deliberately be small.

import numpy as np

state = np.zeros(41, dtype=np.uint8)
state[len(state) // 2] = 1

print(state)

That creates a one-dimensional world with one live cell.

The next chapter will give that world a rule.

We will not begin by building a framework.

We will not begin with inheritance hierarchies or plugin systems.

We will begin with the smallest possible transition function and earn the abstractions later.

That is important because cellular automata are fundamentally about the transition:

current local state -> next local state

If we understand that operation clearly, everything else becomes composition.


The progression of the book

The book will move through several layers.

Part I   discrete rules
         elementary CA
         Rule 30
         Rule 110
         Conway's Life

Part II  richer worlds
         multi-state rules
         stochastic systems
         forest fires
         traffic
         caves and terrain

Part III continuous systems
         smooth kernels
         Lenia-style dynamics
         artificial life

Part IV  learned rules
         differentiable CA
         neural cellular automata
         growth
         persistence
         regeneration

Part V   engineering
         vectorization
         GPU execution
         testing
         reusable simulation architecture
         experiments and projects

The destination is advanced.

The starting point is one bit.


One idea to keep

A cellular automaton is not interesting because each cell is clever.

It is interesting because each cell is not clever.

The power comes from repeated interaction.

That gives us the central idea for the entire book:

Complex behaviour does not require complex local behaviour.

In the next chapter we will prove that to ourselves by implementing an elementary cellular automaton from scratch.