Notes on computation and the natural world

The shape of a small world

What a simple simulation can teach us about patterns, patience, and the beauty of looking twice.

A model does not need to be complicated to reveal something true. Sometimes it just needs room to move.

There is a particular pleasure in watching a small world come to life. Not a world with grand laws or elaborate machinery, but one made from a handful of rules, a little time, and enough curiosity to see what happens next.

We will build one today. The ingredients are modest: a grid, a starting point, and a function that lets each point ask its neighbors what they are doing.

Start with a question

In mathematical language, we are looking for a field f(x,y)f(x, y) that changes smoothly across space. A useful way to think about that smoothness is the gradient:

∇f(x, y) =∂f∂x,∂f∂y

The gradient points toward change. Follow it, and you get a path through the landscape. Ignore it, and you might still find something interesting.

import numpy as np

size = 80
x, y = np.meshgrid(np.linspace(-3, 3, size), np.linspace(-3, 3, size))
field = np.sin(x * x + y * y) * np.exp(-.15 * (x * x + y * y))
print(f"peak: {field.max():.3f}")
using Statistics

samples = [2, 4, 8, 16]
println("mean: $(mean(samples))")
const line = d3.line()
  .x(d => x(d.day))
  .y(d => y(d.value));

svg.append("path").datum(data)
  .attr("d", line);
(ql:quickload :alexandria)

(defparameter *samples* '(2 4 8 16))
(format t "mean: ~,2f~%"
        (/ (reduce #'+ *samples*) (length *samples*)))

Patterns are patient

Run the cell, then change the numbers. The result is not a picture of the world; it is a question asked of the world. This is the quiet superpower of code: it gives an idea somewhere to go.

The best way to understand a system is to build a small one and watch it surprise you.

That surprise is the point. We make a small world, we give it a few rules, and then we pay attention. The rest is just iteration.

LM
Written by Leytzher Muro

Notes on the tools we use to think more clearly.