11. Mathlib

Draft

One library

The Lean library published in November 2026 as a proof of the Riemann hypothesis states five theorems in its readable edition (Section 12), and the first of them does not write its own statement. Its type is RiemannHypothesis, a definition of five lines in Mathlib, the library of mathematics for Lean, and that definition speaks of complex numbers and of a function riemannZeta. Neither is built into Lean. The kernel of Section 6, the small program that checks every term, knows function types, inductive types and universes, and among numbers it treats only the natural numbers specially. Everything else is a definition in a file, made from earlier definitions, and can be read. This part reads them: how one library builds the real numbers, limits and the zeta function out of those few rules, and how a statement written in such a library has to be read by someone who means to rely on it.

In the argument of the series this closes the third step, a library built from the same few rules, and opens the fourth: the statement and every definition under it are the first links of the chain of trust that Section 13 takes apart, and whether they say what is meant is left to a reader. The statement cannot be read before its function, the function before the limits it is made of, and none of it before the numbers and the arithmetic it is written in. So the part begins with the numbers and climbs to the statement.

ladder   43 definitions lead from the natural numbers (bottom) to the statement of the Riemann
         hypothesis (top), 333 lines of source in all. Each stands above the ones its text names.
         After a name: the modules its file imports, directly or through other files

           RiemannHypothesis             4,889
           riemannZeta                   4,889
           HurwitzZeta.hurwitzZetaEven   4,885
           WeakFEPair.Λ                  4,496
           mellin                        4,495
           jacobiTheta₂                  4,870
           Complex.exp                   3,161
           Complex                       2,418
         ▸ Real                          2,387    structure Real where ofCauchy ::
           CauSeq.Completion.Cauchy      2,370      /-- The underlying Cauchy completion -/
           CauSeq                        2,368      cauchy : CauSeq.Completion.Cauchy (abs : ℚ → ℚ)
           Rat                             157
           Int                              14
           Nat                               0

         ▸ the rung in focus, rung 10: Real, with the lines that declare it
           (Mathlib/Basic/Real/Basic.lean, lines 36 to 38); its text names two rungs below it
(the live figure needs JavaScript and loads about 0.1 MB of data)
The definitions under the statement of the Riemann hypothesis in Mathlib, as a ladder climbed from the natural numbers. Green: the rung in focus, with its lines as the source writes them: the marked lines are the declaration, the underlined names the rungs it is defined from. A rung's length is the number of modules its file imports, directly or through other files, an upper bound on what the definition can depend on. Everything is read as text at the commit the readable edition of the proof is built on; nothing was built. Step, or click a rung or a name.

Forty-three definitions, 333 lines of source with their comments, lead from the natural numbers to the statement, each a few lines made from the ones below it: 39 in Mathlib and four in Lean's core library. The order is not a textbook's. The file of Rat imports 157 modules (files of Lean source), directly or through other files. One rung up, IsCauSeq, the definition of a Cauchy sequence, stands in a file that imports 2,368: Mathlib defines Cauchy sequences once, in any ring with an absolute value that takes its values in any ordered field, so rings and ordered fields come before the real numbers. The file of the statement imports 4,889. The introduction unfolds the same definitions the other way, from the statement down.

That import curve reflects Mathlib's foundational wager, visible on a single theorem. Mathlib permits only one definition of the real numbers, one definition of a ring, and one definition of a limit, and every file downstream builds on those exact definitions: 12 of the rungs above Real reference it directly. The wager is that all of contemporary mathematics can share a single unified hierarchy; the price is that every foundational definition must accommodate every future caller, so each is stated in greater generality than any single theorem needs. Kevin Buzzard, one of the mathematicians who joined the project early, recounts how that design took shape:

The principal developer of the Lean Theorem Prover is Leonardo de Moura, who started the project in 2013. At the 2017 Big Proof conference in Cambridge it was decided to split off most of the “mathematical” part of the prover from the “core” part, and move the mathematics into a library of its own. Thus mathlib was born. At the time mathlib contained definitions of groups, rings and topological spaces, filters, a construction of the rational numbers (the naturals and integers remained in core Lean), and little else. Johannes Hölzl and Mario Carneiro became the maintainers of the library, and between them they began to slowly build more mathematics, for example, the real numbers. Hölzl had written a lot of the topology part of the repository, following the Isabelle/HOL approach which relied heavily on the concept of a filter. Carneiro wrote a robust theory of finiteness, and slowly the library began to become relevant to the “working mathematician”.

The library is a free and open source project. It is monolithic in the sense that there is one definition of a group, one definition of a ring, one definition of the real numbers and so on, and all of these definitions can be imported simultaneously and interact with each other. Initially it was not clear what its goals were, other than being a place where people could experiment with doing mathematics in Lean. Mathematicians such as Scott Morrison, myself and Patrick Massot got involved at a very early stage, and because our background was in mathematics which relied on classical logic (i.e., the law of the excluded middle) and other non-constructive axioms such as the axiom of choice, the library developed with these classical assumptions at its core. Each successful mathematics project written in Lean and powered by mathlib seemed to attract more mathematicians to its chatroom, which in turn led to more projects. Within a couple of years Lewis had formalised the p-adic numbers [Lew19], myself and a team of undergraduates (Lau, Hughes, Livingston and Fernández Mir) formalised schemes [BHL+21], Dahmen, Hölzl and Lewis formalised the 2017 Ellenberg–Gijswijt Annals proof of the cap set conjecture [DHL19], and Massot, Commelin and myself formalised the definition of a perfectoid space [BCM20]. Each of these projects could not have happened without mathlib; conversely each of these projects contributed to the growth of mathlib.

—Kevin Buzzard, "What is the point of computers? A question for pure mathematicians" (2021). arXiv 2112.11598 (version 2 of 18 April 2022), the companion paper to his talk at the International Congress of Mathematicians of 2022; Section 2, "mathlib", p. 14: its second and third paragraphs, whole; the keys in brackets are the paper's references. The passage speaks of 2017: at the commit used here the rational numbers are in Lean's core library as well.

At the commit that the readable edition is built on, of 13 October 2026, the library has 8,624 files and 2,340,927 lines. Its mathematics is, in its authors' words, "contemporary mathematics, which is resolutely classical":The mathlib Community, "The Lean mathematical library", CPP 2020 (arXiv 1910.09336), Section 9. The commit is 56a0058 of Mathlib, "chore: bump toolchain to v4.35.0 (#44806)"; files and lines are those of its folder Mathlib/, comments and blank lines included. the axioms of Section 7 are used without ceremony, and the ladder holds an example, π defined as twice a zero of the cosine between 1 and 2 that the axiom of choice picks.

One methodological boundary must be stated plainly at the outset. This part reads Mathlib as source text; it does not run it. Lean never elaborated Mathlib for this series, meaning it never translated the library's files into closed kernel terms (Section 9). Every statement about Mathlib here comes either verbatim from its source text at that October 2026 commit or from static counts over those files. How Lean's elaborator behaves on such definitions (which type class route it picks, or how implicit casts expand) is demonstrated live only on small standalone files that run without importing Mathlib (Section 11.8). What the page computes directly is the analytic object at the top of the ladder: the Riemann zeta function along the critical line, checked against a published table of zeros (Section 11.7).

Five architectural choices hold a monolithic library together at this scale, and auditing any formal statement in Mathlib requires understanding all five.

