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:
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
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:
#cas [roots x] (x ^ 3 - 2 * x - 5 = 0)
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
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)
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 , 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:
theorem fast_without_native (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * x ≤ 1 := by cega [fast] #print axioms fast_without_native
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:
set_option cega.nativeCertificates true in theorem fast_rows : ∀ i : Fin 64, (i.val : ℤ) ^ 2 < 4096 := by cega [fast] #print axioms fast_rows
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:
set_option cega.nativeCertificates true infor one declaration, as above.lake build -R -Kcertificates=fastfor the library itself. It passes the option to every module and builds into.lake/build-fast, separate from the kernel build in.lake/build.require SymLean ... with NameMap.empty.insert `certificates "fast"in a project that depends on SymLean.
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.
Searches propose, the kernel decides#
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:
- Integration. The planner proposes an antiderivative. The kernel checks that its derivative equals the integrand on the whole interval, and only then is the fundamental theorem of calculus applied. A wrong proposal fails that check.
- Cancellation and factoring.
cancelfinds the common factor by a gcd search, then proves the identity with the cancelled form byfield_simpandring1, from the hypotheses that the divisors as written are nonzero. Those hypotheses are the conditions of the report. A factorization is a proposal too, andringproves that the product equals the input. - Equations. A Gröbner basis is computed by search and replayed by
linear_combination, and the real roots of its eliminant, a polynomial in one variable, are isolated by a certificate that the kernel evaluates. - Roots and limits. The isolating intervals are found in compiled code, and the kernel checks their obligations. The theorem reaches the goal through a proved identity with the goal’s own function, so a misread function fails instead of proving another statement.
- Oracles. The oracles run external programs whose answers SymLean proves or refuses.
In this example the common factor is cancelled, and appears as a hypothesis of the theorem:
#cas [cancel] ((x ^ 2 - 1) / (x - 1))
cancelled
x + 1- Input (rational function)
((x ^ 2 - 1) / (x - 1))- Conditions
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
Identity with the cancelled form
∀ (x : ℝ), x - 1 ≠ 0 → (x ^ 2 - 1) / (x - 1) = x + 1
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: , , and needs . For a nonzero of unknown sign the identity is , and the tactics prove the statement you wrote, under these meanings:
example (x : ℝ) (hx : x ≠ 0) : Real.exp (Real.log x) = |x| := by cas
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.
