Mode of #cas

ndsolve

Certified enclosures of the solution of a polynomial initial-value problem, with a theorem of existence and uniqueness.

#cas [ndsolve y t in [t₀, T], y t₀ = y₀] (y' = f)
solves the initial-value problem on [t0,T] for a polynomial f in t and y, prints a certified enclosure of the solution at T, and proves that the solution exists and is unique.
#cas [ndsolve y t in [t₀, T], y t₀ = y₀, at [τ₁, …]] (y' = f)
prints enclosures at the output times τ₁, … instead.
#cas (digits := d) [ndsolve y t in [t₀, T], y t₀ = y₀] (y' = f)
makes every enclosure of width at most 10−d, for d from 1 to 15.

An initial-value problem is often easier to study through bounds on its solution than through a closed formula. ndsolve gives you those bounds as a theorem with three parts: a solution exists on the whole interval, it is the only one, and at each output time it lies in the printed interval.

We get the enclosures from a piecewise Taylor approximation, and the kernel checks it piece by piece. If your equation is linear and has an exact solution, dsolve gives you the formula instead.

Details and Options

  • With the field F = fun t y ↦ f, the theorem has three parts: a solution exists, ∃ y, y t₀ = y₀ ∧ IsIntegralCurveOn y F (Set.Icc t₀ T); two solutions agree on Set.Icc t₀ T; and every solution satisfies lo ≤ y τ ∧ y τ ≤ hi ∧ hi - lo ≤ 1 / 10 ^ d at each output time τ with the printed [lo, hi]. Mathlib’s IsIntegralCurveOn y F s says that y′(t)=F(t,y(t)) for t in s, with the derivative taken within s, so one-sided at the ends of the interval.
  • The kernel checks the residual of each Taylor piece, one-sided Lipschitz bounds of f in tubes around the pieces, and the Grönwall bounds that keep every solution in the tubes. At most 200 pieces are used, and the report says how many.
  • f is a polynomial in t and y with rational coefficients, of degree at most 4 in each variable and with at most 20 monomials. A quotient by an expression in t or y is refused, even when it cancels.
  • The size of the input is bounded before any work on it. A literal has at most 320 characters, a decimal literal a power of ten of at most 256, and f at most 600 syntax nodes. Before f is expanded, every power in it has an exponent of at most 64 and every subexpression a degree of at most 16, and the command’s estimate of the bits of its constants is at most 4096. A coefficient of the expanded polynomial has at most 1024 bits.
  • The endpoints are rational with t0<T, |t0|,|T|≤100, T−t0≤20 and denominators of at most 1000. The initial value is a rational y0 at t0 with |y0|≤100 and a denominator of at most 1012.
  • , at [τ₁, …] lists at least one and at most 8 output times in [t0,T], with denominators of at most 1000, by default T alone.
  • (digits := d) makes every enclosure of width at most 10−d, for d from 1 to 15, by default 6.
  • Where no certified step exists, as near a blow-up of the solution, the command is refused. It is also refused when four runs of the search leave an enclosure wider than 10−d, and inside a section with variables.
  • The tactic cas does not prove the statement of ndsolve. The solution of y' = y with y 0 = 1 is Real.exp, and cas bounds its value directly, as under Applications.

Examples (19)#

Basic Examples (2)

The solution of y' = y with y 0 = 1 is et, and its enclosure at 1 holds e:

In[1]:=
#cas [ndsolve y t in [0, 1], y 0 = 1] (y' = y)
Out[1]=

certified enclosures of width at most 10^-6; the solution exists and is unique on [0, 1] (4 pieces)

y(1)∈[2.7182818, 2.7182819]
y(1) ∈ [2.7182818, 2.7182819]
Domain
t ∈ [0, 1]
Input (polynomial initial value problem)
(y' = y), y 0 = 1

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ y, y 0 = 1 ∧ IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1)) ∧
  (∀ (y z : ℝ → ℝ),
      y 0 = 1 →
        IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1) →
          z 0 = 1 → IsIntegralCurveOn z (fun t y ↦ y) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
    ∀ (y : ℝ → ℝ),
      y 0 = 1 →
        IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1) →
          2.7182818 ≤ y 1 ∧ y 1 ≤ 2.7182819 ∧ 2.7182819 - 2.7182818 ≤ 1 / 10 ^ 6
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ y, y 0 = 1 ∧ IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1)) ∧
      (∀ (y z : ℝ → ℝ),
          y 0 = 1 →
            IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1) →
              z 0 = 1 → IsIntegralCurveOn z (fun t y ↦ y) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
        ∀ (y : ℝ → ℝ),
          y 0 = 1 →
            IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1) →
              2.7182818 ≤ y 1 ∧ y 1 ≤ 2.7182819 ∧ 2.7182819 - 2.7182818 ≤ 1 / 10 ^ 6

    Checked by Lean’s kernel


