- ladder of abstraction
- show population bars
- show chart
- show multiple lines on chart
- show phase diagram
- show multiple lines on phase diagram

- intervention
- counterintuitive behavior
- intervene in either predator or prey, draggable dot over time + population
- phase space plot lotka-volterra will show old and new phase loop
- phase space plot with other model will show new phase loop settling back to old

- models
- lotka-volterra
- alpha: prey birth rate
- beta: proportional of prey eaten by predators
- gamma: death rate of malnourished predators
- delta: ?

- what else?
- three populations

- lotka-volterra
- implementation
- typed arrays
- webworkers to calculate in background
- canvas chart over time, maybe even pixel level drawing
- chart can be colored based on y < predator, y < prey, y < both, neither
- maybe blue, orange, white, black? or purple/green?
- color will then show which one dominates at a period in time
- this may not extend to three population model

- canvas chart for phase space
- this may not extend to three population model (webgl?)

- drawing pixel by pixel lets me put in gradients, dithering
- size the canvas based on the layout size, but need to handle rounding

- analytic

The wikipedia page^{[1]} has analytic formulas for the wavelength:

period T = 2π / sqrt(λ₁λ₂) λ₁ = i sqrt(α γ) λ₂ = -i sqrt(α γ)

This means period T = 2π / sqrt(α γ). Since I’m using α = 2/3, γ = 1, that means 7.695. *But neither my odex nor my heun integration matches*!! They’re not even close. It seems to be so close to 8.0 that I’m going to claim it’s exactly 8.

- Other pages
- https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations
^{[2]}- fixed point, other things I should consider - https://observablehq.com/@mbostock/predator-and-prey?collection=@observablehq/explorables
^{[3]} - https://www.petercollingridge.co.uk/blog/alife/ecosystem-simulation/basic-creature-simulation/
^{[4]}

- https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations

## 1 Numerical integration (move to separate page)#

Mike Bostock’s page uses https://github.com/littleredcomputer/odex-js^{[5]} for the differential equation solving. This library includes a predator-prey demo^{[6]}.

### 1.1 Performance

I’m going to assume Odex gives me the correct answer. The question is: can I get a reasonable approximation that runs faster? For a single run of predator-prey I think it doesn’t matter. The reason I’m curious about performance is that I’m interested in running *lots* of simulations. It’s nice to be able to set the parameters interactively and see the results, but that shows *one* at a time. To understand the space of possible solutions, I want to see *lots* of results simultaneously. See Bret Victor’s page about the Ladder of Abstraction^{[7]}.

Initial results: dumb integration is 10-100X faster than Odex.

### 1.2 Accuracy

Dumb integration is much faster than Odex but it’s not really stable.

{chart}

What happens here is that in each peak and valley of the curve, dumb integration overshoots. {sketch} This is because it uses the slope from the left side (tangent) instead of the combined slope from the left and right (secant). We can’t calculate the slope using the secant without knowing the value on the right. And we can only calculate the value on the right by using the slope. So we’re kind of stuck.

https://en.wikipedia.org/wiki/Predictor%E2%80%93corrector_method^{[8]}