Tutorial

What you trust

What the kernel checks, which axioms a proof uses, and what the opt-in fast profile adds.

When I use a tool in a proof, the first thing I want to know is what I’m trusting. For SymLean the answer is short. A result is a Lean proof, and Lean’s kernel checks it. Native evaluation, which also trusts Lean’s compiler, runs only when you explicitly enable it. Whatever a search finds is a proposal, and nothing it returns becomes a fact until the kernel has checked it. The sections below go through each part, with examples you can run.

Reading the axioms#

You can check the first part yourself with #print axioms, and that’s where I always start. Here is a bound on a box, where each variable lies between two rational bounds, and a table of thirty-two integer inequalities:

In[1]:=
theorem box_bound (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by
  cega

theorem finite_rows : ∀ i : Fin 32, (i.val : ℤ) ^ 2 < 1024 := by
  cega

#print axioms box_bound
#print axioms finite_rows
Out[1]=

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

finite_rows depends on the axioms propext.

Both use only Lean’s standard axioms. The bound went through interval arithmetic and the table through a finite decision procedure, two quite different routes, and the kernel checked both.

What the kernel checks#

Every closing tactic builds a complete proof of the goal. Before it closes the goal, it rejects a proof with holes or unassigned parts, and it checks that the type of the proof is the goal. The kernel then checks the declaration, as it checks every Lean declaration.

The planners, the candidate searches and the decoding of expressions sit outside all this. They decide which proof to build, and the kernel decides whether it is one. That split is why I’m comfortable with fast, unverified search inside SymLean. Every form of cas and cega closes the goal completely or restores it, and only cas_nf, which rewrites, may leave a changed goal.

The kernel routes of cega promise one more thing. Their proofs use no axiom beyond propext, Classical.choice and Quot.sound that the goal, the hypotheses or a supplied certificate don’t already use. A proof that does is rejected with the name of the axiom, and the next route is tried.

You can see the same split in a #cas report, which keeps the evidence apart from the explanation:

In[2]:=
#cas [roots x] (x ^ 3 - 2 * x - 5 = 0)
Out[2]=

the only real solution, by 20 decimals, truncated

2.09455148154232659148
Input (polynomial equation)
(x ^ 3 - 2 * x - 5 = 0)

Checked by Lean’s kernel: Complete list of real solutions

(∃! x,
    x ∈ Set.Ioo (209455148154232659148 / 10 ^ 20) (209455148154232659149 / 10 ^ 20) ∧ x ^ 3 - 2 * x - 5 = 0) ∧
  ∀ (x : ℝ),
    x ^ 3 - 2 * x - 5 = 0 → x ∈ Set.Ioo (209455148154232659148 / 10 ^ 20) (209455148154232659149 / 10 ^ 20)

from CAS.Polynomial.RealRoot.of_exprRootCheck

The certificate: 1 checked step
  1. Complete list of real solutions

    (∃! x,
        x ∈ Set.Ioo (209455148154232659148 / 10 ^ 20) (209455148154232659149 / 10 ^ 20) ∧ x ^ 3 - 2 * x - 5 = 0) ∧
      ∀ (x : ℝ),
        x ^ 3 - 2 * x - 5 = 0 → x ∈ Set.Ioo (209455148154232659148 / 10 ^ 20) (209455148154232659149 / 10 ^ 20)

    Checked by Lean’s kernel · CAS.Polynomial.RealRoot.of_exprRootCheck

The computation
  • Certified isolation

    Square-free polynomial of degree 3, Cauchy bound 8, 6 cells
    Guarantee: the listed solutions are distinct, each rational is a solution, each decimal interval contains exactly one solution, and there are no other real solutions

The certificate lists the proposition that was proved, with exact rational endpoints: one root in an interval of width 10−20, and every real root inside it. That proposition is what the kernel checked. How the answer was found, meaning the route names and the steps of the planner, is explanation. I find it useful to read, but it proves nothing.

Native certificates are opt-in#

Large finite checks, such as a long table of inequalities, are slow to reduce in the kernel, and cega [fast] can check them by compiled code instead. You trade trust for speed, and the proof says so: it also trusts Lean’s compiler and runtime, and the proof depends on a generated axiom whose name contains _native.cegaFast.ax, so #print axioms shows it.

Native checking happens only when the option cega.nativeCertificates is true, and it is false by default, in SymLean and in every project that depends on it. With the option off, cega [fast] is bare cega and checks in the kernel:

In[3]:=
theorem fast_without_native (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * x ≤ 1 := by
  cega [fast]

#print axioms fast_without_native
Out[3]=

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

With the option on, a larger table is checked by compiled code, and the axioms say so:

In[4]:=
set_option cega.nativeCertificates true in
theorem fast_rows : ∀ i : Fin 64, (i.val : ℤ) ^ 2 < 4096 := by
  cega [fast]

#print axioms fast_rows
Out[4]=

fast_rows depends on the axioms propext, fast_rows._native.cegaFast.ax_1.

The table is a new one on purpose. When the kernel has already proved the same statement earlier in the same declaration, cega [fast] reuses that proof, and no native axiom appears. The build of this site elaborates a page in sequence (Elab.async off), and then a proof from an earlier declaration, such as finite_rows, is reused too. With Lean’s default, asynchronous elaboration it is not.

There are three ways to turn it on:

The profiles are kernel, the default, and fast with its alias native. With -R, which makes Lake read its options again, any other value of certificates is an error of SymLean’s configuration, and Lake stops before it builds anything.

The option governs only the checks that run while it is set. A failed native attempt restores the proof state before the kernel routes run, so its axioms don’t survive a refusal, and a later kernel request for the same statement never receives a native proof. The analytic routes, exponentials and logarithms among them, check in the kernel in every profile.

The tests of the certificates of any size follow the same option. With it on, cert_eval and the tactics and commands built on it, cert_shard, cert_cond, cert_scalar, cert_decide and cert_reduce, run their tests in compiled code, elementary functions included, and each loop that compiled code evaluates adds one such axiom to the theorem.

Much of a computer algebra system is search, and search is where bugs live. So SymLean runs its searches as ordinary compiled code and treats every answer as a proposal. Here is what that means, area by area:

In this example the common factor x−1 is cancelled, and x−1≠0 appears as a hypothesis of the theorem:

In[5]:=
#cas [cancel] ((x ^ 2 - 1) / (x - 1))
Out[5]=

cancelled

x + 1
Input (rational function)
((x ^ 2 - 1) / (x - 1))
Conditions
x−1≠0

Checked by Lean’s kernel: Identity with the cancelled form

∀ (x : ℝ), x - 1 ≠ 0 → (x ^ 2 - 1) / (x - 1) = x + 1
The certificate: 1 checked step
  1. Identity with the cancelled form

    ∀ (x : ℝ), x - 1 ≠ 0 → (x ^ 2 - 1) / (x - 1) = x + 1

    Checked by Lean’s kernel

What a refusal means#

A failed call restores the goal and says what it lacked: a hypothesis, a regularity proof, more precision, a supported expression. Missing side conditions are never added as assumptions, and the statement is never changed.

A refusal proves nothing about the goal either way. An integration search that finds no candidate doesn’t show that no antiderivative exists, and a certificate that doesn’t reduce to true is reported in those words, not as a false statement.

Lean’s total functions still apply: 0/0=0, log0=0, and exp(logx)=x needs 0<x. For a nonzero x of unknown sign the identity is exp(logx)=|x|, and the tactics prove the statement you wrote, under these meanings:

In[6]:=
example (x : ℝ) (hx : x ≠ 0) : Real.exp (Real.log x) = |x| := by
  cas
Out[6]=

Lean accepts the proof.

A residual bound gives an error estimate only when combined with a suitable stability theorem. SymLean certifies the bound on the residual, and the stability theorem has to come from the surrounding proof. A result never says more than its statement.

From here, the documentation has a guide for each area, starting with Why SymLean.