A Riccati equation, at the output times 1/2 and 1:

In[2]:=
#cas [ndsolve y t in [0, 1], y 0 = 1/2, at [1/2, 1]] (y' = y ^ 2 + t)
Out[2]=

certified enclosures of width at most 10^-6; the solution exists and is unique on [0, 1] (6 pieces)

y(12)∈[0.8242620, 0.8242621],y(1)∈[2.1278712, 2.1278713]
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
  1. 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

    Checked by Lean’s kernel

Scope (3)

Other names for the function and the variable, an interval that starts at −1, and an output time at the start:

In[3]:=
#cas [ndsolve x s in [-1, 1], x (-1) = 2, at [-1, 0, 1]] (x' = s * x - x ^ 2)
Out[3]=

certified enclosures of width at most 10^-6; the solution exists and is unique on [-1, 1] (14 pieces)

x(−1)∈[2.0000000, 2.0000000],x(0)∈[0.4952166, 0.4952167],x(1)∈[0.5129370, 0.5129371]
x(-1) ∈ [2.0000000, 2.0000000], x(0) ∈ [0.4952166, 0.4952167], x(1) ∈ [0.5129370, 0.5129371]
Domain
s ∈ [-1, 1]
Input (polynomial initial value problem)
(x' = s * x - x ^ 2), x (-1) = 2

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ x, x (-1) = 2 ∧ IsIntegralCurveOn x (fun s x ↦ s * x - x ^ 2) (Set.Icc (-1) 1)) ∧
  (∀ (x z : ℝ → ℝ),
      x (-1) = 2 →
        IsIntegralCurveOn x (fun s x ↦ s * x - x ^ 2) (Set.Icc (-1) 1) →
          z (-1) = 2 →
            IsIntegralCurveOn z (fun s x ↦ s * x - x ^ 2) (Set.Icc (-1) 1) → Set.EqOn x z (Set.Icc (-1) 1)) ∧
    ∀ (x : ℝ → ℝ),
      x (-1) = 2 →
        IsIntegralCurveOn x (fun s x ↦ s * x - x ^ 2) (Set.Icc (-1) 1) →
          (2.0000000 ≤ x (-1) ∧ x (-1) ≤ 2.0000000 ∧ 2.0000000 - 2.0000000 ≤ 1 / 10 ^ 6) ∧
            (0.4952166 ≤ x 0 ∧ x 0 ≤ 0.4952167 ∧ 0.4952167 - 0.4952166 ≤ 1 / 10 ^ 6) ∧
              0.5129370 ≤ x 1 ∧ x 1 ≤ 0.5129371 ∧ 0.5129371 - 0.5129370 ≤ 1 / 10 ^ 6
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ x, x (-1) = 2 ∧ IsIntegralCurveOn x (fun s x ↦ s * x - x ^ 2) (Set.Icc (-1) 1)) ∧
      (∀ (x z : ℝ → ℝ),
          x (-1) = 2 →
            IsIntegralCurveOn x (fun s x ↦ s * x - x ^ 2) (Set.Icc (-1) 1) →
              z (-1) = 2 →
                IsIntegralCurveOn z (fun s x ↦ s * x - x ^ 2) (Set.Icc (-1) 1) → Set.EqOn x z (Set.Icc (-1) 1)) ∧
        ∀ (x : ℝ → ℝ),
          x (-1) = 2 →
            IsIntegralCurveOn x (fun s x ↦ s * x - x ^ 2) (Set.Icc (-1) 1) →
              (2.0000000 ≤ x (-1) ∧ x (-1) ≤ 2.0000000 ∧ 2.0000000 - 2.0000000 ≤ 1 / 10 ^ 6) ∧
                (0.4952166 ≤ x 0 ∧ x 0 ≤ 0.4952167 ∧ 0.4952167 - 0.4952166 ≤ 1 / 10 ^ 6) ∧
                  0.5129370 ≤ x 1 ∧ x 1 ≤ 0.5129371 ∧ 0.5129371 - 0.5129370 ≤ 1 / 10 ^ 6

    Checked by Lean’s kernel


