Algebraic computations in Lean

This is a tutorial on doing proofs with a computational flavour using the Mathlib library for the Lean proof assistant.

The phrase “computational flavour” might need some explanation. These are not heavy computations that require two hours running Mathematica, but simply the kind of mildly-painful calculation that might take a couple of paragraphs on paper.

The tutorial focuses on the Gröbner basis tactic polyrith and on the division-cancelling tactic field_simp. There are several other powerful tactics which are commonly needed for “computational” proofs, notably norm_num, norm_cast (and variants), (n)linarith and gcongr. These other tactics are discussed in context as the need arises.

This is an intermediate-level tutorial, requiring familiarity with the syntax of Lean as covered in approximately the first two chapters of Mathematics in Lean. But the focus of the exercises and presentation is on the computations, so don’t worry about understanding every detail of the syntax if you can pick up the general idea.

This tutorial was originally written in Lean 3 in July 2022 when polyrith first appeared. A video of a talk at ICERM following that version of the tutorial is available in ICERM’s video database. The update to Lean 4 was posted in May 2024.

Feedback is very welcome. Email me (Heather Macbeth), or come to the Lean chat room on Zulip and say hello!

Acknowledgements: I have raided the Mathlib contributions of a number of people for examples in this tutorial. Thank you to Johan Commelin, Julian Külshammer and François Sunatori! And particular thanks to Jeremy Avigad, for sharing the Sphinx template for the tutorial; Marc Masdeu and Patrick Massot, for work on the bump to Lean 4; and Rob Lewis, for many conversations about automation in Lean.