Partial Lean formalization of Analysis I
The files in this directory contain a formalization of selected portions of my text Analysis I into Lean. The formalization is intended to be as faithful a paraphrasing as possible to the original text, while also showcasing Lean's features and syntax. In particular, the formalization is not optimized for efficiency, and in some cases may deviate from idiomatic Lean usage.
Portions of the text that were left as exercises to the reader are rendered in this translation as sorry
s. Readers are welcome to fork the repository here to try their hand at these exercises, but I do not intend to place solutions in this repository directly.
While the arrangement of definitions, theorems, and proofs here are closely paraphrasing the textbook, I am refraining from directly quoting material from the textbook, instead providing references to the original text where appropriate. As such, this formalization should be viewed as an annotated companion to the primary text, rather than a replacement for it.
Much of the material in this text is duplicated in Lean's standard math library Mathlib, though with slightly different definitions. To reconcile these discrepancies, this formalization will gradually transition from the textbook-provided definitions to the Mathlib-provided definitions as one progresses further into the text, thus sacrificing the self-containedness of the formalization in favor of compatibility with Mathlib. For instance, Chapter 2 develops a theory of the natural numbers independent of Mathlib, but all subsequent chapters will use the Mathlib natural numbers instead. (An epilogue to Chapter 2 is provided to show that the two notions of the natural numbers are isomorphic.) As such, this formalization can also be used as an introduction to various portions of Mathlib.
In order to align the formalization with Mathlib conventions, a small number of technical changes have been made to some of the definitions as compared with the textbook version. Most notably:
- Sequences are indexed to start from zero rather than from one, as Mathlib has much more support for the 0-based natural numbers
ℕ
than the 1-based natural numbers. - Many operations that are left undefined in the text, such as division by zero, or taking the formal limit of a non-Cauchy sequence, are instead assigned a "junk" value (e.g.,
0
) to make the operation totally defined. This is because Lean has better support for total functions than partial functions (indiscriminate use of the latter can lead into "dependent type hell" in which even very basic manipulations require quite subtle and delicate proofs). See for instance this blog post by Kevin Buzzard for more discussion.
Currently formalized sections:
- Section 2.1: The Peano axioms
- Section 2.2: Addition
- Section 2.3: Multiplication
- Chapter 2 epilogue: Isomorphism with the Mathlib natural numbers
- Section 3.1: Set theory fundamentals
- Section 4.1: The integers
- Section 4.2: The rationals
- Section 4.3: Absolute value and exponentiation
- Section 5.1: Cauchy sequences of rationals
- Section 5.2: Equivalent Cauchy sequences
- Section 5.3: Construction of the real numbers
- Section 5.4: Ordering the reals
Other resources:
- Web page for this project
- Web page for the book
- Blog post announcing this project, Terence Tao, May 31 2025.
- Lean Zulip discussion about this project
- Notes for contributors
General Lean resources:
- The Lean community
- Lean4 web playground
- How to run a project in Lean locally
- The Lean community Zulip chat
- Learning Lean4
- The natural number game
- Mathematics in Lean - Lean textbook by Jeremy Avigad and Patrick Massot
- Mathlib documentation
- Moogle - semantic search engine for Mathlib
- Loogle - expression matching search engine for Mathlib
- LeanSearch - Natural language search engine for Mathlib
- List of Mathlib tactics
- Lean extensions:
- Common Lean pitfalls
- Lean4 questions in Proof Stack Exchange
- The mechanics of proof - introductory Lean textbook by Heather Macbeth
- My Youtube channel has some demonstrations of various Lean formalization, using a variety of tools.
- A broader list of AI and formal mathematics resources.
More resource suggestions welcome!