Rational endpoints and a rational initial value:

In[4]:=
#cas (digits := 8) [ndsolve y t in [-1/2, 3/4], y (-1/2) = -3/7, at [0, 3/4]] (y' = t ^ 2 - y / 3)
Out[4]=

certified enclosures of width at most 10^-8; the solution exists and is unique on [-1/2, 3/4] (8 pieces)

y(0)∈[−0.325987844, −0.325987843],y(34)∈[−0.121621874, −0.121621873]
y(0) ∈ [-0.325987844, -0.325987843], y(3/4) ∈ [-0.121621874, -0.121621873]
Domain
t ∈ [-1/2, 3/4]
Input (polynomial initial value problem)
(y' = t ^ 2 - y / 3), y (-1/2) = -3/7

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ y,
    y (-(1 / 2)) = -(3 / 7) ∧ IsIntegralCurveOn y (fun t y ↦ t ^ 2 - y / 3) (Set.Icc (-(1 / 2)) (3 / 4))) ∧
  (∀ (y z : ℝ → ℝ),
      y (-(1 / 2)) = -(3 / 7) →
        IsIntegralCurveOn y (fun t y ↦ t ^ 2 - y / 3) (Set.Icc (-(1 / 2)) (3 / 4)) →
          z (-(1 / 2)) = -(3 / 7) →
            IsIntegralCurveOn z (fun t y ↦ t ^ 2 - y / 3) (Set.Icc (-(1 / 2)) (3 / 4)) →
              Set.EqOn y z (Set.Icc (-(1 / 2)) (3 / 4))) ∧
    ∀ (y : ℝ → ℝ),
      y (-(1 / 2)) = -(3 / 7) →
        IsIntegralCurveOn y (fun t y ↦ t ^ 2 - y / 3) (Set.Icc (-(1 / 2)) (3 / 4)) →
          (-0.325987844 ≤ y 0 ∧ y 0 ≤ -0.325987843 ∧ -0.325987843 + 0.325987844 ≤ 1 / 10 ^ 8) ∧
            -0.121621874 ≤ y (3 / 4) ∧ y (3 / 4) ≤ -0.121621873 ∧ -0.121621873 + 0.121621874 ≤ 1 / 10 ^ 8
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ y,
        y (-(1 / 2)) = -(3 / 7) ∧ IsIntegralCurveOn y (fun t y ↦ t ^ 2 - y / 3) (Set.Icc (-(1 / 2)) (3 / 4))) ∧
      (∀ (y z : ℝ → ℝ),
          y (-(1 / 2)) = -(3 / 7) →
            IsIntegralCurveOn y (fun t y ↦ t ^ 2 - y / 3) (Set.Icc (-(1 / 2)) (3 / 4)) →
              z (-(1 / 2)) = -(3 / 7) →
                IsIntegralCurveOn z (fun t y ↦ t ^ 2 - y / 3) (Set.Icc (-(1 / 2)) (3 / 4)) →
                  Set.EqOn y z (Set.Icc (-(1 / 2)) (3 / 4))) ∧
        ∀ (y : ℝ → ℝ),
          y (-(1 / 2)) = -(3 / 7) →
            IsIntegralCurveOn y (fun t y ↦ t ^ 2 - y / 3) (Set.Icc (-(1 / 2)) (3 / 4)) →
              (-0.325987844 ≤ y 0 ∧ y 0 ≤ -0.325987843 ∧ -0.325987843 + 0.325987844 ≤ 1 / 10 ^ 8) ∧
                -0.121621874 ≤ y (3 / 4) ∧ y (3 / 4) ≤ -0.121621873 ∧ -0.121621873 + 0.121621874 ≤ 1 / 10 ^ 8

    Checked by Lean’s kernel


The logistic equation on [0,10], where the solution 1/(1+9e−t) comes close to 1:

In[5]:=
#cas (digits := 8) [ndsolve y t in [0, 10], y 0 = 1/10] (y' = y * (1 - y))
Out[5]=

certified enclosures of width at most 10^-8; the solution exists and is unique on [0, 10] (13 pieces)

y(10)∈[0.999591567, 0.999591568]
y(10) ∈ [0.999591567, 0.999591568]
Domain
t ∈ [0, 10]
Input (polynomial initial value problem)
(y' = y * (1 - y)), y 0 = 1/10

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ y, y 0 = 1 / 10 ∧ IsIntegralCurveOn y (fun t y ↦ y * (1 - y)) (Set.Icc 0 10)) ∧
  (∀ (y z : ℝ → ℝ),
      y 0 = 1 / 10 →
        IsIntegralCurveOn y (fun t y ↦ y * (1 - y)) (Set.Icc 0 10) →
          z 0 = 1 / 10 →
            IsIntegralCurveOn z (fun t y ↦ y * (1 - y)) (Set.Icc 0 10) → Set.EqOn y z (Set.Icc 0 10)) ∧
    ∀ (y : ℝ → ℝ),
      y 0 = 1 / 10 →
        IsIntegralCurveOn y (fun t y ↦ y * (1 - y)) (Set.Icc 0 10) →
          0.999591567 ≤ y 10 ∧ y 10 ≤ 0.999591568 ∧ 0.999591568 - 0.999591567 ≤ 1 / 10 ^ 8
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ y, y 0 = 1 / 10 ∧ IsIntegralCurveOn y (fun t y ↦ y * (1 - y)) (Set.Icc 0 10)) ∧
      (∀ (y z : ℝ → ℝ),
          y 0 = 1 / 10 →
            IsIntegralCurveOn y (fun t y ↦ y * (1 - y)) (Set.Icc 0 10) →
              z 0 = 1 / 10 →
                IsIntegralCurveOn z (fun t y ↦ y * (1 - y)) (Set.Icc 0 10) → Set.EqOn y z (Set.Icc 0 10)) ∧
        ∀ (y : ℝ → ℝ),
          y 0 = 1 / 10 →
            IsIntegralCurveOn y (fun t y ↦ y * (1 - y)) (Set.Icc 0 10) →
              0.999591567 ≤ y 10 ∧ y 10 ≤ 0.999591568 ∧ 0.999591568 - 0.999591567 ≤ 1 / 10 ^ 8

    Checked by Lean’s kernel

Options (2)

(digits := 10) gives enclosures of width at most 10−10. The solution here is tanht:

In[6]:=
#cas (digits := 10) [ndsolve y t in [0, 3], y 0 = 0, at [1, 2, 3]] (y' = 1 - y ^ 2)
Out[6]=

certified enclosures of width at most 10^-10; the solution exists and is unique on [0, 3] (12 pieces)

y(1)∈[0.76159415595, 0.76159415596],y(2)∈[0.96402758007, 0.96402758008],y(3)∈[0.99505475368, 0.99505475369]
y(1) ∈ [0.76159415595, 0.76159415596], y(2) ∈ [0.96402758007, 0.96402758008], y(3) ∈ [0.99505475368, 0.99505475369]
Domain
t ∈ [0, 3]
Input (polynomial initial value problem)
(y' = 1 - y ^ 2), y 0 = 0

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ y, y 0 = 0 ∧ IsIntegralCurveOn y (fun t y ↦ 1 - y ^ 2) (Set.Icc 0 3)) ∧
  (∀ (y z : ℝ → ℝ),
      y 0 = 0 →
        IsIntegralCurveOn y (fun t y ↦ 1 - y ^ 2) (Set.Icc 0 3) →
          z 0 = 0 → IsIntegralCurveOn z (fun t y ↦ 1 - y ^ 2) (Set.Icc 0 3) → Set.EqOn y z (Set.Icc 0 3)) ∧
    ∀ (y : ℝ → ℝ),
      y 0 = 0 →
        IsIntegralCurveOn y (fun t y ↦ 1 - y ^ 2) (Set.Icc 0 3) →
          (0.76159415595 ≤ y 1 ∧ y 1 ≤ 0.76159415596 ∧ 0.76159415596 - 0.76159415595 ≤ 1 / 10 ^ 10) ∧
            (0.96402758007 ≤ y 2 ∧ y 2 ≤ 0.96402758008 ∧ 0.96402758008 - 0.96402758007 ≤ 1 / 10 ^ 10) ∧
              0.99505475368 ≤ y 3 ∧ y 3 ≤ 0.99505475369 ∧ 0.99505475369 - 0.99505475368 ≤ 1 / 10 ^ 10
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ y, y 0 = 0 ∧ IsIntegralCurveOn y (fun t y ↦ 1 - y ^ 2) (Set.Icc 0 3)) ∧
      (∀ (y z : ℝ → ℝ),
          y 0 = 0 →
            IsIntegralCurveOn y (fun t y ↦ 1 - y ^ 2) (Set.Icc 0 3) →
              z 0 = 0 → IsIntegralCurveOn z (fun t y ↦ 1 - y ^ 2) (Set.Icc 0 3) → Set.EqOn y z (Set.Icc 0 3)) ∧
        ∀ (y : ℝ → ℝ),
          y 0 = 0 →
            IsIntegralCurveOn y (fun t y ↦ 1 - y ^ 2) (Set.Icc 0 3) →
              (0.76159415595 ≤ y 1 ∧ y 1 ≤ 0.76159415596 ∧ 0.76159415596 - 0.76159415595 ≤ 1 / 10 ^ 10) ∧
                (0.96402758007 ≤ y 2 ∧ y 2 ≤ 0.96402758008 ∧ 0.96402758008 - 0.96402758007 ≤ 1 / 10 ^ 10) ∧
                  0.99505475368 ≤ y 3 ∧ y 3 ≤ 0.99505475369 ∧ 0.99505475369 - 0.99505475368 ≤ 1 / 10 ^ 10

    Checked by Lean’s kernel


A decaying solution keeps its accuracy, because the Lipschitz bound in the check is one-sided, so the negative slope of -10 * y costs only a small positive constant. Here y(1)=e−10, within 10−12. In the theorem, Lean prints the decimals 0.0000453999297 and 0.0000453999298 as 453999297e-13 and 453999298e-13:

In[7]:=
#cas (digits := 12) [ndsolve y t in [0, 1], y 0 = 1] (y' = -10 * y)
Out[7]=

certified enclosures of width at most 10^-12; the solution exists and is unique on [0, 1] (15 pieces)

y(1)∈[0.0000453999297, 0.0000453999298]
y(1) ∈ [0.0000453999297, 0.0000453999298]
Domain
t ∈ [0, 1]
Input (polynomial initial value problem)
(y' = -10 * y), y 0 = 1

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ y, y 0 = 1 ∧ IsIntegralCurveOn y (fun t y ↦ -10 * y) (Set.Icc 0 1)) ∧
  (∀ (y z : ℝ → ℝ),
      y 0 = 1 →
        IsIntegralCurveOn y (fun t y ↦ -10 * y) (Set.Icc 0 1) →
          z 0 = 1 → IsIntegralCurveOn z (fun t y ↦ -10 * y) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
    ∀ (y : ℝ → ℝ),
      y 0 = 1 →
        IsIntegralCurveOn y (fun t y ↦ -10 * y) (Set.Icc 0 1) →
          453999297e-13 ≤ y 1 ∧ y 1 ≤ 453999298e-13 ∧ 453999298e-13 - 453999297e-13 ≤ 1 / 10 ^ 12
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ y, y 0 = 1 ∧ IsIntegralCurveOn y (fun t y ↦ -10 * y) (Set.Icc 0 1)) ∧
      (∀ (y z : ℝ → ℝ),
          y 0 = 1 →
            IsIntegralCurveOn y (fun t y ↦ -10 * y) (Set.Icc 0 1) →
              z 0 = 1 → IsIntegralCurveOn z (fun t y ↦ -10 * y) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
        ∀ (y : ℝ → ℝ),
          y 0 = 1 →
            IsIntegralCurveOn y (fun t y ↦ -10 * y) (Set.Icc 0 1) →
              453999297e-13 ≤ y 1 ∧ y 1 ≤ 453999298e-13 ∧ 453999298e-13 - 453999297e-13 ≤ 1 / 10 ^ 12

    Checked by Lean’s kernel

Applications (1)

The enclosure of e in a proof. cas bounds Real.exp 1 directly, and only the three standard axioms are used:

In[8]:=
theorem ndsolve_exp_bounds : 2.7182818 ≤ Real.exp 1 ∧ Real.exp 1 ≤ 2.7182819 := by
  cas

#print axioms ndsolve_exp_bounds
Out[8]=

ndsolve_exp_bounds depends on the axioms propext, Classical.choice, Quot.sound.

Properties and Relations (2)

The solution of y' = y with y 0 = 1 is et, so the enclosures at 1/2 and 1 hold e and e:

In[9]:=
#cas (digits := 10) [ndsolve y t in [0, 1], y 0 = 1, at [1/2, 1]] (y' = y)
Out[9]=

certified enclosures of width at most 10^-10; the solution exists and is unique on [0, 1] (5 pieces)

y(12)∈[1.64872127070, 1.64872127071],y(1)∈[2.71828182845, 2.71828182846]
y(1/2) ∈ [1.64872127070, 1.64872127071], y(1) ∈ [2.71828182845, 2.71828182846]
Domain
t ∈ [0, 1]
Input (polynomial initial value problem)
(y' = y), y 0 = 1

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ y, y 0 = 1 ∧ IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1)) ∧
  (∀ (y z : ℝ → ℝ),
      y 0 = 1 →
        IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1) →
          z 0 = 1 → IsIntegralCurveOn z (fun t y ↦ y) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
    ∀ (y : ℝ → ℝ),
      y 0 = 1 →
        IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1) →
          (1.64872127070 ≤ y (1 / 2) ∧
              y (1 / 2) ≤ 1.64872127071 ∧ 1.64872127071 - 1.64872127070 ≤ 1 / 10 ^ 10) ∧
            2.71828182845 ≤ y 1 ∧ y 1 ≤ 2.71828182846 ∧ 2.71828182846 - 2.71828182845 ≤ 1 / 10 ^ 10
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ y, y 0 = 1 ∧ IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1)) ∧
      (∀ (y z : ℝ → ℝ),
          y 0 = 1 →
            IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1) →
              z 0 = 1 → IsIntegralCurveOn z (fun t y ↦ y) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
        ∀ (y : ℝ → ℝ),
          y 0 = 1 →
            IsIntegralCurveOn y (fun t y ↦ y) (Set.Icc 0 1) →
              (1.64872127070 ≤ y (1 / 2) ∧
                  y (1 / 2) ≤ 1.64872127071 ∧ 1.64872127071 - 1.64872127070 ≤ 1 / 10 ^ 10) ∧
                2.71828182845 ≤ y 1 ∧ y 1 ≤ 2.71828182846 ∧ 2.71828182846 - 2.71828182845 ≤ 1 / 10 ^ 10

    Checked by Lean’s kernel


When f does not involve y, the solution is a primitive of f. Here y(1)=∫01tdt=1/2, and the enclosure is the single point 1/2:

In[10]:=
#cas [ndsolve y t in [0, 1], y 0 = 0] (y' = t)
Out[10]=

certified enclosures of width at most 10^-6; the solution exists and is unique on [0, 1] (4 pieces)

y(1)∈[0.5000000, 0.5000000]
y(1) ∈ [0.5000000, 0.5000000]
Domain
t ∈ [0, 1]
Input (polynomial initial value problem)
(y' = t), y 0 = 0

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ y, y 0 = 0 ∧ IsIntegralCurveOn y (fun t y ↦ t) (Set.Icc 0 1)) ∧
  (∀ (y z : ℝ → ℝ),
      y 0 = 0 →
        IsIntegralCurveOn y (fun t y ↦ t) (Set.Icc 0 1) →
          z 0 = 0 → IsIntegralCurveOn z (fun t y ↦ t) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
    ∀ (y : ℝ → ℝ),
      y 0 = 0 →
        IsIntegralCurveOn y (fun t y ↦ t) (Set.Icc 0 1) →
          0.5000000 ≤ y 1 ∧ y 1 ≤ 0.5000000 ∧ 0.5000000 - 0.5000000 ≤ 1 / 10 ^ 6
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ y, y 0 = 0 ∧ IsIntegralCurveOn y (fun t y ↦ t) (Set.Icc 0 1)) ∧
      (∀ (y z : ℝ → ℝ),
          y 0 = 0 →
            IsIntegralCurveOn y (fun t y ↦ t) (Set.Icc 0 1) →
              z 0 = 0 → IsIntegralCurveOn z (fun t y ↦ t) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
        ∀ (y : ℝ → ℝ),
          y 0 = 0 →
            IsIntegralCurveOn y (fun t y ↦ t) (Set.Icc 0 1) →
              0.5000000 ≤ y 1 ∧ y 1 ≤ 0.5000000 ∧ 0.5000000 - 0.5000000 ≤ 1 / 10 ^ 6

    Checked by Lean’s kernel

Possible Issues (8)

The solution 1/(1−t) of y' = y ^ 2 with y 0 = 1 blows up at t=1, and no certified step gets past it. Solve on an interval that ends before 1:

In[11]:=
#cas [ndsolve y t in [0, 2], y 0 = 1] (y' = y ^ 2)
Out[11]=

Error

ndsolve: no certified step at t = 49841/50000; the solution may blow up there

f must be a polynomial in t and y. For a linear equation, dsolve takes sines, cosines and exponentials of the variable:

In[12]:=
#cas [ndsolve y t in [0, 1], y 0 = 1] (y' = sin y)
Out[12]=

Error

ndsolve: f must be a polynomial in t and y with rational coefficients

The degree in y is at most 4, and so is the degree in t:

In[13]:=
#cas [ndsolve y t in [0, 1], y 0 = 1] (y' = y ^ 5)
Out[13]=

Error

ndsolve accepts degree at most 4 in y

The initial condition is at the left end of the interval. To start at 1, write [ndsolve y t in [1, 2], y 1 = 1]:

In[14]:=
#cas [ndsolve y t in [0, 1], y 1 = 1] (y' = y)
Out[14]=

Error

ndsolve: the initial condition must be at t₀ = 0

The output times lie in the interval:

In[15]:=
#cas [ndsolve y t in [0, 1], y 0 = 1, at [2]] (y' = y)
Out[15]=

Error

ndsolve: the output time 2 is not in [0, 1]

The interval has length at most 20:

In[16]:=
#cas [ndsolve y t in [0, 30], y 0 = 1] (y' = -y)
Out[16]=

Error

ndsolve accepts T - t₀ ≤ 20

At most 15 digits:

In[17]:=
#cas (digits := 16) [ndsolve y t in [0, 1], y 0 = 1] (y' = y)
Out[17]=

Error

ndsolve accepts between 1 and 15 digits

The equation is about the function named in the brackets:

In[18]:=
#cas [ndsolve y t in [0, 1], y 0 = 1] (z' = y)
Out[18]=

Error

ndsolve: expected an equation y' = f

Neat Examples (1)

The solution of y' = 1 + y ^ 2 with y 0 = 0 is tant, and the enclosure holds tan1:

In[19]:=
#cas [ndsolve y t in [0, 1], y 0 = 0] (y' = 1 + y ^ 2)
Out[19]=

certified enclosures of width at most 10^-6; the solution exists and is unique on [0, 1] (5 pieces)

y(1)∈[1.5574077, 1.5574078]
y(1) ∈ [1.5574077, 1.5574078]
Domain
t ∈ [0, 1]
Input (polynomial initial value problem)
(y' = 1 + y ^ 2), y 0 = 0

Checked by Lean’s kernel: Existence, uniqueness and enclosures

(∃ y, y 0 = 0 ∧ IsIntegralCurveOn y (fun t y ↦ 1 + y ^ 2) (Set.Icc 0 1)) ∧
  (∀ (y z : ℝ → ℝ),
      y 0 = 0 →
        IsIntegralCurveOn y (fun t y ↦ 1 + y ^ 2) (Set.Icc 0 1) →
          z 0 = 0 → IsIntegralCurveOn z (fun t y ↦ 1 + y ^ 2) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
    ∀ (y : ℝ → ℝ),
      y 0 = 0 →
        IsIntegralCurveOn y (fun t y ↦ 1 + y ^ 2) (Set.Icc 0 1) →
          1.5574077 ≤ y 1 ∧ y 1 ≤ 1.5574078 ∧ 1.5574078 - 1.5574077 ≤ 1 / 10 ^ 6
The certificate: 1 checked step
  1. Existence, uniqueness and enclosures

    (∃ y, y 0 = 0 ∧ IsIntegralCurveOn y (fun t y ↦ 1 + y ^ 2) (Set.Icc 0 1)) ∧
      (∀ (y z : ℝ → ℝ),
          y 0 = 0 →
            IsIntegralCurveOn y (fun t y ↦ 1 + y ^ 2) (Set.Icc 0 1) →
              z 0 = 0 → IsIntegralCurveOn z (fun t y ↦ 1 + y ^ 2) (Set.Icc 0 1) → Set.EqOn y z (Set.Icc 0 1)) ∧
        ∀ (y : ℝ → ℝ),
          y 0 = 0 →
            IsIntegralCurveOn y (fun t y ↦ 1 + y ^ 2) (Set.Icc 0 1) →
              1.5574077 ≤ y 1 ∧ y 1 ≤ 1.5574078 ∧ 1.5574078 - 1.5574077 ≤ 1 / 10 ^ 6

    Checked by Lean’s kernel

See Also

dsolve · nintegrate · findRoot · enclose · N