teorth/analysis: A Lean Companion to Tao's Analysis I
A Lean companion to Analysis I. 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.
At a glance
- What is it?
- teorth/analysis is a Lean 4 formalization of Terry Tao's Analysis I textbook, organized section by section from the Peano axioms through metric spaces. It serves as a machine-checked study companion to the textbook and a guided introduction to Mathlib.
- Who is it for?
- Students who are simultaneously working through Tao's Analysis I and learning Lean will get the most from this repository: each section has a direct textbook counterpart, the sorry stubs mark exactly where proof work begins, and the Chapter 2 epilogue shows concretely how textbook types relate to Mathlib.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 27 days ago.
- What is it written in?
- Mainly Lean, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 25, 2026, and from our analysis. They are not legal advice.
Editorial analysis
What Problem teorth/analysis Solves and Who It Is For
Lean proofs are notorious for demanding that a reader already understand both the mathematics and the proof assistant at once. Tao's Analysis I builds real analysis from scratch, starting with the Peano axioms and constructing integers, rationals, and reals before reaching sequences and continuity. teorth/analysis maps that textbook structure directly into Lean 4, section by section, so a reader can open a .lean file at the same moment they open the corresponding chapter and watch the type-checker confirm or reject each step.
The intended audience is someone working through Analysis I and curious about formal proof, or someone learning Lean who wants a worked corpus grounded in familiar mathematics. The README describes it as "an annotated companion to the primary text, rather than a replacement for it," which means the textbook remains necessary: the Lean files reference specific theorems by number rather than restating the surrounding prose.
Repository Layout and How to Navigate the Sections
The repository uses a standard Lean 4 / Lake project layout. The Analysis/ directory holds one .lean file per section, named to match the textbook: Section_2_1.lean covers the Peano axioms, Section_2_2.lean covers addition, Section_3_1.lean covers set-theory fundamentals, and so on. The top-level Analysis.lean imports all of them. A lake-manifest.json and lakefile.lean specify the dependency tree; a lean-toolchain file pins the exact Lean version required.
Chapter 1 is intentionally absent: the README marks it as "not formalized." Chapters 2 through 7 are covered, taking the reader from natural numbers to metric spaces. Several chapters include epilogue sections that connect the textbook definitions to Mathlib equivalents. The homepage at teorth.github.io/analysis hosts Verso-rendered pages for each section alongside generated API documentation, which makes it possible to browse proofs in a browser without installing Lean.
Getting Started: Cloning and Running the Proofs
The README invites readers to fork the repository to attempt the sorry-marked exercises. A fork also lets contributors submit proofs back as pull requests without modifying the upstream directly. The CONTRIBUTING.md file in the root documents the contribution process.
The README does not provide step-by-step installation instructions; the project homepage at teorth.github.io/analysis is the starting point for setup guidance. Because the project uses Lake, the standard workflow once Lean is installed is to run lake build from the repository root, which fetches Mathlib through the manifest and compiles all sections. The lean-toolchain file specifies the required version, so installing a different Lean version typically causes compilation errors before any proof is checked.
The Mathlib Transition: Textbook Types in Chapter 2, Mathlib Types After
The most consequential design choice in teorth/analysis is its staged migration from self-contained definitions to Mathlib types. Chapter 2 builds natural numbers from scratch using an inductive type, develops addition and multiplication, and proves the Peano axioms independently of Mathlib. This self-contained chapter lets a reader verify that the natural numbers the textbook constructs behave exactly as claimed, without trusting any external library.
Chapter 3 onward uses Mathlib's own types directly. The README explains the reasoning: Mathlib's natural numbers (the standard ℕ) have far more support and better tooling than any textbook-derived type, and using them makes later proofs tractable. The Chapter 2 epilogue proves the isomorphism between the textbook natural numbers and Mathlib's, closing the gap. A similar pattern applies to definitions of sequences: the formalization indexes sequences from zero rather than one, matching Mathlib's convention, because the tooling for 0-based natural numbers is significantly better than for 1-based indexing.
This design means the formalization is not self-contained after Chapter 2. Readers who want to verify Analysis I from first principles will need to trust Mathlib for everything after natural numbers. That is a real constraint, though the README frames it as a deliberate trade-off in favor of Mathlib compatibility.
Junk Values: How Total Functions Replace Partial Definitions
Several places in Analysis I leave operations undefined: division by zero is undefined, and the limit of a non-Cauchy sequence is not assigned a value. Lean works better with total functions than with partial ones, so teorth/analysis assigns junk values (typically 0) to these undefined cases. The README links to a discussion of this pattern by Kevin Buzzard for readers who want the theoretical background.
The junk-value approach affects proof style throughout the formalization. A statement that would be vacuously true in the textbook because the antecedent is never satisfied can require an explicit case analysis in Lean, since the function now returns 0 instead of being undefined. This is one of the places where the formalization departs from idiomatic Lean: a production library would typically use Option types or subtypes to avoid junk values in favor of cleaner dependent-type reasoning. The README explicitly notes that the formalization prioritizes textbook faithfulness over clean Lean style.
Sorry Stubs: Where the Exercises Live
Every exercise left to the reader in Tao's Analysis I is represented in the corresponding .lean file as a sorry. The sorry tactic tells Lean's type-checker to accept an incomplete proof without verification; it compiles but leaves the theorem unproven. This means the repository ships with a significant number of known gaps, and lake build with --warnAsError or any CI configuration that treats sorry as an error will fail.
The README is explicit that solutions will not be merged into the main branch. The project's purpose is to provide the exercise locations and the surrounding proof context, not to hand out answers. A reader who forks the repository and fills in a sorry is doing the work the textbook asks for, with the added constraint that the Lean type-checker must accept the proof. That tight feedback loop is the primary value proposition: analysis intuition can be tested against a machine checker at each step.
teorth/analysis Versus Mathlib's Real Analysis Coverage
Mathlib contains most of the material in Analysis I, developed independently and with different priorities. Mathlib's real analysis coverage is optimized for reuse across the library: definitions are chosen to maximize downstream automation, tactics are idiomatic, and file sizes are kept manageable by splitting large theories into many small files. Mathlib does not follow any particular textbook structure, which makes it challenging to use as a study companion if a reader is working through Tao linearly.
teorth/analysis trades Mathlib's efficiency and proof elegance for direct correspondence with the textbook. A reader who finishes Analysis I using this formalization will have seen concrete Lean proofs of every major theorem in the text. Moving to Mathlib afterward requires learning a different proof style, but the Mathlib transition within the repository (documented in the chapter epilogues) provides a bridge. The two projects are complementary rather than competing: Mathlib is the right choice for research or production Lean development, while teorth/analysis is the right choice for structured study.
Maintenance and license: the repository received its most recent push on 2026-09-05 and is not archived, indicating active work. The Apache-2.0 license permits use, modification, and redistribution, including in academic and commercial contexts, with standard attribution requirements.
Editorial conclusion
Students who are simultaneously working through Tao's Analysis I and learning Lean will get the most from this repository: each section has a direct textbook counterpart, the sorry stubs mark exactly where proof work begins, and the Chapter 2 epilogue shows concretely how textbook types relate to Mathlib. Engineers seeking production-ready Lean abstractions should go to Mathlib directly; the README states the formalization is not optimized for efficiency and may deviate from idiomatic Lean. Before building the project, verify that your local Lean toolchain matches the version pinned in the lean-toolchain file in the repository root, since version mismatches prevent lake build from completing.
Frequently asked questions
What does sorry mean in the teorth/analysis Lean files?
sorry is a Lean 4 tactic that tells the type-checker to accept an incomplete proof without verifying it. In teorth/analysis, sorry marks every exercise from Tao's Analysis I that has been left for the reader; the project intentionally does not provide solutions.
Can I use teorth/analysis without owning a copy of Analysis I?
The README describes the formalization as an annotated companion to the textbook, not a replacement. The Lean files reference specific theorem numbers from the text rather than restating the surrounding prose, so the textbook is necessary to follow the proofs.
Does teorth/analysis cover Analysis II as well?
The README does not document any work on Analysis II. The repository is titled as a formalization of Analysis I, and the section listing in the README covers only those chapters.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/teorth-analysis)