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. - The Chapter 2 natural numbers are constructed by an inductive type, rather than via a purely axiomatic approach. However, the Peano Axioms are formalized in the epilogue to this chapter.
- Chapter 1: Introduction (possible future expansion)
- Chapter 2: Starting at the beginning: the natural numbers
- Section 2.1: The Peano axioms (Verso page) (Documentation) (Lean source)
- Section 2.2: Addition (Verso page) (Documentation) (Lean source)
- Section 2.3: Multiplication (Verso page) (Documentation) (Lean source)
- Chapter 2 epilogue: Isomorphism with the Mathlib natural numbers (Verso page) (Documentation) (Lean source)
- Chapter 3: Set theory
- Section 3.1: Fundamentals (Verso page) (Documentation) (Lean source)
- Section 3.2: Russell's paradox (possible future expansion)
- Section 3.3: Functions (planned)
- Section 3.4: Images and inverse images (planned)
- Section 3.5: Cartesian products (planned)
- Section 3.6: Cardinality of sets (planned)
- Chapter 3 epilogue: Connections with Mathlib sets (planned)
- Chapter 4: Integers and rationals
- Section 4.1: The integers (Verso page) (Documentation) (Lean source)
- Section 4.2: The rationals (Verso page) (Documentation) (Lean source)
- Section 4.3: Absolute value and exponentiation (Verso page) (Documentation) (Lean source)
- Section 4.4: Gaps in the rational numbers (planned)
- Chapter 5: The Real numbers
- Section 5.1: Cauchy sequences of rationals (Verso page) (Documentation) (Lean source)
- Section 5.2: Equivalent Cauchy sequences (Verso page) (Documentation) (Lean source)
- Section 5.3: Construction of the real numbers (Verso page) (Documentation) (Lean source)
- Section 5.4: Ordering the reals (Verso page) (Documentation) (Lean source)
- Section 5.5: The least upper bound property (Verso page) (Documentation) (Lean source)
- Section 5.6: Real exponentiation, part I (possible future expansion)
- Chapter 5 epilogue: Isomorphism with the Mathlib real numbers (Verso page) (Documentation) (Lean source)
- Chapter 6: Limits of sequences
- Section 6.1: Convergence and limit laws (Verso page) (Documentation) (Lean source)
- Section 6.2: The extended real number system (Verso page) (Documentation) (Lean source)
- Section 6.3: Suprema and Infima of sequences (Verso page) (Documentation) (Lean source)
- Section 6.4: Limsup, Liminf, and limit points (Verso page) (Documentation) (Lean source)
- Section 6.5: Some standard limits (Verso page) (Documentation) (Lean source)
- Section 6.6: Subsequences (Verso page) (Documentation) (Lean source)
- Section 6.7: Real exponentiation, part II (possible future expansion)
- Chapter 6 epilogue: Connections with Mathlib limits (planned)
- Chapter 7: Series
- Section 7.1: Finite series (planned)
- Section 7.2: Infinite series (planned)
- Section 7.3: Sums of non-negative numbers (planned)
- Section 7.4: Rearrangement of series (planned)
- Section 7.5: The root and ratio tests (planned)
- Chapter 8: Infinite sets (planned)
- Chapter 9: Continuous functions on
ℝ
(planned) - Chapter 10: Differentiation of functions (planned)
- Chapter 11: The Riemann integral (planned)
- Appendix A: The basics of mathematical logic (possible future expansion)
- Appendix B: The decimal system (possible future expansion)
- 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
- 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!
To build this project after installing Lean and cloning this repository, follow these steps:
% cd analysis/
% cd analysis/
% lake exe cache get
% lake build
To build the project's web page after installing Lean and cloning this repository, follow these steps:
% cd analysis/
% cd analysis/
% lake exe cache get
% lake -R -Kenv=dev build Analysis:docs
% lake build
% cd ../
% cd book/
% lake exe analysis-book
% cd ../
After this, book/_site/
contains the project's web page.
This can be served as a webpage by executing python3 serve.py