---
name: bdf2
description: "Follow the slow part of a stiff ordinary differential equation on a fixed grid while damping rapid transients. The second-order backward differentiation formula uses two consecutive states and one implicit solve per step. Start with one backward Euler step if only the initial state is given."
---

# Second-order backward differentiation formula (BDF2)

## 1. What this solves

A model with fast decay may need a tiny explicit step even when only its slow evolution matters. BDF2 uses the last two states and a new implicit slope to advance at second order. Fast decaying modes become small within a few steps. The method is L-stable in the multistep sense given below.

## 2. When to use

Use a smooth stiff ODE with unwanted fast damped modes, a constant grid, and a reliable endpoint solve. Supply $f(t,y)$ and a Jacobian or solver for the same residual. If you already have two states, they must lie one step apart and be accurate to $O(h^2)$ or better.

## 3. When not to use (and what to use instead)

| Situation | Use instead |
|---|---|
| Rough stiff decay or a robust first damping step | `backward-euler`. |
| Stiff problem with changing steps, requested tolerances, or dense output | `radau-iia-5` or a variable-step BDF implementation such as CVODE BDF. |
| Persistent conservative oscillations and long-time invariants | `implicit-midpoint` or `gauss-legendre-4` for canonical Hamiltonians. |
| Smooth nonstiff dynamics or explicit constraints | `rk4` or `dormand-prince-rk45` for the former, `rattle` for constrained conservative mechanics with constant masses. |

## 4. Algorithm

Let $y_-$ and $y$ be the states at $t-h$ and $t$. From $y_0$ alone, start by solving the backward Euler equation $y_1=y_0+h f(t_0+h,y_1)$. The error of that single startup step is $O(h^2)$, enough for second-order global convergence.

Set $a=y+(y-y_-)/3$, $c=2h/3$ and $t_1=t+h$. Solve

$$Y=a+c f(t_1,Y).$$

Start Newton at $Y=y$ and solve $[I-cJ_f(t_1,Y)]\delta=Y-a-c f(t_1,Y)$, then set $Y\leftarrow Y-\delta$. The starter uses the same solve with $a=y_0$, $c=h$. Shift the two-state history after a successful step. The reference accepts a small scaled Newton correction and reports nonfinite arithmetic, a singular matrix or exhausted iterations.

For $y'=\lambda y$ and $z=h\lambda$, the amplification roots satisfy $(3-2z)\rho^2-4\rho+1=0$. The roots satisfy the A-stability root condition for $\operatorname{Re}(z)\le0$, and **both** tend to zero as $|z|$ tends to infinity there. This is the L-stability claim for BDF2, expressed in terms of both multistep roots. A small sign change in a stiff component is compatible with rapid decay.

## 5. Parameters

| Parameter | How to choose it |
|---|---|
| Fixed nonzero step $h$ | Resolve the quantities of interest and compare at least two step refinements. The fixed-step coefficients depend on equal spacing. For changing steps use coefficients derived from the step ratio and a variable-step stability and error controller. |
| Newton tolerance and limit | For each component, let `scale` be its largest absolute value in the step input, the old iterate, and the updated iterate. Require that component’s correction to be at most `max(tol * scale, 4 * ulp(scale))`, where `ulp` is floating-point spacing. The reference defaults to `tol=1e-13` and allows 20 updates. Tighten the solve to check that time discretization dominates the error. |

## 6. Applying it to your code

Keep two accepted states as immutable history, and only overwrite them after an endpoint solve converges. Use an analytic or automatically differentiated Jacobian when available. Large systems need a linear solver suited to their structure. Use a properly started new history after a discontinuity or a change of fixed grid. Add the code comment `bdf2 v0.1.0, Hairer & Wanner (1996)`.

## 7. Verification

Create `port_adapter.py` with `start(fun, jac, t, y, h) -> y1` and `step(fun, jac, t, previous, current, h) -> y_next`. States and returned slopes are sequences, and `jac(t,y)[i][j]` differentiates equation $i$ with respect to component $j$. The time of `current` is `t`; the RHS for a BDF2 step is evaluated at `t+h`. Run `python <skill>/checks/check_port.py` from the adapter directory and show the output. Other languages can use `checks/cases.json` directly.

On your model check fixed-time errors under refinement, track the fast component over its first few steps, and compare with `backward-euler` at the same grid. Both methods can step over fast decay. The difference in order should appear on the slow component once the step resolves it.

## 8. Failure signatures

| Symptom | Likely cause |
|---|---|
| Order collapses after changing the step | Fixed-grid weights were applied to unequally spaced states, or the startup history is inaccurate. |
| A large stiff component survives startup | The starter or main step used an explicit slope, or Newton returned a poor root. |
| Small correction is hard to obtain | Check the Jacobian, variable scales, and whether the chosen step admits a useful nearby root. |

## 9. Files and commands

`reference/bdf2.py` contains the starter, step and fixed-grid iterator. `uv run examples/relaxation.py` compares BDF2 and backward Euler. `uv run verify/check_cases.py` checks second order, stiff decay, startup and BDF2 steps on mixed-scale states, and four broken ports. `uv run checks/make_cases.py` prints the fixture JSON.

## 10. Sources

- Curtiss and Hirschfelder introduce stiff equations and derive implicit backward-difference formulas, including the two-step one, for a scalar model equation. [Curtiss and Hirschfelder (1952)](https://doi.org/10.1073/pnas.38.3.235)
- Hairer and Wanner give the BDF root locus curves and show that the two-step formula is A-stable (Sect. V.1). [Solving Ordinary Differential Equations II (1996)](https://doi.org/10.1007/978-3-642-05221-7)
