A Lean companion to Analysis I
1,890
stars
1,804
commits
Lean
primary language
Sep 5, 2026
updated
The files in this directory contain a formalization 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 sorrys. 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:
ℕ than the 1-based natural numbers.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.ℝ
I am using this repository to host some other minor Lean content unrelated to the text book:
More resource suggestions welcome!
To build this project after installing Lean and cloning this repository, follow these steps:
% ./build.sh
To build the project's web page after installing Lean and cloning this repository, follow these steps:
% ./build-web.sh
After this, _site/ contains the project's web page.
This can be served as a webpage by executing python3 serve.py
Because this project uses a deprecated method to conditionally require doc-gen4
in order to update the version of Lean and Mathlib used in the project you need to:
lakefile.lean to change the require lines for Mathlib and doc-gen4,
to pin to the tag corresponding to the next Lean version
(it is highly recommended that you update in incremental steps)lean-toolchain to change the Lean version to the next versionlake update -R -Kenv=devlean-toolchain to the latest Lean version;
if so, revert it to the intended version(top 30 of 48)
Lean
99.8%
A Lean companion to Analysis I
1,890
stars
1,804
commits
Lean
primary language
Sep 5, 2026
updated
The files in this directory contain a formalization 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 sorrys. 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:
ℕ than the 1-based natural numbers.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.ℝ
I am using this repository to host some other minor Lean content unrelated to the text book:
More resource suggestions welcome!
To build this project after installing Lean and cloning this repository, follow these steps:
% ./build.sh
To build the project's web page after installing Lean and cloning this repository, follow these steps:
% ./build-web.sh
After this, _site/ contains the project's web page.
This can be served as a webpage by executing python3 serve.py
Because this project uses a deprecated method to conditionally require doc-gen4
in order to update the version of Lean and Mathlib used in the project you need to:
lakefile.lean to change the require lines for Mathlib and doc-gen4,
to pin to the tag corresponding to the next Lean version
(it is highly recommended that you update in incremental steps)lean-toolchain to change the Lean version to the next versionlake update -R -Kenv=devlean-toolchain to the latest Lean version;
if so, revert it to the intended version(top 30 of 48)
Lean
99.8%