Engineering

Chimeric sorting

Classical sorting algorithms are usually written as something done to an array by an outside procedure. This model asks what happens if you give the array's elements autonomy instead: each cell is its own thread, sees only its immediate neighbours, and follows one local rule. Nobody is coordinating them.

What comes out is more interesting than a sorted list. Mixed arrays, where cells run different sorting rules, spontaneously segregate into contiguous bands of the same rule. Nobody told them to cluster. That is the phenomenon this page exists to let you watch.

A recorded run: 40 cells, three rules mixed, playing on a loop.

What you're looking at

Cell hueWhich rule the cell follows: steel is bubble, green is insertion, mauve is selection.
Cell brightnessThe cell's value. Brighter means larger.
HatchingA frozen cell. It cannot act, but an active neighbour can still displace it.
Red line segmentsSortedness falling — the array getting worse before it gets better.

What the paper found

Error resilience

Decentralised arrays sort more reliably than a top-down implementation when some elements malfunction or are frozen. A conventional sort has a single thread of control to lose; this one has as many as it has cells.

Delayed gratification

The array will temporarily make itself less sorted in order to navigate around a defect, then recover. Watch the sortedness chart for the red segments — those are the moments it is getting worse on purpose.

Chimeric emergence

When cells running different rules are mixed, same-rule cells cluster into contiguous runs. This is not in any cell's rule. It falls out of the interaction.

Run your own

Choose the number of cells, the mix of rules and how many cells to freeze, and watch what happens. Experiments run on the same small server as the rest of this site, so this needs a sign-in.

Sign in to run one

Every run anyone has done

Each experiment writes a summary here, so this table grows. Peak clustering is the highest aggregation the array reached at any point during the sort — the transient banding, not the final arrangement, which is fixed in advance by which rule each value happens to start with.

CellsFrozenRunsSettledMedian swapsAvg peak clustering
200%11/11050.85
500%11/15140.72

Diverse intelligence

Michael Levin is a biologist and cognitive scientist at Tufts and Harvard's Wyss Institute whose lab studies how intelligence shows up at every scale — bioelectric signalling in growing embryos, collective decisions in cell assemblies, hybrid biological–computational systems. The thread running through it is diverse intelligence: the idea that problem-solving, memory and goal-directedness are not exclusive to brains but arise in far simpler substrates.

The sorting paper sits squarely in that program. Give a humble bubble-sort cell autonomy and a local rule and it turns out to have rudimentary competencies — navigation, robustness, self-organisation — that we do not usually associate with if a[i] > a[i+1]: swap().

Credit

The model is from Classical Sorting Algorithms as a Model of Morphogenesis by Taining Zhang, Adam Goldstein and Michael Levin (arXiv 2401.05375). The original simulation code is Taining Zhang's, at Zhangtaining/cell_research.

I first built a visualiser for this in Python, Redis and React. This is a reimplementation of the simulation in Clojure so it runs inside this site, on the same server and the same database as everything else here. The engine was verified against the original by comparing the distributions both produce over many runs, since a model this nondeterministic cannot be checked by comparing outputs.