riemann-nano

riemann-nano is a small language model trained on one document: the Lean 4 formalization of the proof of the Riemann Hypothesis, released by Levent AlpΓΆge in November 2026. The proof runs to 175,000 files and about 300 million tokens. That's enough to train a language model on, and to ask how big that model should be.

To answer that, we trained about 60 nanochat models at six compute budgets and fitted a scaling law in the style of Chinchilla. We then used the law to predict the compute-optimal model size at a larger budget, 1017 FLOPs, and trained that model. That model is riemann-nano: a 7-layer transformer with 61M parameters. Every model in the sweep, riemann-nano included, was trained on Hugging Face Jobs; riemann-nano itself took one H200.

Scaling laws for riemann-nano

The prediction holds up: in a sweep at 1017 FLOPs, riemann-nano is within noise of the best model of any size.

Samples

Part of the fun of a model trained on a single corpus is seeing what it picks up. Here's riemann-nano, and two smaller models from the scaling sweep, finishing the same prompts.

Watching it learn

Prompt: /-- The completed Riemann zeta function. -/ def

With 100Γ— less compute than riemann-nano, the model has worked out that Lean is full of integers:

def (Ξ› : Submodule β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€ β„€

With 10Γ— less, it knows a definition needs a name and a type, if not what goes in them:

def B/4 : ℝ/4444444444444444444444444444445444444444445444455454444545444444454444444444554454544

riemann-nano writes a full definition, then closes a namespace it never opened:

def Basic : Prop := βˆ€ (L : PeriodPair) (h : SCFTAll) (ψ : β„‚ β†’+ β„‚), IsHomClass L ψ β†’ IsCharClass L (h * ψ) β†’
  βˆ€ Οƒ : β„‚ ≃+* β„‚, (βˆ€ z, β€–Οƒ zβ€– = β€–zβ€–) β†’ βˆ€ (s : β„‚) (a : β„•), 0 < a β†’ (a : β„‚) ^ 2 * Οƒ h = h * (s ^ 2 * Οƒ (h * ψ (Complex.I ^ a / s)))

end Formalism.HermitianLattices.Ext.L3

The same thing happens with proofs. Asked why ΞΆ(s) β‰  0 when Re s > 1, the smallest model reaches for simp and lists every lemma it knows: simp [zero_add, zero_add, add_zero, neg_zero, neg_zero, neg_zero, neg_zero]. riemann-nano writes a tidy proof, then moves on to the next lemma in the family. It mixes a lemma it invented with a real one, summable_geometric_of_lt_one, which the proof uses 173 times:

theorem riemannZeta_ne_one_of_one_lt_re {s : β„‚} (hs : 1 < s.re) : riemannZeta s β‰  1 := by
  have : 1 < s.re := hs
  simp only [riemannZeta_eq_tsum_of_summable_norm summable_norm]
  exact summable_geometric_of_lt_one (by linarith) (by linarith)

Analytic number theory, house style

Prompt: namespace RiemannHypothesis

namespace RiemannHypothesis

def gauss : ℝ := Real.exp (-2 * Real.log 4)

def bnd : ℝ := 2 * Real.log (2 * |2|) / 2

def bnd1 : ℝ := 4 / 3

lemma gauss_nonneg : 0 ≀ gauss := by unfold gauss; positivity

lemma gauss_pos : 0 < gauss := by unfold gauss; positivity

lemma gauss_pos1 : 0 < gauss := by
  unfold gauss; positivity

lemma bnd1_pos : 0 < gauss := by
  unfold gauss; positivity

Define a constant, prove it's positive, prove it again just in case, then prove it a third time under bnd1's name. The real proof calls positivity more than 45,000 times, and riemann-nano has picked up the habit.

A proof of the Riemann Hypothesis

Prompt: theorem riemannHypothesis : RiemannHypothesis := by

theorem riemannHypothesis : RiemannHypothesis := by
  have h1 := riemannHypothesis
  unfold RiemannHypothesis
  exact mul_le_mul_of_nonneg_right (by norm_num) (by positivity)

theorem riemannHypothesis : RiemannHypothesis :=
  riemannHypothesis

theorem riemannHypothesisE : RiemannHypothesisE := riemannHypothesis

theorem riemannHypothesisT : RiemannHypothesisT := riemannHypothesis

The most efficient proof possible: cite the theorem itself. Once it has one, it reuses it for the variants E and T.

Algebraic geometry on demand

Prompt: structure

structure IsRegularLocalRing (S : Type*) [CommRing S] [IsRegularLocalRing S]
    [IsLocalRing S] [IsRegularLocalRing S] : Prop :=
  ringKrullDim S = 1 ∧ ringKrullDim S = 1 ∧
    ringKrullDim S = ringKrullDim (ResidueField S)

Krull dimensions, residue fields and the right typeclass brackets, all from a one-word prompt. It does assume the structure in its own definition, twice.

A little in-context learning

Show riemann-nano three worked examples, and it picks up the idea of finishing a simple goal with the right tactic:

-- the prompt: three examples
example : 8 ^ 2 + 15 ^ 2 = 17 ^ 2 := by norm_num
example : Nat.Prime 11 := by norm_num
theorem three_mul' (n : β„•) : 3 * n = n + n + n := by ring

-- riemann-nano's proofs, each checked by Lean βœ“
example : 3 ^ 2 + 4 ^ 2 = 5 ^ 2 := by norm_num
example : Nat.Prime 13 := by norm_num
theorem two_mul' (n : β„•) : 2 * n = n + n := by ring
theorem sq_nonneg' (x : ℝ) : 0 ≀ x ^ 2 := by positivity

Asked for Nat.gcd 12 18 = 6, it reaches for BΓ©zout's identity and stops halfway. Asked to make up Pythagorean triples of its own, it's more creative than correct: 2 ^ 3 + 7 ^ 2 = 17 ^ 2.

Where everything lives

With no prompt at all, riemann-nano starts a file the way the proof does, with a wall of imports:

import Mathlib
import Development.AbelianVarietyTheory.Proofs.InertiaEigenvalues.UnipotentBlockColumnIndex
import Development.AbelianVarietyTheory.Proofs.InertiaEigenvalues.QuotientAveragePeriodicBoundedFreeStatement
import Development.AbelianVarietyTheory.Proofs.InertiaEigenvalues.QuotientAveragePeriodicRelationFamilyStatement
import Development.AbelianVarietyTheory.Proofs.InertiaEigenvalues.QuotientAverageBilinearEquivSymmContinuousStatement

Nearly half the proof lives under AbelianVarietyTheory/Proofs, so that's where it sends you first.

Usage

from transformers import AutoModelForCausalLM, AutoTokenizer

repo = "lewtun/riemann-nano"
tokenizer = AutoTokenizer.from_pretrained(repo, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True)

prompt = "theorem riemannHypothesis : RiemannHypothesis := by\n"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True, temperature=0.8, top_k=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

You need transformers 5.24. The model uses custom code, so trust_remote_code=True is required for both the model and the tokenizer. The tokenizer adds a beginning-of-document token, and generation stops at <|eos|>.

Limitations

  • Its proofs are unchecked. Treat its output as Lean-flavoured fiction until Lean accepts it.
  • It is small and narrow. riemann-nano has only seen this one formalization and its Mathlib imports. It is not a general Lean assistant.
  • It is a research artifact. It exists to test scaling-law predictions on a single, finite mathematical corpus. At larger budgets than this one, the 300M tokens have to be reused many times and the law above stops holding. The training code, data preparation and scaling analysis are on the rh branch of the nanochat fork.

Acknowledgements

Thanks to Ben Burtenshaw for the original idea of training a nanochat model on the Riemann Hypothesis proof.

Downloads last month
97
Safetensors
Model size
60.9M params
Tensor type
F32
Β·
BF16
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support