Five decisions that keep one librarya row to a design choice of Mathlib; in ink, a line of its source at the commit the readable edition of the proof is built on

  1. 11.3algebra as type classes one + for every structure

    A class is a record of operations and proofs with the carrier as a parameter, and an instance says that a type has one. A lemma is proved once for the class and Lean finds the instance. The routes from class to class must agree by definition.

    class Field (K : Type u)

    extends CommRing K, DivisionRing K

    18 routes from Field to AddZeroClass

  2. 11.3bundled maps a homomorphism is one object

    A map that preserves structure is a structure of its own: the function together with the proofs that it preserves the operations. A lemma takes the object, and nothing about the map is left for a search to find.

    def ofRealHom : ℝ →+* ℂ

    a function and four proofs

  3. 11.4filters one definition of limit

    A way of approaching (a point, a point from one side, infinity) is the family of sets that are reached eventually. A limit is one inequality between two such families, and each lemma about limits is proved once.

    Tendsto f l₁ l₂ := l₁.map f ≤ l₂

    64 kinds of statement, one definition

  4. 11.6total functions junk values

    Every function is defined everywhere. Where the mathematics has no value the library picks one, and the condition moves from the function to the theorems about it. A statement then says what the definitions make it say.

    theorem div_zero (a : G₀) : a / 0 = 0

    riemannZeta 1 = (γ - log (4 * π)) / 2

  5. 11.8simp normal forms one way to write each thing

    Where an expression can be written in several ways the library fixes one, the form that its simplifier rewrites toward, and states its lemmas in it. A name then spells a statement, and a lemma can be found by guessing its name.

    ofReal_natCast (n : ℕ) : ofReal n = n

    tagged @[simp, norm_cast], proved by rfl

green: the choice that changes what a statement says

The reading starts at the bottom, since a rung says only what the rungs under it make it say.

The numbers

The bottom of the ladder is the number systems, and no two of them are made the same way. How numbers are made decides what it takes to show two of them equal.

Five number systems, five constructionsfrom the natural numbers up: each type of numbers is made from the one before it, and no two are made the same way

from ℕ to ℂ

  1. 11.2ℕ, an inductive type Lean's core library · Two constructors, zero and succ. The one type of numbers that the kernel treats specially.

  2. 11.2ℤ, a second inductive type Lean's core library · Two constructors: ofNat for 0, 1, 2, … and negSucc for −1, −2, …, so that every integer is written in exactly one way. No quotient.

  3. 11.2ℚ, a structure with proofs Lean's core library · A numerator, a denominator, a proof that the denominator is not 0 and a proof that the two are coprime: a normal form in place of a quotient.

  4. 11.2ℝ, a quotient Mathlib · Cauchy sequences of rationals up to those that tend to zero, wrapped in a structure, with the operations sealed so that the construction stays hidden.

  5. 11.2ℂ, a pair of reals Mathlib · A structure with two real fields, re and im. A real number enters by the map r ↦ ⟨r, 0⟩, which the elaborator inserts as a coercion.

green: the one step that takes a quotient

The natural numbers Nat are an inductive type in Lean's core library with constructors zero and succ (Section 5). They are the sole number system about which the kernel knows more than the inductive declaration states; Nat is, in the words of its docstring, "special-cased by both the kernel and the compiler, and overridden with an efficient implementation". Where an algebra textbook constructs \(\mathbb Z\) as equivalence classes of pairs of natural numbers and \(\mathbb Q\) as equivalence classes of fractions, Lean's core library avoids quotients twice in favor of canonical normal forms. Int is a second inductive type with constructor ofNat for \(0, 1, 2, \dots\) and constructor negSucc for \(-1, -2, \dots\), giving every integer a unique representation. Rat is a four-field structure storing an integer numerator, a natural denominator, a proof that the denominator is nonzero, and a proof that numerator and denominator are coprime. Because 1/2 and 2/4 reduce to the exact same canonical record, equality on Int and Rat can be decided directly by computation without lifting operations across quotient equivalences.

The real numbers have no normal form, and here Mathlib does take the quotient. It begins with what a Cauchy sequence is:

