Guide
Differential equations
Linear differential equations solved exactly, certified initial-value problems, Laplace and Fourier transforms, and Fourier series.
With a differential equation, the first thing I want to know is whether it has a closed form, and the tools here split along that line. When the equation is in one of the supported families, start with the exact solution. A linear equation gets its general solution, with the theorem that every solution is in the family, and an initial-value problem gets its only solution. When there is no closed form, ndsolve proves enclosures of the solution. The transforms and the Fourier coefficients live here too, and they are theorems about Mathlib’s integrals of the input function.
Differential equations
Transforms
laplaceThe Laplace transform of a sum of polynomial, exponential, trigonometric and hyperbolic terms, with a theorem about the integral.inverseLaplaceA function whose Laplace transform is a given proper rational function, with a theorem about the integral.fourierTransformThe Fourier transform of a Gaussian in Mathlib’s convention, with a theorem for every frequency.
Fourier series
fourierThe Fourier coefficients of a function on [-π, π] as exact functions of n, with a theorem about the integrals.fourierCosThe coefficients of the cosine series on [0, L] as exact functions of n, with a theorem about the integrals.fourierSinThe coefficients of the sine series on [0, L] as exact functions of n, with a theorem about the integrals.
The harmonic oscillator, started at with . Look at the shape of the theorem. It’s an equivalence about every twice-differentiable function, so it says that solves the problem and also that nothing else does:
#cas [dsolve y x, y 0 = 1, y' 0 = 0] (y'' + y = 0)
order 2, characteristic roots: ±i
y(x) = cos(x)- Input (linear equation of order 2 with constant coefficients)
(y'' + y = 0)
Checked by Lean’s kernel: The unique solution of the initial-value problem
∀ (y : ℝ → ℝ), (∀ k < 2, Differentiable ℝ (iteratedDeriv k y)) → ((∀ (x : ℝ), iteratedDeriv 2 y x + y x = 0) ∧ y 0 = 1 ∧ deriv y 0 = 0 ↔ ∀ (x : ℝ), y x = Real.cos x)
The certificate: 1 checked step
The unique solution of the initial-value problem
∀ (y : ℝ → ℝ), (∀ k < 2, Differentiable ℝ (iteratedDeriv k y)) → ((∀ (x : ℝ), iteratedDeriv 2 y x + y x = 0) ∧ y 0 = 1 ∧ deriv y 0 = 0 ↔ ∀ (x : ℝ), y x = Real.cos x)
The solutions of this Riccati equation are not elementary, so I ask for numbers instead. The theorem has three parts: a solution exists on , it is unique, and at the two times I asked for, it lies in the printed intervals:
#cas [ndsolve y t in [0, 1], y 0 = 1/2, at [1/2, 1]] (y' = y ^ 2 + t)
certified enclosures of width at most 10^-6; the solution exists and is unique on [0, 1] (6 pieces)
y(1/2) ∈ [0.8242620, 0.8242621], y(1) ∈ [2.1278712, 2.1278713]- Domain
t ∈ [0, 1]- Input (polynomial initial value problem)
(y' = y ^ 2 + t), y 0 = 1/2
Checked by Lean’s kernel: Existence, uniqueness and enclosures
(∃ y, y 0 = 1 / 2 ∧ IsIntegralCurveOn y (fun t y ↦ y ^ 2 + t) (Set.Icc 0 1)) ∧ (∀ (y z : ℝ → ℝ), y 0 = 1 / 2 → IsIntegralCurveOn y (fun t y ↦ y ^ 2 + t) (Set.Icc 0 1) → z 0 = 1 / 2 → IsIntegralCurveOn z (fun t y ↦ y ^ 2 + t) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧ ∀ (y : ℝ → ℝ), y 0 = 1 / 2 → IsIntegralCurveOn y (fun t y ↦ y ^ 2 + t) (Set.Icc 0 1) → (0.8242620 ≤ y (1 / 2) ∧ y (1 / 2) ≤ 0.8242621 ∧ 0.8242621 - 0.8242620 ≤ 1 / 10 ^ 6) ∧ 2.1278712 ≤ y 1 ∧ y 1 ≤ 2.1278713 ∧ 2.1278713 - 2.1278712 ≤ 1 / 10 ^ 6
The certificate: 1 checked step
Existence, uniqueness and enclosures
(∃ y, y 0 = 1 / 2 ∧ IsIntegralCurveOn y (fun t y ↦ y ^ 2 + t) (Set.Icc 0 1)) ∧ (∀ (y z : ℝ → ℝ), y 0 = 1 / 2 → IsIntegralCurveOn y (fun t y ↦ y ^ 2 + t) (Set.Icc 0 1) → z 0 = 1 / 2 → IsIntegralCurveOn z (fun t y ↦ y ^ 2 + t) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧ ∀ (y : ℝ → ℝ), y 0 = 1 / 2 → IsIntegralCurveOn y (fun t y ↦ y ^ 2 + t) (Set.Icc 0 1) → (0.8242620 ≤ y (1 / 2) ∧ y (1 / 2) ≤ 0.8242621 ∧ 0.8242621 - 0.8242620 ≤ 1 / 10 ^ 6) ∧ 2.1278712 ≤ y 1 ∧ y 1 ≤ 2.1278713 ∧ 2.1278713 - 2.1278712 ≤ 1 / 10 ^ 6
Here is where each tool stops. dsolve takes equations that are linear in and its derivatives. With rational constant coefficients the order can be anything, while coefficients that depend on are handled in first order only, through an integrating factor. The initial values have to be given at one point, so for a boundary-value problem I fit the constants of the general solution myself. ndsolve takes a right side that is a polynomial in and , of degree at most 4 in each, on an interval of length at most 20. Near a blow-up of the solution no certified step exists, and the command is refused. The transforms cover a fixed menu: laplace takes sums of at most eight terms , with a cosine, sine, hyperbolic cosine or hyperbolic sine or no at all, inverseLaplace a proper rational function of , and fourierTransform a Gaussian. Mathlib has no uniqueness theorem for the Laplace transform, so inverseLaplace gives an inverse transform and doesn’t claim it’s the only one. The Fourier series work on with integer frequencies, or on for sums of terms .
