# qed

**A verification ledger for machine-made mathematics.** A Lean 4 source scanner that ignores comments and strings,
an import-closure check, a Comparator-config audit, a manuscript ledger with verification levels, and a model of
how long people need to referee what is left. Zero dependencies, one file, Node 18+ and browsers.

On 6 October 2026 OpenAI published 722 mathematical manuscripts produced by an internal model, with a Lean library
for some of them, in one repository (github.com/openai/math). Three were withdrawn the next day. Mathematicians were
asked to sort out which of the results hold. qed is for that sorting: it reads the release as data and says, for
each paper, how far it has been checked, and by what.

```
npm test      # 13 tests
npm run demo  # a short tour on the bundled snapshot
```

## What the bundled snapshot says

`data/snapshot.json` is `qed repo` run on github.com/openai/math at commit `fd4aeeb` (7 October 2026):

| | |
| --- | --- |
| Manuscripts in the catalogue | 719 in 372 families, plus 3 withdrawn |
| Main result listed in `lean/formalization.yaml` | 172 manuscripts (23.8%) |
| In a family with Lean work, main result not listed | 303 |
| No Lean work in the family | 244 |
| Revised with a version note | 27 |
| Lean files in `lean/OAI` | 122,458 files, 26.2 million lines, 1.57 GB |
| Theorems and lemmas declared | 2,263,073 |
| `sorry` / `admit` outside comments | 0 |
| `axiom` declarations, `native_decide`, `unsafe`, `implemented_by` | 0 |
| Comparator configs | 416, every one permitting only `propext`, `Quot.sound`, `Classical.choice` |
| Solution import closures inside the library | 416 of 416 free of sorry and axioms (median 77 modules) |
| Lean scope notes (`lean/docs`) | 242 families; 64 of them name something the formal statement leaves out |

The release's own README counts 300 of 719 top-line results as formalized. qed's 172 is stricter: a manuscript counts
only if `formalization.yaml` lists it as the source of a formalized main result.

What this does and does not mean: the formal library is unusually clean as text, and every Comparator setup asks
for the standard axioms only. Lean then guarantees that each checked theorem follows from its statement. It does not
say that the Lean statement is the paper's statement (the challenge files exist so a person can read that), that the
result is new, or anything about the 547 manuscripts whose main result is not formalized. That reading is people's
work, and the ledger shows how much of it is left.

## The ledger

| level | meaning |
| --- | --- |
| `withdrawn` | the release withdrew it |
| `manuscript` | a PDF; no Lean work in its family |
| `family` | its family has formal work, but not this paper's main result |
| `lean` | main result listed in formalization.yaml, with a Comparator setup |
| `reviewed` | checked by a named referee (none are recorded in the release) |

## The scanner

`scan(source)` lexes Lean 4 (nested `/- -/` comments, doc comments, strings, raw strings, `«names»`, char
literals), tracks `namespace` / `section` / `mutual` / `end` (including `namespace A.B` closed one part at a time),
and reports declarations, `sorry` and `admit` with the declaration they sit in, custom `axiom`s, `native_decide`,
`decide +native`, `unsafe`, `implemented_by`, `extern` and `set_option debug.skipKernelTC true`. Verdicts:
`clean`, `incomplete`, `assumes`, `trusts-compiler`, `flagged`, `unchecked`.

`closure(scans, module)` follows imports through the files you scanned and collects every gap on the way.
`checkConfig(config, challengeScan, solutionScan)` audits a [Comparator](https://github.com/leanprover/comparator)
setup: axioms beyond the standard three, theorem names missing from the challenge, a solution that uses `sorry`.

qed reads Lean as text. It is a quick first pass that needs no Lean install, not the kernel: `#print axioms` and
Comparator are the real checks, and a `sorry` in an imported file the theorem never uses still taints a closure here.

## Command line

```
qed scan <file.lean> [...]                 exit 2 if any file is incomplete or unchecked
qed config <challenge.json> [--lean dir]   exit 3 if the setup has errors
qed repo <path to a clone> [--out f.json]  rebuild the snapshot (about 2.5 minutes for the whole release)
qed ledger [snapshot.json]
qed triage [snapshot.json] [--reviewers 40 --per-week 6 --hours 40 --lean-discount 0.5]
qed demo
```

To rebuild the snapshot yourself:

```
git clone --depth 1 https://github.com/openai/math
node bin/qed.js repo math --out data/snapshot.json
```

## The review queue

`triage(ledger, options)` is arithmetic, not a forecast. With 40 referees giving 6 hours a week, 40 hours per
manuscript and half of that saved when the main result is in Lean, the 719 remaining manuscripts need 25,320 hours:
105.5 weeks. Every number is a flag.

## API

```js
const Q = require("./src/qed.js");          // or <script src="qed.js"> → window.QED
Q.scan(leanSource)                          // { verdict, imports, decls, sorries, axioms, flags, options }
Q.closure({ module: scan, … }, rootModule)  // { modules, clean, sorry, axioms, flags, externalRoots }
Q.checkConfig(config, challengeScan, solutionScan)   // { ok, findings, extraAxioms }
Q.ledger(manuscripts)                       // { counts, rows, subjects }
Q.triage(ledger, { reviewers, hoursPerWeek, hours, leanDiscount })   // { hours, weeks, curve }
Q.parseContents(md) / Q.parseOverview(tex) / Q.parseFormalization(yaml)
```

## Examples

- `examples/scan-a-folder.js` lists every file under a folder that is not clean.
- `examples/audit-comparator.js` audits every Comparator config in a Lean project.
- `examples/review-queue.js` shows how the time to referee changes with the Lean discount.

## Data and licences

The snapshot holds titles, directory names and counts from github.com/openai/math (Apache-2.0). The sample Lean files
in `data/samples` are ours. qed is MIT-licensed and not affiliated with OpenAI.