/-- A sequence is Cauchy if the distance between its entries tends to zero. -/
@[nolint unusedArguments]
def IsCauSeq {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
    {β : Type*} [Ring β] (abv : β → α) (f : ℕ → β) :
    Prop :=
  ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε

Definition 11.2.1 (the real numbers of Mathlib). Let abv be a function from a ring \(\beta\) to a linearly ordered field \(\alpha\). A sequence \(f : \mathbb N \to \beta\) is Cauchy if for every \(\varepsilon > 0\) in \(\alpha\) there is an \(i\) such that \(\mathrm{abv}(f_j - f_i) < \varepsilon\) for all \(j \ge i\). CauSeq β abv is the type of Cauchy sequences. When abv is an absolute value, two of them are equivalent if their difference tends to zero, and CauSeq.Completion.Cauchy abv is the quotient by that relation. The type Real is a structure with one field, an element of CauSeq.Completion.Cauchy (abs : ℚ → ℚ).

The opening comment of Real/Basic.lean explains why Mathlib chose Cauchy sequences over Dedekind cuts: "This choice is motivated by how easy it is to prove that ℝ is a commutative ring, by simply lifting everything to ℚ." Two engineering details protect users from that construction afterward. First, Real wraps the quotient inside a single-field structure rather than defining Real as a transparent type alias; second, its basic operations and order are marked private irreducible_def, as in private irreducible_def add : ℝ → ℝ → ℝ. Without those barriers, tactics like simp or unification could accidentally unfold real arithmetic into equivalence classes of rational sequences, slowing elaboration and leaking implementation details. Instead, downstream files interact with ℝ strictly through its proved algebraic and order interfaces: that ℝ forms a commutative ring and a field (two instances in the same file, Section 11.3) and, in a subsequent file, "a conditionally complete linear order" (the least upper bound property). Nothing higher on the ladder ever needs to know how a real number was built. One rung above Real, Complex is a plain two-field structure storing real parts re and im.

The construction can be hidden. The borders between the types cannot, and the statement crosses one, with a natural number n in an equation between complex numbers.

Remark 11.2.2 (five types, four maps). On paper \(\mathbb N \subset \mathbb Z \subset \mathbb Q \subset \mathbb R \subset \mathbb C\), and one identifies along the inclusions without comment. Here these are five types, a term of one is not a term of another, and each inclusion is a function. The one from ℝ to ℂ is def ofReal (r : ℝ) : ℂ := ⟨r, 0⟩, registered as a coercion: a function that the elaborator, the program that completes what a person writes (Section 9), inserts where a real number stands and a complex one is expected, and that Lean prints as ↑. A natural number becomes a complex number through the reals: the file defines natCast n := ofReal n. The numeral 2 is a different term at each of the five types. Section 11.6 has to find these maps in the statement of the hypothesis, because the kernel checks the statement with them in it.

That settles the types. The signs between them are still open: one + and one / are written at all five.

Algebra as type classes

Take x + 0 = x for a real number x. The theorem that proves it is not about the reals, and the + and the 0 in that theorem's statement are not the addition and the zero of the reals. All three come from a type class: a structure of operations and of proofs about them (Section 8), a value of which the elaborator finds by a search and passes as a hidden argument (Section 9). The reals enter through instances, the values of such structures that are declared for a type.

graph    51 classes, from Field (top) down to the 17 that extend nothing (Add, Zero, Mul, One ...),
         joined by 86 "extends"; 18 routes lead from Field to AddZeroClass, the class that holds
         x + 0 = x. Route 3 of 18, by first parents as far as they go:

         Field            class Field (K : Type u) extends CommRing K, DivisionRing K
          └ CommRing
             └ Ring
                └ Semiring
                   └ AddCommMonoid
                      └ AddMonoid
                         └ AddZeroClass     protected add_zero : ∀ a : M, a + 0 = a      (line 69)

on ℝ     the file of the real numbers writes no instance of AddZeroClass; it proves the field inside
         instance commRing : CommRing ℝ where                                              (line 176)
           add_zero a := by apply ext_cauchy; simp [cauchy_add, cauchy_zero]               (line 182)
(the live figure needs JavaScript and loads about 0.12 MB of data)
The classes of Mathlib's algebraic hierarchy from Field down to the notation classes, read from the source: a hairline from a class down to each class it extends. Green: one of the routes along extends from Field to AddZeroClass, whose field add_zero is x + 0 = x. Grey ground: a class of which the file of the real numbers declares ℝ an instance. Below: the class in focus as written, and what that file writes for it. The text allows every route; which one Lean's instance search takes was not observed. Step through the routes; click a class.

Where in that hierarchy is x + 0 = x stated, where is it proved for ℝ, and how does Lean connect the two?

Example 11.3.1 (x + 0 = x on the reals). Reading Mathlib's source text at the commit of 13 October 2026 (with nothing elaborated), the law x + 0 = x is the field add_zero : ∀ a : M, a + 0 = a of the weak class AddZeroClass. For ℝ, that identity is proved once at line 182 of Real/Basic.lean inside instance commRing : CommRing ℝ, by descending to the quotient of rational Cauchy sequences; the file never declares a standalone AddZeroClass ℝ instance. Connecting Field ℝ or CommRing ℝ down to AddZeroClass ℝ are chains of generated structure projections, one projection per extends edge. Across the 51 classes and 86 extends edges between Field and the bare notation classes, the source graph permits 18 distinct projection routes from Field down to AddZeroClass. Which route Lean's tabled search actually traverses on ℝ was not observed here, because Mathlib was not built. ◁

The file of the reals suggests that the search need not even begin at Field:

/-! Extra instances to short-circuit type class resolution.

These short-circuits have an additional property of ensuring that a computable path is found; if
`Field ℝ` is found first, then decaying it to these typeclasses would result in a `noncomputable`
version of them. -/

instance instRing : Ring ℝ := by infer_instance
-- ...
instance : AddMonoid ℝ := by infer_instance

Each of these lines has Lean find an instance once and records the result as an instance of its own, where a later search for AddMonoid ℝ can end. The comment's second reason belongs to Section 7: the inverse of a real number is declared noncomputable, the mark of a definition that the compiler cannot turn into a program, the instance Field ℝ with it, and whatever is reached through that instance would be so too.

Because type class search commits to the first solution it finds (Example 9.4.2) and hides the winning term inside implicit arguments, two theorems about ℝ can easily pick up AddZeroClass ℝ or TopologicalSpace (X × Y) along two different routes. If those two routes do not produce the exact same instance up to definitional equality, applying one theorem to the other fails in the kernel with a type mismatch.

Remark 11.3.2 (the routes must agree by definition). Every path to a type class on a given type must yield not merely isomorphic or propositionally equal structures, but structures that are definitionally equal (Section 6), so that the kernel equates them by unfolding definitions alone. Eric Wieser's study of hierarchy hazards states the requirement bluntly: "Unless all possible paths are considered judgmentally equal, this is a recipe for disaster."E. Wieser, "Multiple-inheritance hazards in dependently-typed algebraic hierarchies", arXiv 2306.00617 (2023), the abstract. Judgmentally equal is equal by definition. Mathlib's own design note contrasts two ways of extracting a weaker structure (such as a topology) from a richer one (such as a metric): either write an external instance function computing a TopologicalSpace from any MetricSpace, or make MetricSpace directly extend TopologicalSpace ("forgetful inheritance") so the topology sits inside the metric space record as pre-existing data fields. The note illustrates why the first design breaks on products:

To illustrate this, consider the pair MetricSpace / TopologicalSpace. Consider the topology on a product of two metric spaces. With the first approach, it could be obtained by going first from each metric space to its topology, and then taking the product topology. But it could also be obtained by considering the product metric space (with its sup distance) and then the topology coming from this distance. These would be the same topology, but not definitionally, which means that from the point of view of Lean's kernel, there would be two different TopologicalSpace instances on the product. This is not compatible with the way instances are designed and used: there should be at most one instance of a kind on each type. This approach has created an instance diamond that does not commute definitionally.

—Mathlib, the library note "forgetful inheritance". Mathlib/Algebra/Group/Monoid.lean, lines 156 to 205, at the commit of 13 October 2026; this is the second paragraph of the note, which ends by sending its reader to a paper, "Competing inheritance paths in dependent type theory: a case study in functional analysis".

Forgetful inheritance also explains why Mathlib classes store extra operations that look mathematically redundant. Mathematically, an additive monoid needs only + and 0, since multiplying an element by a natural number (n • a) is uniquely determined by repeated addition. Yet if AddMonoid defined n • a externally by recursion on n, then on ℤ (which is also a ring) n • k via AddMonoid would be recursive addition while n • k via module multiplication would be integer multiplication ↑n * k: equal as integers, yet not definitionally equal when n and k are variables. To prevent that diamond, AddMonoid stores nsmul : ℕ → M → M as an explicit data field inside the class (defaulting to recursive nsmulRec when no conflict threatens, as ℝ uses, while allowing ℤ to plug in native multiplication at the root so every path projects out the identical operation). Similarly, DivisionRing carries explicit ratCast and qsmul fields, which its docstring explains are needed "to implement the DivisionRing K → Algebra ℚ K instance since we need to control the specific definitions for some special cases of K (in particular K = ℚ itself)". Every class in Mathlib bundles its textbook axioms together with whatever auxiliary operations are needed to make all inheritance diamonds commute by definition.

Two further conventions govern when Mathlib uses type classes versus ordinary records, both aimed at keeping instance search unambiguous. First, algebraic classes leave the carrier type outside as a parameter (Field ℝ, a field structure placed on the type ℝ, rather than a single bundled record containing both carrier and operations) because, in its authors' words, "a type class problem should have (essentially) at most one solution, and only the parameters affect the type class search".The mathlib Community (2020), Section 4.1.1, where such classes are called semi-bundled, "with all operations being bundled except for the carrier types". Morphisms between structures make the opposite choice. Because many different homomorphisms can exist between two rings R and S (and many functions R → S are not homomorphisms at all), Mathlib bundles a homomorphism into a single record pairing the underlying function with proofs that it preserves the operations:

/-- The coercion `ℝ → ℂ` as a `RingHom`. -/
@[instance_reducible]
def ofRealHom : ℝ →+* ℂ where
  toFun x := (x : ℂ)
  map_one' := ofReal_one
  map_zero' := ofReal_zero
  map_mul' := ofReal_mul
  map_add' := ofReal_add

ℝ →+* ℂ is notation for the structure RingHom. A lemma about ring homomorphisms takes such an object as its argument, and the four proofs travel with the function; nothing about the map is left for a search to find.

That is the arithmetic of the statement. Its function is made of an integral and of limits, so the limit has to be read next.

Limits once

A course of analysis defines the limit of a sequence, then the limit of a function at a point, then limits from one side, limits at infinity and infinite limits, and proves the same lemmas for each. The book Mathematics in Lean counts them: eight ways for x to approach something (a point, from the right or from the left, each with or without the point itself, and plus or minus infinity), as many for f(x), hence 64 kinds of statement. Mathlib has one.

statement   Tendsto f (𝓝[≠] 1) (𝓝 1)       f = fun s ↦ (s - 1) * riemannZeta s, drawn for real s
            in Mathlib: the lemma riemannZeta_residue_one
unfolded    := (𝓝[≠] 1).map f ≤ 𝓝 1                                     def Tendsto
            ↔  ∀ V ∈ 𝓝 1, f ⁻¹' V ∈ 𝓝[≠] 1                              tendsto_def
            ↔  ∀ ε > 0, ∃ δ > 0, ∀ s, 0 < |s − 1| < δ → |f s − 1| < ε    HasBasis.tendsto_iff
picture     the graph of f over the whole line, −∞ and +∞ its two ends, with f 1 = 0 as Lean computes it
            V = (0.75, 1.25), a set of 𝓝 1: a band across the graph, hatched outside       ε = 0.25
            under the line: f⁻¹(V), and inside it, in green,
            U = (0.588, 1.412) ∖ {1}, a set of 𝓝[≠] 1 that f maps into V                   δ = 0.412
table       8 filters by 8 filters = 64 statements about one f. A set U at each of the 7 sizes of V tried:
            (s − 1) ζ(s)  11 of 64, 1 of them a lemma of Mathlib      x⁻¹    10 of 64, 6 lemmas
            log x          5 of 64, 4 lemmas                          exp x  16 of 64, 2 lemmas
(the live figure needs JavaScript; it loads no data)
Green: the set U of the filter l₁ that f maps into the chosen set V of l₂; Tendsto f l₁ l₂ asks for such a U for every V. Ink bar and band: V, hatched outside. Under the line: the preimage of V and five sets of l₁. Both lines are squeezed outside their middle half, so that −∞ and +∞ are their ends. The dot is the value Lean gives f at the point. Choose f, a row (l₁) and a column (l₂) of the 64; drag an edge of V. Sets are computed on samples, not proved; ringed cells are lemmas of Mathlib.

The problem is compounded even further when it comes to the supporting lemmas. For instance, limits compose: if f x tends to y₀ when x tends to x₀ and g y tends to z₀ when y tends to y₀ then g ∘ f x tends to z₀ when x tends to x₀. There are three notions of “tends to” at play here, each of which can be instantiated in any of the eight ways described in the previous paragraph. This results in 512 lemmas, a lot to have to add to a library! Informally, mathematicians generally prove two or three of these and simply note that the rest can be proved “in the same way.” Formalizing mathematics requires making the relevant notion of “sameness” fully explicit, and that is exactly what Bourbaki’s theory of filters manages to do.

—Jeremy Avigad and Patrick Massot, Mathematics in Lean, chapter 11. The last of the six paragraphs that open the chapter on topology, in the copy that calls itself "Mathematics in Lean v4.34.0 documentation" (online). The eight ways it refers to are counted two paragraphs before it, and are the ones at the head of this section.

The idea is to make "x approaches a" into an object. A way of approaching is known once one knows which sets are reached eventually: for x going to infinity, the sets that contain a half-line; for x going to a, the sets that contain an interval around a; for x going to a without touching it, the sets that contain such an interval with a taken out. Such a family of sets is a filter, and "f(x) approaches b as x approaches a" becomes one relation between two filters.

structure Filter (α : Type*) where
  /-- The set of sets that belong to the filter. -/
  sets : Set (Set α)
  /-- The set `Set.univ` belongs to any filter. -/
  univ_sets : Set.univ ∈ sets
  /-- If a set belongs to a filter, then its superset belongs to the filter as well. -/
  sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets
  /-- If two sets belong to a filter, then their intersection belongs to the filter as well. -/
  inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets
-- ...
def Tendsto (f : α → β) (l₁ : Filter α) (l₂ : Filter β) :=
  l₁.map f ≤ l₂

Definition 11.4.1 (filter, push-forward, limit). A filter on a type \(\alpha\) is a set \(F\) of subsets of \(\alpha\) that contains \(\alpha\) itself, every superset of a member, and the intersection of any two members. (Mathlib allows the filter of all subsets, which Bourbaki excludes.) For filters \(F\) and \(G\) on \(\alpha\), \(F \le G\) means that every set of \(G\) is a set of \(F\). The push-forward of \(F\) under \(m : \alpha \to \beta\) is the filter \(\mathrm{map}\; m\; F\) of all \(V \subseteq \beta\) with \(m^{-1}(V) \in F\). For \(f : \alpha \to \beta\), a filter \(l_1\) on \(\alpha\) and a filter \(l_2\) on \(\beta\),

\[\mathrm{Tendsto}\; f\; l_1\; l_2 \quad\text{means}\quad \mathrm{map}\; f\; l_1 \le l_2, \quad\text{that is,}\quad f^{-1}(V) \in l_1 \ \text{ for every } V \in l_2 .\]

At first glance the ordering \(F \le G\) (meaning \(G \subseteq F\) as families of subsets) looks backward, yet geometrically it points the right way. Picture a filter as a cloud of points concentrated around a target: shrinking the cloud more tightly around \(a\) makes it fit inside more supersets, so a tighter, smaller cloud corresponds to a larger collection of supersets. Reversing family inclusion aligns \(\le\) with geometric containment of clouds. As Mathematics in Lean puts it, viewing a filter as "a generalized element of Set X", with atTop (sets containing some \([N, \infty)\)) representing arbitrarily large numbers and 𝓝 a (neighborhoods of \(a\)) representing points arbitrarily close to \(a\), turns l₁.map f ≤ l₂ into plain containment: the image cloud \(f(l_1)\) lands inside \(l_2\). All eight standard ways of approaching a limit become eight instances of Filter: 𝓝 a; the restricted neighborhood filter 𝓝[s] a cut down to a subset \(s\), where \(s\) is either {a}ᶜ (the punctured neighborhood 𝓝[≠] a) or one of the four open or closed half-lines at \(a\); plus atTop and atBot.

One definition pays only if each lemma is proved once too. The book's example was composition.

Proposition 11.4.2 (limits compose). If Tendsto f l₁ l₂ and Tendsto g l₂ l₃, then Tendsto (g ∘ f) l₁ l₃.

Proof. Let \(W \in l_3\). Then \(g^{-1}(W) \in l_2\) by the second hypothesis, so \(f^{-1}(g^{-1}(W)) \in l_1\) by the first, and this set is \((g \circ f)^{-1}(W)\). ∎

Mathlib's proof is the same two steps, written as the term that they are (Section 4):

theorem Tendsto.comp {f : α → β} {g : β → γ} {x : Filter α} {y : Filter β} {z : Filter γ}
    (hg : Tendsto g y z) (hf : Tendsto f x y) : Tendsto (g ∘ f) x z := fun _ hs => hf (hg hs)

One lemma, "yielding in one shot all 512 variants of the composition lemma", as the book says. The ε and the δ have not gone. They have become theorems: for each of these filters the library proves a basis, a family of sets that generates it (balls around a point, half-lines), and one theorem, Filter.HasBasis.tendsto_iff, turns a limit between two filters with bases into the statement with quantifiers. For a point a of one metric space and a point b of another the result is Metric.tendsto_nhds_nhds, which reads Tendsto f (𝓝 a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, dist x a < δ → dist (f x) b < ε.

Which exact filter appears in a theorem header is part of the mathematical claim an auditor must check, as the first lemma about \(\zeta\) read here illustrates.

Example 11.4.3 (the residue of ζ at 1, and why the neighborhood is punctured). In the file defining the Riemann zeta function, the lemma riemannZeta_residue_one states Tendsto (fun s ↦ (s - 1) * riemannZeta s) (𝓝[≠] 1) (𝓝 1) (drawn in the figure for real \(s\) by sampling the function numerically on the page, without proving any limit there). Unfolded via metric bases, the lemma says that for every \(\varepsilon > 0\) there exists \(\delta > 0\) such that \(\lvert (s-1)\,\zeta(s) - 1 \rvert < \varepsilon\) whenever \(0 < \lvert s - 1 \rvert < \delta\). Puncturing the domain filter via 𝓝[≠] 1 rather than writing 𝓝 1 is essential. Because every function in Lean is total on its domain type, riemannZeta 1 evaluates to some finite complex number (identified in Section 11.6), so at \(s = 1\) the product (1 - 1) * riemannZeta 1 evaluates to 0, giving the function a removable jump from limit 1 to value 0 right at 1. Had the author written the unpunctured filter 𝓝 1, every neighborhood \(U \in \mathcal{N}(1)\) would include \(s = 1\) itself, mapping 1 to 0 and making the theorem false. Across the 64 limit statements formed by pairing the eight standard filters on domain and codomain (taking the six local filters at 1), 11 hold for (s - 1) * riemannZeta s, all expressed by passing different filter arguments to the single definition Tendsto. ◁

The lemma leaned on two things not yet read: the function riemannZeta, and its value where ζ has none.

The zeta function

At the top of the ladder stand two definitions of one file. Each is a link the reader has to audit, since what the theorem says is what these lines say.

/-- The Riemann zeta function `ζ(s)`. -/
@[wikidata Q187235]
def riemannZeta := hurwitzZetaEven 0
-- ...
/-- A formal statement of the **Riemann hypothesis** – constructing a term of this type is worth a
million dollars. -/
@[wikidata Q205966]
def RiemannHypothesis : Prop :=
  ∀ (s : ℂ) (_ : riemannZeta s = 0) (_ : ¬∃ n : ℕ, s = -2 * (n + 1)) (_ : s ≠ 1), s.re = 1 / 2

A reader who expects \(\sum n^{-s}\) finds neither a series nor a continuation. The series converges only for \(\mathrm{Re}\, s > 1\), and "the analytic continuation of the series" cannot be a definition before the continuation is known to exist. The file that does the work says so:

Of course, we cannot *define* these functions by the above formulae (since existence of the
meromorphic continuation is not at all obvious); we in fact construct them as Mellin transforms of
various versions of the Jacobi theta function.

So Mathlib defines ζ on all of ℂ at one stroke, by the formula of Riemann's second proof of the functional equation: the Mellin transform of a theta function, corrected at its two poles and divided by the Gamma factor. It does so once for a family, the even Hurwitz zeta functions, in which ζ is the member with parameter 0.

def completedHurwitzZetaEven (a : UnitAddCircle) (s : ℂ) : ℂ :=
  ((hurwitzEvenFEPair a).Λ (s / 2)) / 2
-- ...
noncomputable def hurwitzZetaEven (a : UnitAddCircle) :=
  Function.update (fun s ↦ completedHurwitzZetaEven a s / Gammaℝ s)
  0 (if a = 0 then -1 / 2 else 0)

To audit the function by its definition is to follow those names down. This is where they lead.

Definition 11.5.1 (the zeta function of Mathlib, unfolded). For \(x > 0\) let \(\theta(x) = \sum_{n \in \mathbb Z} e^{-\pi n^2 x}\), and for complex \(s\) let

\[\begin{aligned} \Lambda_0(s) &= \tfrac12 \int_1^\infty t^{s/2 - 1}\bigl(\theta(t) - 1\bigr)\,dt \;+\; \tfrac12 \int_0^1 t^{s/2 - 1}\bigl(\theta(t) - t^{-1/2}\bigr)\,dt, \\ \Lambda(s) &= \Lambda_0(s) - \frac1s - \frac1{1 - s}, \qquad \Gamma_{\mathbb R}(s) = \pi^{-s/2}\,\Gamma(s/2). \end{aligned}\]

Then riemannZeta s is \(\Lambda(s) / \Gamma_{\mathbb R}(s)\) for \(s \ne 0\), and \(-1/2\) for \(s = 0\), every operation in these formulas being Lean's total one (Section 11.6).

The unfolding is by hand, from the source lines of the rungs between riemannZeta and the theta function; Lean was not asked. Both integrals converge for every s, since \(\theta(t) - 1\) decays like \(e^{-\pi t}\) and \(\theta(t) - t^{-1/2}\) is \(t^{-1/2}(\theta(1/t) - 1)\) by the transformation law of θ. So \(\Lambda_0\) is entire, and for \(\mathrm{Re}\, s > 1\) Riemann's computation gives \(\Lambda(s) = \pi^{-s/2}\,\Gamma(s/2)\,\zeta(s)\). A construction is not yet the zeta function, though. Two theorems of the same file make it one.

Theorem 11.5.2 (Mathlib, as its source states them). (i) For every \(s \ne 1\) the function riemannZeta is complex differentiable at \(s\) (differentiableAt_riemannZeta). (ii) For \(\mathrm{Re}\, s > 1\), riemannZeta s = ∑' n : ℕ, 1 / (n + 1 : ℂ) ^ s (zeta_eq_tsum_one_div_nat_add_one_cpow).

Both (i) and (ii) are formal theorems in Mathlib's source. By classical complex analysis on paper, those two properties leave no freedom in what the function can be away from \(s = 1\).

Proposition 11.5.3 (what identifies the function). A function on \(\mathbb C\) with the properties (i) and (ii) agrees with the Riemann zeta function at every \(s \ne 1\).

Proof. By (i) the function is holomorphic on \(\mathbb C \setminus \{1\}\), which is open and connected, and so is ζ. For \(\mathrm{Re}\, s > 1\) the series converges absolutely, so the sum in (ii) is its sum, and the two functions agree on that half-plane. Holomorphic functions on a connected open set that agree on a nonempty open subset agree on all of it. ∎

Uniqueness of analytic continuation lets an auditor forget the construction of Definition 11.5.1. Replace that Hurwitz-Jacobi-Mellin formula by any other definition satisfying Theorem 11.5.2, and riemannZeta s takes the exact same values at every \(s \ne 1\). Auditing the function itself therefore reduces to auditing the definitions used in Theorem 11.5.2 (complex differentiability, infinite sums ∑', and complex powers) rather than inspecting Mellin transforms. Auditing the main theorem statement, however, still requires looking directly at how it phrases the hypothesis, especially at the pole \(s = 1\) where Proposition 11.5.3 says nothing.

Reading a statement like an auditor

Whether the five lines of RiemannHypothesis express what mathematicians mean by the conjecture is a link in the chain of trust that no computer program can check. A standard reference work of the field, the Digital Library of Mathematical Functions published by the United States National Institute of Standards and Technology (NIST), states the conjecture as follows:

The product representation (25.2.11) implies ζ(s)≠0 for ℜs>1. Also, ζ(s)≠0 for ℜs=1, a property first established in Hadamard (1896) and de la Vallée Poussin (1896a, b) in the proof of the prime number theorem (25.16.3). The functional equation (25.4.1) implies ζ(−2n)=0 for n=1,2,3,…. These are called the trivial zeros. Except for the trivial zeros, ζ(s)≠0 for ℜs≤0. In the region 0<ℜs<1, called the critical strip, ζ(s) has infinitely many zeros, distributed symmetrically about the real axis and about the critical line ℜs=1/2. The Riemann hypothesis states that all nontrivial zeros lie on this line.

—NIST Digital Library of Mathematical Functions, §25.10(i). Version 1.2.8 of 15 September 2026, dlmf.nist.gov/25.10. The page sets its formulas as mathematics, the one half of the critical line as a built-up fraction; the numbers in parentheses are its own equations.

Against this paragraph the five lines of Section 11.5 have to be read as one reads a contract. Lean itself shows what is in them, on a line of the same shape written for the integers, which need no library:

#check ∀ (s : Int) (_ : s * s = 0) (_ : ¬∃ n : Nat, s = -2 * (n + 1)) (_ : s ≠ 1), s = 0
∀ (s : Int), s * s = 0 → (¬∃ n, s = -2 * (↑n + 1)) → s ≠ 1 → s = 0 : Prop

Two things appear that the source did not show. Each binder (_ : …) quantifies over the proofs of a proposition and never uses them, which is implication (Section 5), and Lean prints an arrow. And an arrow ↑ stands in front of n: the left side of the equation is an integer, so the right side has to be one, and the elaborator has cast the natural number n, and only n; 2 and 1 are integer numerals. Mathlib's line has the same shape over ℂ, and the readable edition's own statement file writes this reading out for the second of its five theorems:The readable edition at its commit 72fead1: src/Statements.lean, lines 3 and 4, and src/Main.lean, line 8, theorem riemannZeta_eq_zero_re : RiemannZetaZerosOnLine := riemannHypothesis.

def RiemannZetaZerosOnLine : Prop :=
  ∀ s : ℂ, riemannZeta s = 0 → (¬∃ n : ℕ, s = -2 * ((n : ℂ) + 1)) → s ≠ 1 → s.re = 1 / 2

Its main file proves that theorem by the single term riemannHypothesis, the theorem whose type is Mathlib's definition. If the file checks as its documentation reports (it was not run here), Lean takes the two spellings for one proposition.

Read with its arrows in place, the line can be held against the quoted paragraph, clause by clause.

Remark 11.6.1 (the clauses). (i) ∀ (s : ℂ) is every complex number, not a strip. A term of this type therefore also proves what the quoted paragraph cites as known: no zeros with real part at least 1, and none with real part at most 0 but the trivial ones. (ii) ¬∃ n : ℕ, s = -2 * (n + 1) removes −2, −4, −6, …; the + 1 is there because Lean's natural numbers begin at 0. (iii) s ≠ 1 removes the pole. (iv) s.re = 1 / 2 is an equation between real numbers, so the division is that of the reals and 1 / 2 is one half. The same characters at the type of the natural numbers are 0 (Section 11.8).

Clause (iii) is where the reading stops being routine. On paper ζ has no value at 1. In Lean riemannZeta 1 is a complex number like any other, and the file says so:

Note that mathematically ζ(s) is undefined at s = 1, while Λ(s) is undefined at both s = 0 and s = 1. Our construction assigns some values at these points; exact formulae involving the Euler-Mascheroni constant will follow in a subsequent PR.

—Mathlib, the opening comment of Mathlib/NumberTheory/LSeries/RiemannZeta.lean. Lines 23 to 25 at the commit of 13 October 2026; the copyright line of the file names David Loeffler, 2023. Λ is the completed function of Definition 11.5.1, which the file calls completedRiemannZeta.

The formula has come since. Another file of the library proves riemannZeta 1 = (γ - log (4 * π)) / 2, under the comment that "mathematically ζ 1 is undefined, but our construction ascribes this particular value to it". Definition 11.5.1 shows where it comes from: at s = 1 the term 1/(1 − s) is 1/0, which in Lean is 0, what is left of Λ is its constant term at the pole, and the Gamma factor there is 1. The value is about −0.977 and not zero, since γ < 1 < log 4π. So clause (iii) excludes nothing: a zero at 1 was impossible already. What it buys is that the truth of the statement does not hang on a number that only the construction ascribes.

Such a number is a junk value: what a total function returns where the mathematical function is undefined. The definition of ζ leans on them, and one proof of the library shows the convention at work.

/-- The trivial zeroes of the even Hurwitz zeta function. -/
theorem hurwitzZetaEven_neg_two_mul_nat_add_one (a : UnitAddCircle) (n : ℕ) :
    hurwitzZetaEven a (-2 * (n + 1)) = 0 := by
  have : (-2 : ℂ) * (n + 1) ≠ 0 :=
    mul_ne_zero (neg_ne_zero.mpr two_ne_zero) (Nat.cast_add_one_ne_zero n)
  rw [hurwitzZetaEven, Function.update_of_ne this, Gammaℝ_eq_zero_iff.mpr ⟨n + 1, by simp⟩,
    div_zero]

The trivial zeros are proved by dividing by zero. div_zero is the theorem a / 0 = 0, which holds in every field of the library because 0⁻¹ = 0 is one of the axioms of the class (Section 11.8). The Gamma function is 0 at its poles by the same convention: its definition divides by s, s + 1, and so on, and at a pole one of these is 0. So the Gamma factor vanishes at −2, −4, …, and the quotient that defines ζ is a number over 0. The value is the right one, for on paper Λ is finite at those points and 1/Γ vanishes. But the proof is short because of the convention, and at s = 0 the same convention would make ζ(0) equal to 0, which is why the definition sets the value −1/2 there by hand.

There is another way to build a library, as old as proof checking. In Automath, the proof checker that N. G. de Bruijn's group built in Eindhoven from 1967 on, the logarithm was to take two arguments, a number and a proof that the number is positive: log 3 is then written with a proof of 3 > 0 beside the 3, and de Bruijn's survey of the project tells of the trouble of saying that the value does not depend on that proof (Section 4.8 quotes the passage). His remedy, that two proofs of one proposition be equal by definition, is a rule of Lean's kernel (Section 6), and Mathlib still goes the other way: a function takes numbers only and is defined everywhere, and the condition moves into the theorems about it. The real logarithm of the library is defined on all of ℝ, an "unconventional extension", its docstring says, chosen "as it gives the formula log (x * y) = log x + log y for all nonzero x and y". The gain is terms with no proofs in them and identities with few side conditions. The price is the reader's: a statement can be true for a reason that has nothing to do with what it seems to say, and only the definitions tell. Section 7 takes up the convention in general; in the statement of the hypothesis the one point where it would matter is removed by a clause.

How much of the library actually sits underneath that five-line statement? Two text-based counts bracket the true dependency cone from below and from above. Walking only the explicit constant names written in the source text gives the 43-rung ladder of Section 11.1, an underestimate that omits everything the elaborator inserts behind notation: the instances for *, +, -, /, and numerals, the implicit coercions, and the proofs carried inside structures. Counting every file reachable through import headers gives an upper bound.

map      Mathlib at the commit the readable edition of the proof is built on: 8,624 files, 2,340,927 lines
         in 32 areas. A rectangle to a folder, its area the folder's lines; a green tile to each module that
         the file stating the Riemann hypothesis imports, directly or through other files

         area                 lines    of them imported
         Algebra            333,013    175,128
         CategoryTheory     277,282          0
         Analysis           252,251    151,428
         Topology           198,699    126,974
         RingTheory         192,618     46,197
         Data               142,596     97,344
         MeasureTheory      123,030     81,715
         NumberTheory        76,274      4,533
         all of Mathlib   2,340,927    989,702    (42.3 %, in 2,954 of its files)

outside  from Lean's core library and seven packages the file imports 1,936 modules more, 586,980 lines:
         4,889 modules, 1,576,420 lines in all, the farthest 23 import lines away
(the live figure needs JavaScript and loads about 0.4 MB of data)
Mathlib at the commit the readable edition of the proof is built on, to scale: a rectangle to a folder, its area the folder's lines. Green: a tile to each module that the file stating the Riemann hypothesis imports, directly or through other files, within the distance chosen; beside Mathlib, to the same scale, what it imports from outside. White is not imported. Imported is more than used: the closure of import lines bounds from above what the statement can depend on. Counted from text; nothing was built. Step the distance, click a bar, point at a tile or a folder.

To state the hypothesis a file imports, directly or through other files, 4,889 modules of 1,576,420 lines: 2,953 of Mathlib's, and 1,936 from Lean's core library and seven other packages. With the file itself that is 2,954 of Mathlib's 8,624 files and 42.3% of its lines, and none of its category theory. Imported is not used. A module comes whole, and the closure of the import lines bounds from above what the statement can depend on. Which declarations it does depend on can be read only off the elaborated library, which this series did not have. The one published count is of a larger object: the export of the readable edition's challenge file, in which its five theorems are stated without their proofs, is the list of everything under the five statements that a checker reads (Section 13), and it holds 52,173 declarations.A. Sutherland, "Verification files for the shorter Lean proof of RH and of GRH for Dirichlet L-functions", math.mit.edu/~drew/shortgrh, as last updated on 27 November 2026, in the row of the checker con-leche. It counts declarations, for both shorter editions; the two counts in the text are of definitions and of modules.

This part has quoted the library's comments beside its declarations. They are not evidence of the same kind.

Remark 11.6.2 (a docstring is not a statement). The comment over the functional equation riemannZeta_one_sub writes it with a sine and a power of 2; the statement under the comment has a cosine and a power of 2π. They agree, since \(2^{1-s}\pi^{-s} = 2\,(2\pi)^{-s}\) and \(\sin(\pi(1-s)/2) = \cos(\pi s/2)\), but only the second is what Lean checks when the library is built. The kernel never sees a comment. An auditor reads docstrings to learn what the authors meant, and statements to learn what was proved.

The statement has been read, and only read. What it says of the zeros can also be tried on them.

The function itself

Nothing so far has produced a value of ζ. Mathlib's definition cannot: it is marked noncomputable, being made of an integral and of limits. So the function is computed here directly, in the page, by the two classical formulas for it on the critical line.

Z(t)      Z(t) = e^(iϑ(t)) ζ(½ + it), real for real t, from t = 0 to T = 60; ● where the page finds it changing sign
          ──────────────●──────●───●────●──●────●──●─●────●─●──●──●──●─   13 sign changes,
          0         10        20        30        40        50        60   the first at 14.134725, the last at 59.347044
N(t)      the zeros counted up to t, a staircase on its main term (t/2π) log(t/2πe) + 7/8:
          at T = 60 the count is 13, the main term 12.87
counts    sign changes of Z up to T: 13    zeros in the whole strip, by the argument of ζ: 13    in the table: 13
          the three agree; they are floating-point computations without error bounds, not a proof
table     up to t = 74,921 the page finds 100,000 sign changes, as many as the published table has zeros;
          11,940 of them are held against the table here (all 10,142 below t = 10,000, every 50th above):
          the farthest is 2.9 × 10⁻⁹ away, inside the 3 × 10⁻⁹ that the table states for itself
(the live figure needs JavaScript and loads about 0.26 MB of data)
Green: where the page finds the real function Z changing sign, zeros of ζ on the critical line. Ink: Z(t), and the count N(t) on its main term. Ticks: the same zeros in Odlyzko's published table (all below t = 10,000, every 50th above). Bottom row: the page's zero less the table's, hatched beyond the accuracy the table states. Three counts side by side: sign changes, zeros in the strip by the argument of ζ, the table. They agree as floating-point computations without error bounds; that is not a verification of the hypothesis. Move T by the slider, a drag, or a click below; run scrolls.

Two statements divide the work of a numerical test of the hypothesis.T. Trudgian, "An improved upper bound for the argument of the Riemann zeta-function on the critical line II", arXiv 1208.5846 (version 2 of 5 September 2012), Corollary 1. The functions Z and ϑ are equations 25.10.1 and 25.10.2 of the Digital Library quoted in Section 11.6, which takes the phase of the Gamma function at its principal value; the two choices of ϑ differ by multiples of 2π, and Z is the same for both. The first finds zeros on the line by a change of sign, and for that the function has to be real.

Definition 11.7.1 (the function on the critical line). For real \(t\) let

\[\vartheta(t) = \operatorname{ph} \Gamma\!\left(\tfrac14 + \tfrac12 i t\right) - \tfrac12 t \ln \pi, \qquad Z(t) = e^{i\vartheta(t)}\, \zeta\!\left(\tfrac12 + i t\right),\]

where ph is the phase, taken continuous in \(t\) and 0 at \(t = 0\). Then \(Z\) is real, \(\lvert Z(t) \rvert = \lvert \zeta(\tfrac12 + it) \rvert\), and a sign change of \(Z\) is a zero of ζ on the critical line.

\(Z\) is real because \(e^{i\vartheta(t)}\) is the phase of the Gamma factor \(\Gamma_{\mathbb R}\) at \(\tfrac12 + it\), and the completed function \(\Lambda\) of Definition 11.5.1 is real on the line, by its symmetries \(\Lambda(1-s) = \Lambda(s)\) and \(\Lambda(\bar s) = \overline{\Lambda(s)}\).

A sign change says nothing of a zero off the line. The second statement says how many zeros there are to find up to a height T, on the line or off it.

Theorem 11.7.2 (counting the zeros; Trudgian 2012). Let \(N(T)\) be the number of zeros of ζ in the critical strip with imaginary part in \((0, T)\). For \(T \ge T_0 \ge e\),

\[\Bigl\lvert\, N(T) - \frac{T}{2\pi} \log \frac{T}{2\pi e} - \frac78 \,\Bigr\rvert \;\le\; 0.111 \log T + 0.275 \log\log T + 2.450 + \frac{0.2}{T_0} .\]

It says so to within an error of the size of log T; and for a given T that is not the height of a zero the number N(T) can be computed exactly, as a whole number, by following the argument of ζ along a path from outside the strip to the point 1/2 + iT. If the sign changes up to T are as many as N(T), every zero up to that height is on the line. Done with rigor it looks like this:

We verify numerically, in a rigorous way using interval arithmetic, that the Riemann hypothesis is true up to height \(3\cdot10^{12}\). That is, all zeroes \(\beta + i\gamma\) of the Riemann zeta-function with \(0<\gamma\leq 3\cdot 10^{12}\) have \(\beta = 1/2\).

—Dave Platt and Tim Trudgian, "The Riemann hypothesis is true up to 3·10¹²" (2020). The abstract; arXiv 2004.09765 (21 April 2020), published in the Bulletin of the London Mathematical Society (DOI 10.1112/blms.12460).

The rigor is in the interval arithmetic, which bounds every rounding, and in a method going back to Turing by which, the paper says, "we can confirm that all the expected zeroes have been accounted for, so none lie off the half line and the Riemann hypothesis holds in the given range". The page does the same two counts without either safeguard.

Example 11.7.3 (two counts and a table). In the page, \(Z(t)\) is evaluated in double-precision floating point using Euler-Maclaurin summation below \(t = 80\) and the Riemann-Siegel formula with 13 correction terms above; its sign changes are located on a fixed sampling grid, while total zeros in the critical strip are counted separately by tracking the argument of \(\zeta\) from \(2 + iT\) to \(1/2 + iT\), and both are compared against A. Odlyzko's published table of the first 100,000 zeros,A. Odlyzko, "Tables of zeros of the Riemann zeta function", www-users.cse.umn.edu/~odlyzko/zeta_tables, the file of the first 100,000 zeros, fetched on 1 December 2026. which states a bound of \(3 \times 10^{-9}\) for its own accuracy and from which the page stores all 10,142 zeros below \(t = 10{,}000\) plus every 50th zero thereafter. Up to \(T = 60\), the page finds 13 sign changes, 13 zeros via the argument of \(\zeta\), and 13 entries in the table, compared against a smooth main term of 12.87. At \(T = 74{,}920\), the page's two separate counts still match at 99,998 sign changes of \(Z\) and 99,998 zeros in the strip, consistent with the subsampled table (which brackets the count between 99,950 and 99,999 below that height) and a main term of 99,998.17. Across all 11,940 stored table zeros, the largest discrepancy is \(2.9 \times 10^{-9}\), within the table's stated precision. Even so, that agreement compares two unverified floating-point calculations against a table rather than verifying the hypothesis up to \(T = 74{,}920\): rounding errors are not bounded by intervals, and a pair of zeros spaced more closely than the sampling grid would escape the sign-change scan. ◁

Nor does any of it touch Lean. That the function computed here is the riemannZeta of Definition 11.5.1 away from s = 1 is Proposition 11.5.3, an argument on paper from two statements of the library. No number computed in the page was compared with anything Lean produced.

In Lean

Without Mathlib, three of this part's ideas can still be tried in Lean 4.35.0, in files that import nothing, and a fourth can be read.

The first is that a name is a statement. Mathlib names a theorem by spelling what it says: "Terms of Props (e.g. proofs, theorem names) use snake_case", its conventions read, "Props and Types (or Sort) (inductive types, structures, classes) are in UpperCamelCase", and "Functions are named the same way as their return values".Mathlib's naming conventions, the section "Capitalization" (mathlib.org/contribute/naming.html, read on 1 December 2026). So div_zero is a / 0 = 0, mul_ne_zero makes a product of nonzero factors nonzero, and Gammaℝ_eq_zero_iff is an equivalence whose left side is Gammaℝ s = 0: the proof of the trivial zeros in Section 11.6 can be read off its names. Lean's core library spells many of its names the same way, so the habit can be practiced on it. Guess a name and ask for the statement:

#check Nat.mul_add
#check Nat.div_zero
#check Nat.le_antisymm
#check Nat.zero_add_comm
example (a b c : Nat) (h : a ∣ b) (h' : b ∣ c) : a ∣ c := by exact?
Nat.mul_add (n m k : Nat) : n * (m + k) = n * m + n * k
Nat.div_zero (n : Nat) : n / 0 = 0
Nat.le_antisymm {n m : Nat} (h₁ : n ≤ m) (h₂ : m ≤ n) : n = m
Names.lean:4:7: error(lean.unknownIdentifier): Unknown constant `Nat.zero_add_comm`
Try this:
  [apply] exact Nat.dvd_trans h h'

A wrong guess costs a line, and where guessing fails exact?, a tactic (Section 10: a program that builds a proof), searches the library for a theorem that closes the goal and prints the term. Names can be guessed because the library also fixes one way to write each thing, the form that its simplifier (simp, Section 10) rewrites toward, and states its lemmas in that form: n + 1 and not Nat.succ n, a natural number cast into ℂ directly and not through ℝ. The lemma that says the two casts agree, ofReal_natCast (n : ℕ) : ofReal n = n, carries the tags @[simp, norm_cast] and the proof rfl.

The second is a hierarchy: six classes under Mathlib's names, with its headers shortened, and one diamond. An additive commutative group is an additive group and a commutative monoid, and each of those is a monoid.

class AddZeroClass (M : Type) extends Zero M, Add M where
  zero_add : ∀ a : M, 0 + a = a
  add_zero : ∀ a : M, a + 0 = a
class AddSemigroup (G : Type) extends Add G where
  add_assoc : ∀ a b c : G, a + b + c = a + (b + c)
class AddMonoid (M : Type) extends AddSemigroup M, AddZeroClass M
class AddCommMonoid (M : Type) extends AddMonoid M where
  add_comm : ∀ a b : M, a + b = b + a
class AddGroup (A : Type) extends AddMonoid A, Neg A where
  neg_add_cancel : ∀ a : A, -a + a = 0
class AddCommGroup (G : Type) extends AddGroup G, AddCommMonoid G

theorem add_zero {M : Type} [AddZeroClass M] (a : M) : a + 0 = a :=
  AddZeroClass.add_zero a

instance : AddCommGroup Int where
  add_assoc := Int.add_assoc
  zero_add := Int.zero_add
  add_zero := Int.add_zero
  neg_add_cancel := Int.add_left_neg
  add_comm := Int.add_comm

example (x : Int) : x + 0 = x := add_zero x
example (x : Nat) : x + 0 = x := add_zero x

set_option pp.explicit true in
#synth AddZeroClass Int

example : (AddGroup.toAddMonoid : AddMonoid Int) = AddCommMonoid.toAddMonoid := rfl
Hierarchy.lean:24:33: error(lean.synthInstanceFailed): failed to synthesize instance of type class
  AddZeroClass Nat

Hint: Type class instance resolution failures can be inspected with the `set_option trace.Meta.synthInstance true` command.
@AddMonoid.toAddZeroClass Int (@AddGroup.toAddMonoid Int (@AddCommGroup.toAddGroup Int instAddCommGroupInt))

The lemma add_zero is proved once, for every type with an AddZeroClass. The integers were declared an AddCommGroup and nothing less, and Lean accepts add_zero x for an integer: it has found its way down. For a natural number it refuses, no instance having been declared. #synth prints the way, three projections, through AddGroup. Now move the two lines of AddGroup above those of AddCommMonoid and run the file again. The refusal stays, and the last line becomes:

@AddMonoid.toAddZeroClass Int (@AddCommMonoid.toAddMonoid Int (@AddCommGroup.toAddCommMonoid Int instAddCommGroupInt))

The route goes through AddCommMonoid: the order of two declarations decided it. The last line of the file says why that is harmless. The two ways from AddCommGroup Int to AddMonoid Int are equal by rfl, that is, by definition, in both versions of the file. This is the situation of the 18 routes of Section 11.3 at a size that can be run. In Mathlib itself the search was not observed, and its text shows the choice being steered by hand: the file that defines AddMonoid sets explicit priorities on projections, beginning right after that class with attribute [instance 150] AddSemigroup.toAdd.

The third experiment exposes the implicit casts and type class instances hidden behind everyday arithmetic notation:

#eval (1 / 2 : Nat)
#eval (1 / 2 : Rat)
set_option pp.explicit true in
#check fun (n : Nat) (s : Int) => s = -2 * (n + 1)
0
(1 : Rat)/2
fun n s =>
  @Eq Int s
    (@HMul.hMul Int Int Int (@instHMul Int Int.instMul)
      (@Neg.neg Int Int.instNegInt (@OfNat.ofNat Int (nat_lit 2) (@instOfNat (nat_lit 2))))
      (@HAdd.hAdd Int Int Int (@instHAdd Int Int.instAdd) (@Nat.cast Int instNatCastInt n)
        (@OfNat.ofNat Int (nat_lit 1) (@instOfNat (nat_lit 1))))) : Nat → Int → Prop

The characters 1 / 2 are 0 among the natural numbers and one half among the rationals, which Lean's core library has. With pp.explicit Lean prints the arguments it filled in: the type at which = is taken, the instance behind each * and +, the minus sign as a negation applied to the numeral 2, and the cast Nat.cast on n. That is the printout to ask for when a statement matters. For Mathlib's own it needs the library built.

One last snippet from Mathlib's source text, read here without running Lean, shows total division at work in a proof:

@[simp]
theorem div_zero (a : G₀) : a / 0 = 0 := by rw [div_eq_mul_inv, inv_zero, mul_zero]

Three rewrites, each named for what it says: a / 0 is a · 0⁻¹, which is a · 0, which is 0. The middle one, inv_zero, is not proved from anything. It restates a field of the class GroupWithZero, which stands there under the comment "The inverse of 0 in a group with zero is 0." The convention of Section 11.6 is an axiom of the structure, and @[simp] enters the theorem among the rewrite rules of the simplifier.

A library is one body of definitions, each made once and every function in it total, and a statement written in it says what those definitions make it say. The kernel holds a proof to the statement; that the statement is the one meant is settled by reading, and what has to be read is not the construction: it is the statement itself, the theorems that characterize the functions in it, and the definitions and conventions under both.

To read a statement is not to prove it. Section 12 asks how a proof is produced on top of such a library, whoever or whatever writes it, and Section 13 what a check of such a proof establishes.

← Back to all posts