1. What this solves
Use both endpoint slopes to advance a smooth time-dependent problem at second order. For a heat equation already discretized in space, this is the Crank–Nicolson time update. The method here takes the resulting ODE as input. Choice and implementation of a spatial discretization are outside its scope.
2. When to use
Use a fixed grid for a smooth ODE when an implicit endpoint solve and second-order accuracy suit the problem. A-stability is useful for diffusion, especially after the initial transient is resolved or damped. Supply the right-hand side and a Jacobian, or provide your own endpoint solver.
3. When not to use (and what to use instead)
| Situation | Use instead |
|---|---|
| Fast decay should disappear over a large step | backward-euler for rough results or startup damping, bdf2 for second-order fixed steps, or radau-iia-5 for adaptive high accuracy. |
| Symplecticity or exact quadratic invariants matter | implicit-midpoint or gauss-legendre-4 for canonical systems. |
| Smooth general nonstiff dynamics with tolerance control | dormand-prince-rk45. |
| Positive or TVD states are required | Use ssprk33 when forward Euler with your spatial operator preserves the property at a usable step. |
4. Algorithm
Advance from to by solving
Cache during the solve. Form and solve by Newton, starting at . Use the matrix , and subtract the computed correction. The update reverses when the endpoints swap and changes sign.
implicit-midpoint instead uses the single slope . They give identical steps for autonomous linear or affine systems . A time-dependent linear RHS can already give different steps, and nonlinear systems generally do. The trapezoidal map in the original coordinates is generally not symplectic and does not preserve quadratic invariants in general. The checker includes a nonlinear rotation that changes its squared norm under trapezoid while midpoint preserves it.
5. Parameters and stiff startup
Use a signed fixed step and check second-order accuracy at a common physical time. The dense reference bounds each Newton correction by max(tol * scale, 4 * ulp(scale)). For each component, scale is its largest absolute value in the step input and the old and updated iterates, and ulp is floating-point spacing. The default is tol=1e-13 with up to 20 updates. A singular matrix, nonfinite arithmetic or exhausted limit fails the step. A zero step returns the input.
For scalar decay with , the factor tends to as tends to . Steps with alternate in sign. At , the mode begins . Replacing the first full step by two backward-euler half steps reduces the unresolved mode before resuming trapezoid on the original grid. A few bdf2 steps initialized by backward Euler can also damp the mode before switching. If forcing or boundaries keep exciting fast modes, continue with an L-stable method or decrease the step so decay is resolved. A damped startup reduces the size of ringing and can still leave sign changes. If positivity is mandatory, verify it for the actual time method, operator and step.
7. Verification
Export step(fun, jac, t, y, h) -> y_next in port_adapter.py. Run python <skill>/checks/check_port.py from the adapter directory and show its output. The fixed cases in checks/cases.json give the equations for ports in other languages. The checker covers signed steps, endpoint averaging, order, and ringing on a very fast scalar mode.
On your system, compare at fixed physical times after halving . Inspect peaks just after startup or a discontinuity. Compare plain steps with a damped restart if the solution displays alternating spatial or temporal components. Use an independent check of your chosen spatial discretization.
8. Failure signatures
| Symptom | Likely cause |
|---|---|
| Alternating sign with a slowly shrinking envelope on fast decay | The far-left stability factor is close to . Damp the initial mode or switch to L-stable integration. |
| Linear fixtures pass while nonlinear fixtures fail | Check whether the code evaluates only one slope at the midpoint. |
| Newton fails on forced or coupled cases | Check Jacobian orientation, the factor , and the two endpoint time arguments. |
9. Files and commands
reference/implicit_trapezoidal.py solves a fixed step. uv run examples/fast_decay.py shows ringing and a damped startup. uv run verify/check_cases.py tests mixed-scale nonlinear solves, correct and broken ports, midpoint equivalence for an autonomous affine system, nonlinear invariant loss, and a canonical area defect. uv run checks/make_cases.py prints the fixture JSON.
10. Sources
- Crank and Nicolson introduced the method in the heat-conduction setting. Crank and Nicolson (1947) · 1996 reprint
- Giles and Carter analyze replacing initial Crank–Nicolson steps with backward Euler startup. Giles and Carter (2006)