Guide

Numerics

Digits, ranges, integrals, roots and eigenvalue bounds, each a proved enclosure, and the tactic cega that proves numerical bounds.

Sooner or later a proof needs an actual number: some digits of a constant, the range of a function on a box, a definite integral, a root, or a bound on an eigenvalue. Every number here comes with a theorem. The printed digits are digits of the real value, and an enclosure holds at every point of its box, not at sample points. The arithmetic is exact rational interval arithmetic from FloatLib, so the error of finite precision is part of the bound, and there is no rounding left over for me to argue about.

Digits

  • NThe first digits of a closed real expression, with a theorem that every printed digit is right.

Ranges and extrema

  • encloseAn interval that holds every value of an expression on a box, with upper, absolute and center bounds, all proved.
  • maximizeThe maximum of a polynomial on the real line or on an interval, exact or enclosed, with a theorem.
  • minimizeThe minimum of a polynomial on the real line or on an interval, exact or enclosed, with a theorem.

Integrals, roots and differential equations

  • nintegrateA definite integral to a fixed number of decimal places, with a theorem that bounds the error.
  • findRootA certified simple root of a function in an interval, to a chosen number of decimals, with a uniqueness theorem.
  • ndsolveCertified enclosures of the solution of a polynomial initial-value problem, with a theorem of existence and uniqueness.

Matrices

  • eigenvalueBoundsDecimal bounds on the smallest and the largest eigenvalue of a symmetric matrix, with a theorem that they hold and are sharp.

Bounds in proofs

  • cegaProves numerical bounds: inequalities on a box of real variables, closed constants and interval integrals.
  • cega usingProves a goal from a certificate that you built once, by the certificate’s own soundness theorem.
  • cega?Proves the goal as cega does, and suggests the call to keep in the proof.

Settings

  • OptionsThe settings of cas, cega and #cas: the budget of a call, what a report shows, and the trace classes.

Fifty digits of π, each one proved. The theorem puts π between the printed decimal and the next one up:

In[1]:=
#cas [N 50] (pi)
Out[1]=

first 50 significant digits, truncated

3.1415926535897932384626433832795028841971693993751
Domain
closed real expression

Checked by Lean’s kernel: Certified decimal digits

31415926535897932384626433832795028841971693993751 / 10 ^ 49 ≤ Real.pi ∧
  Real.pi < (31415926535897932384626433832795028841971693993751 + 1) / 10 ^ 49

from CAS.Continuum.DigitsEval.eval_sound

The certificate: 1 checked step
  1. Certified decimal digits

    31415926535897932384626433832795028841971693993751 / 10 ^ 49 ≤ Real.pi ∧
      Real.pi < (31415926535897932384626433832795028841971693993751 + 1) / 10 ^ 49

    Checked by Lean’s kernel · CAS.Continuum.DigitsEval.eval_sound

The computation
  • Certified numerical evaluation

    Working precision: 206 bits, 74 series terms, 150 logarithm terms
    Guarantee: every printed digit is a digit of the real value, truncated toward zero

The same arithmetic proves bounds inside a proof. A bound like the one below is obvious from a plot and tedious to prove by hand. Here cega reads the box [0,1] from the hypothesis and proves ex≤2.72 on it, which is tight, since e≈2.71828:

In[2]:=
example (x : ℝ) (hx : x ∈ Set.Icc (0 : ℝ) 1) : Real.exp x ≤ 2.72 := by
  cega
Out[2]=

Lean accepts the proof.

An enclosure is always valid, but it isn’t always tight, and (depth := n) lets cega bisect the box when you need a closer bound. A box has rational endpoints and at most 8 coordinates by default, and every subexpression has to be defined on all of it: denominators stay away from zero and the arguments of log stay positive. cega needs rational bounds on every variable among the hypotheses. When a bound is false, or true but out of reach of the enclosures, it refuses, and the message proposes the next call to try. Every check stays in the kernel unless you turn on cega.nativeCertificates, which also trusts Lean’s compiler. The trust tutorial goes through what that adds to the trusted base. The enclosures are computed with exact rationals, and cega [use_floats] computes them with IEEE floats instead, in binary64 or in the format you name. Certificates says what changes and what doesn’t.

One note on reading the theorems: Lean prints a decimal that has zeros right after the point as an integer with a power of ten, so 0.011437 appears as 11437e-6 and 0.000001 as 1e-6.