Where to Go Next

The programs in this book prove only a few facts about their own results. A good next step is to state and prove a general property of one of them. For example, prove that normalize in the symbolic math chapter returns a list with no zero coefficients.

Properties to Prove

Chapter Property
Bayes normalize returns weights that sum to 1 when the input weights are positive
Triple store query returns only bindings that satisfy every pattern
BM25 tokenize returns lowercase words and never an empty word
Summarizer summarize returns at most n sentences, in text order
Vector store cosine lies between -1 and 1 for nonzero vectors
Hopfield an asynchronous update never increases the energy
Symbolic math normalize is idempotent, and eval distributes over add
Autograd backward gives the chain rule for every node before the root

A First Proof

Start with normalize in the symbolic math chapter. The statement is normalize (normalize terms) = normalize terms for every term list. The proof needs three lemmas: mergeSort is idempotent for the same comparison; the foldr merge returns a list with strictly descending exponents and nonzero coefficients; and normalize of a list that already has those properties returns the same list. Prove the last by induction on the list. Then combine the three: the first call establishes the invariant, and the second leaves it unchanged. This proof covers every list, which the native_decide examples cannot do.

Tactics and Mathlib

simp rewrites a goal with existing lemmas; omega solves linear arithmetic on Nat and Int; decide evaluates a decidable proposition; native_decide compiles the check and trusts the compiler. Use decide for finite cases and induction with simp and omega for generic statements. ring, from mathlib, proves polynomial identities.

Mathlib is a large dependency: thousands of files, a long first build, and imports that add check time. Start with the standard library and add mathlib when a proof needs algebra or analysis. The package index lists projects at https://reservoir.lean-lang.org/. Mathlib’s documentation is at https://leanprover-community.github.io/mathlib4_docs/, and the community answers questions on Zulip at https://leanprover.zulipchat.com.