# And Reimann hypothesis falls

When Levent Alpöge released a ~175,000-file Lean 4 formalization claiming a proof of the Riemann Hypothesis and Generalized Riemann Hypothesis at [alpo.ge](https://alpo.ge), I wanted to inspect it and see how to verify it locally.

## What Lean Is

Lean is a programming language and interactive proof assistant based on dependent type theory. In Lean, mathematical statements are **types**, and proofs are **programs** of those types.

When you compile a Lean project with `lake build`, Lean's small kernel type-checks every logical step from first principles. If the project compiles cleanly, it literally means the mathematical statements are proven true, as long as there are no shortcuts hidden in the codebase.

## Why `sorry` and Custom Axioms Must Not Exist

Lean has two escape hatches that still allow a file to compile:

- `sorry`: A placeholder that tells Lean to accept an unfinished proof without checking it. A single `sorry` anywhere in the dependency chain means a step was skipped rather than proved.
- **Custom** `axiom` **declarations**: These let an author assert any statement as true by fiat. If you add an unproved (or false) axiom, you can "prove" anything from it, which makes the entire result meaningless.

Because of this, compiling is only half the check. You also have to verify that the final theorems depend strictly on Lean's three standard mathematical axioms (`propext`, `Classical.choice`, and `Quot.sound`) and nothing else.

## My Lean Detour Back in 2023

I first learned Lean back in 2023. I spent five days, plus a dedicated self-improvement slot from work, learning Lean 3 by proving that $\sqrt{2}$ is irrational. Right after that, I realized Lean 4 had completely overhauled the syntax, replacing `begin ... end` blocks with whitespace-sensitive `by` blocks and rewriting lambda and pattern-matching syntax (see the [Lean 4 Survival Guide for Lean 3 Users](https://github.com/leanprover-community/mathlib4/wiki/Lean-4-survival-guide-for-Lean-3-users)).

It reminded me of Macromedia Flash's ActionScript 3 to 4 transition, which Steve Jobs later killed off anyway. Despite that curveball and having **no AI support** at the time, I still finished my $\sqrt{2}$ irrationality proof in Lean 3.

## A Personal Connection to Matematik Köyü

One detail about this Riemann Hypothesis formalization stood out to me immediately: its author, **Levent Alpöge**, is Turkish and has taught at **Matematik Köyü** (the Nesin Mathematics Village in Şirince, Turkey).

As a fellow Turk, I actually stayed at Matematik Köyü for a few days myself to attend an evolution seminar. Knowing the project came from someone connected to that village made me want to pull the code down and look at it myself.

![2013 - Maths Village, Izmir](https://cdn.hashnode.com/uploads/covers/61b75a1bd2a5c9036e6ef87e/270b6231-0d5a-47ae-8dd6-d1d181b4c67e.jpg align="right")

## How to Run and Verify the Project Locally Using the Cache

If you run `lake build` directly on a Lean 4 project that depends on Mathlib, Lake tries to compile Mathlib from scratch. On my first attempt, that ate over 11 GB of disk space (including ~5.6 GB of intermediate C/IR files) and filled my drive before even reaching the project's own source files.

Pulling Mathlib's prebuilt cache first avoids compiling Mathlib yourself.

### 1\. Install `elan` (Lean's version manager)

```bash
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh
```

`elan` reads the project's `lean-toolchain` file (`leanprover/lean4:v4.33.1`) and installs the exact matching Lean version automatically.

### 2\. Unpack the project

After downloading the archive parts (`lean.tar.gz.part01` through `part14` from [alpo.ge](https://alpo.ge)):

```bash
cat lean.tar.gz.part* | tar -xzf -
cd lean
```

### 3\. Pull the Mathlib cache first

Before building anything, fetch the prebuilt `.olean` files for the pinned Mathlib commit:

```bash
lake exe cache get
```

This downloads precompiled Mathlib binaries instead of compiling them locally, saving hours of CPU time and gigabytes of intermediate build files.

### 4\. Build the top-level target

```bash
lake build Main
```

The main exported theorems live in `src/Main.lean` and `src/Statements.lean`, stated directly against Mathlib's `RiemannHypothesis`, `riemannZeta`, and `DirichletCharacter.LFunction`. Because the repository contains roughly 175,000 `.lean` files, expect the full build to take substantial time, RAM, and free disk space.

### 5\. Verify the axioms

Once `Main` compiles, check that no `sorry` or custom axiom snuck in anywhere in the dependency graph:

```lean
import Main

#print axioms riemannHypothesis
#print axioms LFunction_eq_zero_re
```

A valid, assumption-free classical proof in Lean 4 will print **only** these three axioms:

```text
'riemannHypothesis' depends on axioms: [propext, Classical.choice, Quot.sound]
```

If `sorryAx`, `Lean.ofReduceBool`, or any custom axiom appears, the proof has an unproved gap. For extra assurance, you can also run an independent kernel checker like `lean4checker` over the compiled `.olean` files.

### Cleaning up if you run low on disk space

If you need to reclaim disk space later without removing Lean or the source files:

```bash
rm -rf .lake/packages/*/.lake/build ~/.cache/mathlib
```
