Leibniz by example
1 Example:   the predator-prey equations
2 A guide to reading this example
3 Why Leibniz?
4 What else can you do with Leibniz?

Leibniz by example

Konrad Hinsen

Context predator-prey
uses functions/derivatives-ℝ→ℝ

Let’s start right away with an example, the explanations will follow in the next section.

1 Example: the predator-prey equations

The predator-prey equations, also known as the Lotka-Volterra equations, describe the dynamics of two interacting species in an ecosystem in terms of non-linear differential equations.

The two interacting time-dependent observables are the number of prey, prey : ℝ→ℝ, and the number of predators, predators : ℝ→ℝ. Although the number of individuals of a species is really an integer, it is taken to be a real number for the benefit of using differential equations. The two coupled equations for prey and predators are

pp1: 𝒟(prey) = (prey-growth-rate × prey) - (predation-rate × predators × prey)
pp2: 𝒟(predators) = (predator-growth-rate × predators × prey) - (predator-loss-rate × predators)

These equations are based on a few assumptions:
  • In the absence of predators, the prey exihibits exponential growth described by prey-growth-rate : ℝp.

  • The number of prey decreases by predation, which is predation-rate : ℝp times the number of encounters between individuals of each species. The latter is taken to be proportional to both prey and predators.

  • In the absence of prey, the number of predators decreases by starvation, described by predator-loss-rate : ℝp.

  • The number of predators grows with the availability of food, which, like predation, is proportional to both prey and predators with the proportionality constant predator-growth-rate : ℝp.

Context predator-prey-explanation
extends predator-prey

2 A guide to reading this example

3 Why Leibniz?

Compare the example in the first section with the beginning of the Wikipedia entry on the same topic, which uses traditional mathematical notation. If Wikipedia adopted Leibniz, what would it gain?

  1. A machine-readable version of the predator-prey equations, generated from the same input and therefore identical in content. You can look at it here. It’s an XML file, which your browser may not display nicely, but you can always download it and open it in a text editor. A Leibniz-aware solver for differential equations could read this file, prompt you for parameter values and initial values, and compute and plot a solution. And if you had two Leibniz-aware solvers, you could compare their output, knowing for sure that they work on the same equations. Better yet, they work on the same equations that you have read and understood while reading the explanation. No more mistakes in transcribing equations to code!

  2. A more precise notation. For example, in the Wikipedia text, it is not immediately clear that x and y are functions of time, whereas α, β, γ, δ are constants. In Leibniz, you have to say what each object is, and you get an error message if you try to take the derivative of something that is not a function. More generally, everything typeset on a blue background has been checked for consistency and completeness.

4 What else can you do with Leibniz?

This simple example doesn’t illustrate all the features of Leibniz. Moreover, Leibniz is far from complete at this time. Here are some things that you can do, or will soon be able to do, using Leibniz: