Algorithm Search⌘K

Modelcore

Lotka-Volterra competition model

Also called competitive Lotka-Volterra equations.

Two species with logistic growth that reduce each other's growth, whose outcome depends on the competition coefficients.

The Lotka-Volterra competition model is a pair of logistic equations in which each species also lowers the growth of the other: N˙1=r1N1(1−(N1+α12N2)/K1)\dot N_1 = r_1 N_1 (1 - (N_1 + \alpha_{12} N_2)/K_1) and N˙2=r2N2(1−(N2+α21N1)/K2)\dot N_2 = r_2 N_2 (1 - (N_2 + \alpha_{21} N_1)/K_2). The outcome depends only on the carrying capacities and the competition coefficients. The two species coexist at a stable equilibrium when each species limits itself more than it limits the other. Otherwise one species wins, or the winner depends on the start. This is the model behind the theorem form of the competitive exclusion principle.

The machine

The state. N1(t)≥0N_1(t) \ge 0 and N2(t)≥0N_2(t) \ge 0 are the sizes or densities of two species that use the same resources.

The parameters. All are positive.

  • rir_i, in 1 per time: the growth rate of species ii when it is rare and alone.
  • KiK_i, in individuals (or density) of species ii: its carrying capacity when alone.
  • α12\alpha_{12}, without unit: the effect of one individual of species 2 on the growth of species 1, measured in individuals of species 1. α12=0.5\alpha_{12} = 0.5 means that two individuals of species 2 crowd species 1 as much as one individual of species 1 does. α21\alpha_{21} is the reverse.

The equations.

dN1dt=r1N1(1−N1+α12N2K1),dN2dt=r2N2(1−N2+α21N1K2).\frac{dN_1}{dt} = r_1 N_1 \left(1 - \frac{N_1 + \alpha_{12} N_2}{K_1}\right), \qquad \frac{dN_2}{dt} = r_2 N_2 \left(1 - \frac{N_2 + \alpha_{21} N_1}{K_2}\right).

The assumptions. Each species alone follows the logistic model. The competition is not explicit: the resources are not in the state, and each species feels the other only through a linear term in the per capita growth rate. The coefficients are constant. The populations are well mixed and large. Some books write β12\beta_{12} or a12a_{12} for α12\alpha_{12}, or put the coefficients in the form bij=riαij/Kib_{ij} = r_i \alpha_{ij}/K_i; this page uses the form above.

The isoclines. The per capita growth of species 1 is zero on the line L1:N1+α12N2=K1L_1 : N_1 + \alpha_{12} N_2 = K_1, and that of species 2 on the line L2:α21N1+N2=K2L_2 : \alpha_{21} N_1 + N_2 = K_2. The relative position of the two lines in the positive quadrant gives the outcome. Two numbers decide it:

  • Δ1=K1−α12K2\Delta_1 = K_1 - \alpha_{12} K_2. It is positive if species 1, when rare, can grow in a population of species 2 at its capacity K2K_2.
  • Δ2=K2−α21K1\Delta_2 = K_2 - \alpha_{21} K_1. It is positive if species 2 can invade species 1 at K1K_1.
  1. LV-COMPETITION-OUTCOME(K1, K2, α12, α21)
  2. 1Δ1 ← K1 - α12 K2 ▷ can species 1 invade species 2 alone?
  3. 2Δ2 ← K2 - α21 K1 ▷ can species 2 invade species 1 alone?
  4. 3if Δ1 > 0 and Δ2 > 0 then return "coexist at (N1*, N2*)"
  5. 4if Δ1 > 0 and Δ2 < 0 then return "species 1 wins"
  6. 5if Δ1 < 0 and Δ2 > 0 then return "species 2 wins"
  7. 6if Δ1 < 0 and Δ2 < 0 then return "bistable: the start decides"
  8. 7return "degenerate (an isocline passes through an equilibrium)"

The rule costs O(1)O(1) arithmetic operations. The growth rates r1r_1 and r2r_2 do not enter it: they change how fast the outcome comes, and the path, but not the outcome. The implementation checks the rule against RK4 runs from four start points for 30 random parameter sets.

What it counts

  • The four equilibria (0,0)(0, 0), (K1,0)(K_1, 0), (0,K2)(0, K_2) and, when it is positive, the coexistence point
N1∗=K1−α12K21−α12α21=Δ11−α12α21,N2∗=Δ21−α12α21.N_1^* = \frac{K_1 - \alpha_{12} K_2}{1 - \alpha_{12}\alpha_{21}} = \frac{\Delta_1}{1 - \alpha_{12}\alpha_{21}}, \qquad N_2^* = \frac{\Delta_2}{1 - \alpha_{12}\alpha_{21}}.
  • The stability of each equilibrium, and so the long-run outcome: coexistence, the exclusion of one species, or two outcomes that depend on the start.
  • The rate of approach, from the eigenvalues of the Jacobian.

Three examples. All have r1=r2=1r_1 = r_2 = 1 per unit of time.

K1K_1 K2K_2 α12\alpha_{12} α21\alpha_{21} Δ1\Delta_1 Δ2\Delta_2 outcome
100 100 0.5 0.5 50 50 coexistence at (66.67,66.67)(66.67, 66.67), eigenvalues −1/3-1/3 and −1-1
100 100 1.5 1.5 −50-50 −50-50 saddle at (40,40)(40, 40), eigenvalues 0.20.2 and −1-1; the start decides
100 80 0.6 1.5 52 −70-70 species 1 wins and goes to (100,0)(100, 0)

In the second case, the start (45,35)(45, 35) ends at (100,0)(100, 0) and the start (35,45)(35, 45) ends at (0,100)(0, 100). In the third case, species 1 wins from (1,50)(1, 50), although it starts 50 times rarer.

Relation to other models

  • Logistic growth. With N2=0N_2 = 0, species 1 follows the logistic model and goes to K1K_1.
  • Lotka-Volterra predator-prey. The same quadratic terms with opposite signs on the two species. The predator-prey model has neutral cycles; the competition model has no periodic orbits, because it is a competitive system in the plane (each species lowers the growth of the other), and in such a system every bounded solution tends to an equilibrium.
  • Resource models. In a model with explicit resources, such as consumers that eat from a pool that is renewed, the coefficients αij\alpha_{ij} come out of the overlap in the resource use, when the resources are fast and stay near their equilibrium. The Lotka-Volterra form is then a linear approximation near the equilibrium. The competitive exclusion principle page gives a resource model and its theorem.
  • More species. The generalized form N˙i=riNi(1−∑jαijNj/Ki)\dot N_i = r_i N_i (1 - \sum_j \alpha_{ij} N_j / K_i) for nn species, with αii=1\alpha_{ii} = 1, can have cycles and more complex behaviour for n≥3n \ge 3. For two species, the outcome is always one of the four cases above.
  • Space and patches. In a landscape of patches, a weaker competitor that colonizes faster can persist next to a stronger one. The Levins metapopulation model is the one-species base of these models.

Known results in the model

The boundary equilibria. At (K1,0)(K_1, 0) the Jacobian is triangular, with the eigenvalues −r1-r_1 and r2Δ2/K2r_2 \Delta_2 / K_2. So (K1,0)(K_1, 0) is stable if Δ2<0\Delta_2 < 0 and a saddle if Δ2>0\Delta_2 > 0. By symmetry, (0,K2)(0, K_2) has the eigenvalues −r2-r_2 and r1Δ1/K1r_1 \Delta_1 / K_1. The origin has the eigenvalues r1r_1 and r2r_2, so it is always unstable.

Proof for (K1,0)(K_1, 0). The partial derivatives of N˙2\dot N_2 at N2=0N_2 = 0 are ∂N˙2/∂N1=0\partial \dot N_2 / \partial N_1 = 0 and ∂N˙2/∂N2=r2(1−α21K1/K2)=r2Δ2/K2\partial \dot N_2 / \partial N_2 = r_2 (1 - \alpha_{21} K_1 / K_2) = r_2 \Delta_2 / K_2. The entry ∂N˙1/∂N1\partial \dot N_1 / \partial N_1 at (K1,0)(K_1, 0) is r1(1−2K1/K1)=−r1r_1(1 - 2K_1/K_1) = -r_1. A triangular matrix has its diagonal entries as eigenvalues. □\square

The coexistence point. If α12α21≠1\alpha_{12}\alpha_{21} \ne 1, the isoclines meet in one point (N1∗,N2∗)(N_1^*, N_2^*) given above. It is positive if and only if Δ1\Delta_1 and Δ2\Delta_2 have the same sign as 1−α12α211 - \alpha_{12}\alpha_{21}. The Jacobian there is

J∗=(−r1N1∗/K1−r1α12N1∗/K1−r2α21N2∗/K2−r2N2∗/K2),J^* = \begin{pmatrix} -r_1 N_1^*/K_1 & -r_1 \alpha_{12} N_1^*/K_1 \\ -r_2 \alpha_{21} N_2^*/K_2 & -r_2 N_2^*/K_2 \end{pmatrix},

with the trace tr⁡J∗<0\operatorname{tr} J^* < 0 and the determinant det⁡J∗=r1r2N1∗N2∗K1K2(1−α12α21)\det J^* = \frac{r_1 r_2 N_1^* N_2^*}{K_1 K_2}(1 - \alpha_{12}\alpha_{21}).

Proof. At the point, 1−(N1∗+α12N2∗)/K1=01 - (N_1^* + \alpha_{12} N_2^*)/K_1 = 0, so the derivative of N˙1\dot N_1 with respect to N1N_1 is −r1N1∗/K1-r_1 N_1^*/K_1 and with respect to N2N_2 is −r1α12N1∗/K1-r_1 \alpha_{12} N_1^*/K_1. The second row is the same with the indices swapped. The determinant is r1r2N1∗N2∗K1K2(1−α12α21)\frac{r_1 r_2 N_1^* N_2^*}{K_1 K_2}(1 - \alpha_{12}\alpha_{21}). □\square

So a positive coexistence point is a stable node (both eigenvalues are real and negative, because (tr⁡J∗)2−4det⁡J∗≥(J11∗−J22∗)2≥0(\operatorname{tr} J^*)^2 - 4\det J^* \ge (J^*_{11} - J^*_{22})^2 \ge 0 when det⁡J∗>0\det J^* > 0 and the off-diagonal entries have the same sign) when α12α21<1\alpha_{12}\alpha_{21} < 1, and a saddle when α12α21>1\alpha_{12}\alpha_{21} > 1.

The four cases. Let Δ1,Δ2≠0\Delta_1, \Delta_2 \ne 0.

  1. Δ1>0\Delta_1 > 0 and Δ2>0\Delta_2 > 0: then α12α21<1\alpha_{12}\alpha_{21} < 1, because K1>α12K2>α12α21K1K_1 > \alpha_{12} K_2 > \alpha_{12}\alpha_{21} K_1. The coexistence point is positive and every solution with N1(0),N2(0)>0N_1(0), N_2(0) > 0 tends to it.
  2. Δ1>0\Delta_1 > 0 and Δ2<0\Delta_2 < 0: every solution with N1(0)>0N_1(0) > 0 tends to (K1,0)(K_1, 0). Species 1 wins.
  3. Δ1<0\Delta_1 < 0 and Δ2>0\Delta_2 > 0: species 2 wins, by symmetry.
  4. Δ1<0\Delta_1 < 0 and Δ2<0\Delta_2 < 0: then α12α21>1\alpha_{12}\alpha_{21} > 1. The coexistence point is a positive saddle. Its stable manifold divides the open quadrant into two basins: one of (K1,0)(K_1, 0) and one of (0,K2)(0, K_2).

The condition of case 1 reads α21/K2<1/K1\alpha_{21}/K_2 < 1/K_1 and α12/K1<1/K2\alpha_{12}/K_1 < 1/K_2. The left side of the first inequality is the drop in the per capita growth of species 2 (divided by r2r_2) per individual of species 1, and the right side is the drop that one individual of species 1 causes to its own species (divided by r1r_1). So coexistence means: each species limits itself more than it limits the other.

Proof of case 1 by a Lyapunov function. Write ui=Ni−Ni∗u_i = N_i - N_i^*. Since K1=N1∗+α12N2∗K_1 = N_1^* + \alpha_{12} N_2^*, the first equation is N˙1=r1K1N1(−u1−α12u2)\dot N_1 = \frac{r_1}{K_1} N_1 (-u_1 - \alpha_{12} u_2), and the second is N˙2=r2K2N2(−u2−α21u1)\dot N_2 = \frac{r_2}{K_2} N_2 (-u_2 - \alpha_{21} u_1). Let

V=∑i=12wi(Ni−Ni∗ln⁡Ni),w1=α21K1r1,w2=α12K2r2.V = \sum_{i=1}^{2} w_i \left(N_i - N_i^* \ln N_i\right), \qquad w_1 = \frac{\alpha_{21} K_1}{r_1}, \quad w_2 = \frac{\alpha_{12} K_2}{r_2}.

Then V˙=∑iwiuiNiN˙i=−α21u1(u1+α12u2)−α12u2(u2+α21u1)=−(α21u12+2α12α21u1u2+α12u22)\dot V = \sum_i w_i \frac{u_i}{N_i}\dot N_i = -\alpha_{21} u_1(u_1 + \alpha_{12} u_2) - \alpha_{12} u_2 (u_2 + \alpha_{21} u_1) = -\left(\alpha_{21} u_1^2 + 2\alpha_{12}\alpha_{21} u_1 u_2 + \alpha_{12} u_2^2\right). This quadratic form is positive definite, because its discriminant is 4α122α212−4α12α21=4α12α21(α12α21−1)<04\alpha_{12}^2\alpha_{21}^2 - 4\alpha_{12}\alpha_{21} = 4\alpha_{12}\alpha_{21}(\alpha_{12}\alpha_{21} - 1) < 0. So V˙<0\dot V < 0 except at the coexistence point. Each term Ni−Ni∗ln⁡NiN_i - N_i^* \ln N_i tends to infinity as Ni→0N_i \to 0 or Ni→∞N_i \to \infty, so the sublevel sets of VV in the open quadrant are compact, and each solution stays in one of them. By the Lyapunov theorem with LaSalle's principle, each positive solution tends to the only point where V˙=0\dot V = 0. □\square

Proof of case 2. Here the line L2L_2 lies strictly below L1L_1 in the quadrant, because its intercepts K2/α21<K1K_2/\alpha_{21} < K_1 and K2<K1/α12K_2 < K_1/\alpha_{12} are both smaller. So the quadrant splits into three regions: AA below L2L_2, where both species grow; BB between the lines, where N1N_1 grows and N2N_2 falls; CC above L1L_1, where both fall. On the boundary of BB, the field points into BB: on L1L_1 (above L2L_2), N˙1=0\dot N_1 = 0 and N˙2<0\dot N_2 < 0; on L2L_2 (below L1L_1), N˙2=0\dot N_2 = 0 and N˙1>0\dot N_1 > 0. So a solution that enters BB stays there. In BB the solution is monotone in each coordinate and bounded, so it converges, and the limit is an equilibrium in the closure of BB with N1>0N_1 > 0. The only one is (K1,0)(K_1, 0). A solution in AA or CC is also monotone in each coordinate while it stays there. If it stays forever, it converges to an equilibrium in the closure of that region. For AA the candidates are (0,0)(0, 0) and (0,K2)(0, K_2), and both are impossible, because N1N_1 is positive and increasing. For CC the only candidate is (K1,0)(K_1, 0). Otherwise the solution enters BB. With N2(0)=0N_2(0) = 0, species 1 follows the logistic model to K1K_1. □\square

Proof of case 4. The saddle has a one-dimensional stable manifold: two solution curves that tend to (N1∗,N2∗)(N_1^*, N_2^*). One comes from the region near the origin and one from far away, along the isoclines. Together with the saddle they form a curve that splits the quadrant. On each side, the argument of case 2 applies to the region between the isoclines that touches the axis: the region near (K1,0)(K_1, 0) where N˙1>0>N˙2\dot N_1 > 0 > \dot N_2 traps solutions and sends them to (K1,0)(K_1, 0), and the region near (0,K2)(0, K_2) sends them to (0,K2)(0, K_2). A solution that is not on the stable manifold enters one of these two regions, because, as in case 2, it cannot converge to anything else while it is monotone. □\square

Speed of the outcome. The time scale of the final approach is set by the eigenvalue of the stable equilibrium closest to zero. In the coexistence example it is −1/3-1/3, so a small deviation decays like e−t/3e^{-t/3}, three times slower than in a single logistic population with r=1r = 1.

Degenerate cases. If Δ1=0\Delta_1 = 0 or Δ2=0\Delta_2 = 0, the coexistence point lies on an axis and merges with a boundary equilibrium. If α12α21=1\alpha_{12}\alpha_{21} = 1 and Δ1=Δ2=0\Delta_1 = \Delta_2 = 0, the two isoclines coincide and there is a whole line of equilibria. These cases need exact equalities between parameters, so small changes remove them; they are not robust predictions of coexistence.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

lotka_volterra_competition.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lotka-volterra-competition/. The authors are listed in prov/8SQFG6.jsonl.
"""The two-species Lotka-Volterra competition model.

    dN1/dt = r1 N1 (1 - (N1 + a12 N2) / K1)
    dN2/dt = r2 N2 (1 - (N2 + a21 N1) / K2)

All parameters are positive. a12 is the effect of one individual of
species 2 on species 1, in units of individuals of species 1, and a21 is
the reverse. The module classifies the outcome from the parameters,
gives the equilibria and their Jacobians, and integrates the model with
fixed step RK4 so that the tests can compare the two.
"""

import math


def field(n1: float, n2: float, p):
    """The vector field for p = (r1, r2, K1, K2, a12, a21)."""
    r1, r2, k1, k2, a12, a21 = p
    return r1 * n1 * (1.0 - (n1 + a12 * n2) / k1), r2 * n2 * (1.0 - (n2 + a21 * n1) / k2)


def outcome(p) -> str:
    """'coexist', 'species 1', 'species 2', 'bistable' or 'degenerate' from the invasion tests."""
    _, _, k1, k2, a12, a21 = p
    inv1 = k1 - a12 * k2  # @line L1
    inv2 = k2 - a21 * k1  # @line L2
    if inv1 > 0 and inv2 > 0:  # @line L3
        return "coexist"
    if inv1 > 0 and inv2 < 0:  # @line L4
        return "species 1"
    if inv1 < 0 and inv2 > 0:  # @line L5
        return "species 2"
    if inv1 < 0 and inv2 < 0:  # @line L6
        return "bistable"
    return "degenerate"  # @line L7


def interior_equilibrium(p):
    """(N1*, N2*) = ((K1 - a12 K2), (K2 - a21 K1)) / (1 - a12 a21), or None if a12 a21 = 1."""
    _, _, k1, k2, a12, a21 = p
    den = 1.0 - a12 * a21
    if den == 0.0:
        return None
    return (k1 - a12 * k2) / den, (k2 - a21 * k1) / den


def jacobian(n1: float, n2: float, p):
    """The Jacobian matrix of the field at (n1, n2)."""
    r1, r2, k1, k2, a12, a21 = p
    return (
        (r1 * (1.0 - (2.0 * n1 + a12 * n2) / k1), -r1 * a12 * n1 / k1),
        (-r2 * a21 * n2 / k2, r2 * (1.0 - (2.0 * n2 + a21 * n1) / k2)),
    )


def eigenvalues(m):
    """The two eigenvalues of a real 2 by 2 matrix, as complex numbers."""
    (a, b), (c, d) = m
    tr, det = a + d, a * d - b * c
    disc = complex(tr * tr - 4.0 * det) ** 0.5
    return (tr + disc) / 2.0, (tr - disc) / 2.0


def rk4(n1: float, n2: float, dt: float, steps: int, p):
    """The state after `steps` RK4 steps of size dt."""
    for _ in range(steps):
        k1 = field(n1, n2, p)
        k2 = field(n1 + dt * k1[0] / 2, n2 + dt * k1[1] / 2, p)
        k3 = field(n1 + dt * k2[0] / 2, n2 + dt * k2[1] / 2, p)
        k4 = field(n1 + dt * k3[0], n2 + dt * k3[1], p)
        n1 += dt * (k1[0] + 2 * k2[0] + 2 * k3[0] + k4[0]) / 6
        n2 += dt * (k1[1] + 2 * k2[1] + 2 * k3[1] + k4[1]) / 6
    return n1, n2


def lyapunov(n1: float, n2: float, p) -> float:
    """V = sum of w_i (N_i - N_i* ln N_i), w1 = a21 K1 / r1, w2 = a12 K2 / r2; it decreases when a12 a21 < 1."""
    r1, r2, k1, k2, a12, a21 = p
    e1, e2 = interior_equilibrium(p)
    w1, w2 = a21 * k1 / r1, a12 * k2 / r2
    return w1 * (n1 - e1 * math.log(n1)) + w2 * (n2 - e2 * math.log(n2))
test_lotka_volterra_competition.py 93 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/lotka-volterra-competition/. The authors are listed in prov/8SQFG6.jsonl.

import random

from lotka_volterra_competition import (
    eigenvalues,
    field,
    interior_equilibrium,
    jacobian,
    lyapunov,
    outcome,
    rk4,
)


