Follow three proofs in Lean, from a triangle bound to a matrix certificate, and see how theorems can be combined to design specialized mathematical workflows.
English transcript
How large can the sum be?
Choose a triangle and call its angles A, B, and C. Add the cosines of those three angles. How large can the sum be? The answer is three halves. An equilateral triangle reaches that value. To prove the bound for every triangle, we'll use a theorem from Reusable, a library of Lean proofs. The theorem gives us an identity that turns the inequality into two squares.
Find the theorem
Open the Reusable showcase. In the search box, enter Wolstenholme defect. This card is Wolstenholme's inequality, in defect form. The Lean statement shows the exact name and assumptions. The minimal import is the Geometry module. The provenance links you to the original theorem in the archive. The trust row lists the axioms Lean reports for this result.
Read the identity
The identity assumes the three angles add to pi. The weights x, y, and z can be any real numbers. Start with the sum of the squares of the weights, then subtract the weighted cosine expression. The theorem says this difference equals the sum of the two squares shown below. Each square is nonnegative, so the difference is nonnegative too. That gives us the weighted inequality. The identity does the trigonometric work. The angle sum matters. Drop that hypothesis and set every angle to zero and every weight to one. The claimed inequality becomes six at most three. Lean checks this counterexample.
Prove it in Lean
Here's the example from Recipe One of the guide, with its import. The example takes six real numbers and the angle sum as a hypothesis. have key applies the theorem to those inputs and puts the equality in the local context. The next command passes the nonnegativity of each square to Lean's nonlinear arithmetic tactic. Using the equality and those two facts, the tactic closes the goal.
Try x = y = z = 1
Now use one for each of the three weights. The right side is three, and the left side is twice the sum of the cosines. Divide both sides by two to recover our bound of three halves. The practice file checks this specialization in Lean. It applies the same theorem to three ones and closes the resulting goal. That is the first reuse pattern: a general identity becomes the particular result you need.
A certificate for three real roots
Now imagine you need to prove that this cubic has three distinct real roots. The graph suggests three crossings of the horizontal axis. How could we turn that picture into evidence Lean can use? R0011 asks for ordered sample points and alternating signs. At minus two, zero, one, and two, the exact values are minus one, one, minus one, and three. Notice the three open intervals. Each pair of consecutive values has strictly opposite signs, so each interval contains a root. The intervals are disjoint. This is why there are at least three distinct roots. We never need to compute the roots themselves. Watch what happens if we remove the constant term. One selected sample is now zero, so this particular certificate no longer meets the strict sign condition. Move that sample from zero to minus one. The four signs alternate again. Different witnesses can certify a different instance of the same problem.
Build a lemma on top of R0011
The practice file does something more general. It defines a lemma named three_real_roots, with four ordered points and three sign conditions. First supply the nonzero polynomial and the vector of sample points to R0011. Two obligations remain. The first obligation is that the vector is strictly increasing. Split into its three adjacent pairs and use the order hypotheses. The second is that the product of each adjacent pair of evaluations is negative. Each case is one of our sign hypotheses. We can now apply our lemma to the original cubic. Evaluating the polynomial at zero shows it is nonzero. Then norm_num checks the three inequalities between sample points and the three inequalities between products of evaluations. In the guide, Lean checks this chain from the generic theorem to the particular cubic. The plot helps us choose inputs for the proof.
Compose two matrix theorems
The next problem begins with a symmetric real matrix. We want a certificate that its quadratic form is a sum of squares. Here is a two by two example with twos on the diagonal and ones off the diagonal. Its characteristic polynomial is t squared minus four t plus three. The coefficients have signs plus, minus, plus. The determinant is three, so the two by two matrix has rank two. R0032 uses symmetry and the sign condition on the coefficients to give positive semidefiniteness. R0033 takes positive semidefiniteness and the rank. It gives a number of squares equal to the rank. For this matrix we can illustrate the result along the two diagonal directions. In ordinary coordinates, the displayed two squares expand to the original form. Recipe Four checks the general composition with symmetry, signs and rank as hypotheses. The companion file checks all three for this matrix and separately proves the displayed identity.
A desk for mathematical workflows
This suggests a way to build a specialized mathematical workflow. Begin with a concrete problem and state the guarantee you want before choosing a theorem. Suppose the requested output is a certificate that the quadratic form is a sum of exactly k squares. Find a theorem whose conclusion has that shape. Read the argument slots. Positive semidefiniteness can come from the preceding theorem. Symmetry, coefficient signs, and rank still need evidence. A calculation with exact coefficients can propose witnesses. The proof needs the exact facts accepted at the input of each theorem. The guide already contains the composed Lean term. A successful check of the abstract theorem confirms that the pieces fit under its hypotheses. To obtain a certificate for a specific matrix, you also need Lean proofs of those hypotheses for that matrix. Excovery already has a planner for tools with typed inputs and outputs. This view sketches a future interface for working at the level of theorem cards. It connects a problem, candidate theorems, open obligations, and the final Lean check. The guide already gives us examples to build from.
Start with the next case
Pick the next case you would like to prove. In the triangle, change the weights. In the cubic, change the sample points. For the matrix, start from the conclusion and work back to the exact coefficients and rank you can certify. A further design uses signs and a degree bound to certify all roots are real, then monicity and a valid index to apply Newton's inequalities. Use the guide and the theorem cards to follow each step to its Lean statement. The downloadable Lean files give you a working starting point.