def test_examples_of_the_page() -> None:
    p = (1.0, 1.0, 100.0, 100.0, 0.5, 0.5)
    assert outcome(p) == "coexist"
    e1, e2 = interior_equilibrium(p)
    assert abs(e1 - 200 / 3) < 1e-12 and abs(e2 - 200 / 3) < 1e-12
    ev = sorted(z.real for z in eigenvalues(jacobian(e1, e2, p)))
    assert abs(ev[0] + 1.0) < 1e-12 and abs(ev[1] + 1 / 3) < 1e-12
    n = rk4(5.0, 1.0, 0.05, 4000, p)
    assert abs(n[0] - 200 / 3) < 1e-6 and abs(n[1] - 200 / 3) < 1e-6

    q = (1.0, 1.0, 100.0, 100.0, 1.5, 1.5)
    assert outcome(q) == "bistable"
    e1, e2 = interior_equilibrium(q)
    assert abs(e1 - 40.0) < 1e-12 and abs(e2 - 40.0) < 1e-12
    ev = sorted(z.real for z in eigenvalues(jacobian(e1, e2, q)))
    assert abs(ev[0] + 1.0) < 1e-12 and abs(ev[1] - 0.2) < 1e-12
    a = rk4(45.0, 35.0, 0.05, 4000, q)
    b = rk4(35.0, 45.0, 0.05, 4000, q)
    assert abs(a[0] - 100.0) < 1e-6 and a[1] < 1e-6
    assert abs(b[1] - 100.0) < 1e-6 and b[0] < 1e-6

    s = (1.0, 1.0, 100.0, 80.0, 0.6, 1.5)
    assert outcome(s) == "species 1"
    c = rk4(1.0, 50.0, 0.05, 4000, s)
    assert abs(c[0] - 100.0) < 1e-6 and c[1] < 1e-6


def test_boundary_equilibrium_eigenvalues() -> None:
    # At (K1, 0) the eigenvalues are -r1 and r2 (1 - a21 K1 / K2).
    p = (0.7, 1.3, 100.0, 80.0, 0.6, 1.5)
    ev = sorted(z.real for z in eigenvalues(jacobian(100.0, 0.0, p)))
    assert abs(ev[0] - 1.3 * (1 - 1.5 * 100 / 80)) < 1e-12 and abs(ev[1] + 0.7) < 1e-12


def test_classification_matches_simulation() -> None:
    # Random parameters with seed 3; the outcome rule against RK4 from several starts.
    rng = random.Random(3)
    starts = [(1.0, 1.0), (10.0, 90.0), (90.0, 10.0), (150.0, 150.0)]
    seen = set()
    for _ in range(30):
        p = (rng.uniform(0.5, 2.0), rng.uniform(0.5, 2.0), rng.uniform(50, 150),
             rng.uniform(50, 150), rng.uniform(0.2, 1.8), rng.uniform(0.2, 1.8))
        kind = outcome(p)
        seen.add(kind)
        ends = [rk4(x, y, 0.05, 6000, p) for x, y in starts]
        k1, k2 = p[2], p[3]
        if kind == "coexist":
            e = interior_equilibrium(p)
            assert all(abs(u - e[0]) < 1e-3 and abs(v - e[1]) < 1e-3 for u, v in ends)
        elif kind == "species 1":
            assert all(abs(u - k1) < 1e-3 and v < 1e-3 for u, v in ends)
        elif kind == "species 2":
            assert all(abs(v - k2) < 1e-3 and u < 1e-3 for u, v in ends)
        elif kind == "bistable":
            # Each end is one of the two single-species states.
            assert all((abs(u - k1) < 1e-3 and v < 1e-3) or (abs(v - k2) < 1e-3 and u < 1e-3) for u, v in ends)
    assert {"coexist", "species 1", "species 2", "bistable"} <= seen


def test_lyapunov_function_decreases_in_coexistence() -> None:
    p = (1.0, 0.6, 100.0, 70.0, 0.4, 0.5)
    assert outcome(p) == "coexist"
    x, y = 3.0, 120.0
    v = lyapunov(x, y, p)
    for _ in range(300):
        x, y = rk4(x, y, 0.05, 2, p)
        w = lyapunov(x, y, p)
        assert w <= v + 1e-12
        v = w


def test_field_vanishes_at_equilibria() -> None:
    p = (1.0, 1.0, 100.0, 80.0, 0.6, 0.5)
    e = interior_equilibrium(p)
    for pt in [(0.0, 0.0), (100.0, 0.0), (0.0, 80.0), e]:
        fx, fy = field(pt[0], pt[1], p)
        assert abs(fx) < 1e-12 and abs(fy) < 1e-12

References

  1. Lotka 1925, the equations for species that compete for the same food
  2. Gause 1934, the competition equations and the experiments with two species of Paramecium and with yeasts
  3. James D. Murray, Mathematical Biology I, An Introduction, third edition, Springer, 2002, Chapter 3, Models for Interacting Populations (the section on competition models and the principle of competitive exclusion)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/8SQFG6/text.yaml