theorem-os informalize turns a Lean proof that compiles into a natural-language proof. Each step quotes the Lean text it explains and names the declarations it relies on. Independent auditors check every step against the Lean source before anything is published. The result is artifact/proof.md with artifact/informalization.json, which binds the Markdown to the frozen proof, the extracted outline, every accepted output and every audit.
theorem-os run runs this workflow automatically after independent proof acceptance, once for every original target. No separate prepare command or curated local walkthrough is needed. The result's explanations field records progress and each artifact's paths under <output>.runtime/explanations/<language>/. Use --explanation-language zh|en (default zh) or --no-explanations. Generation uses the solver's model configuration and two auditors, with separate unlimited default time, token and revision budgets. Explanation failures do not change proof acceptance or the solver's successful exit code; --resume verifies the accepted proof and resumes explanation checkpoints without solving again. Preset Lean replays skip model generation.
The protocol is lean-proof-informalization-v1. It combines methods from published work. Step-wise informalization with a premise library follows arXiv 2509.09726, translation in dependency order with already translated dependencies as context follows Herald (arXiv 2410.10878), and per-step \lean/\uses anchors follow leanblueprint. As in the other TheoremOS roles, the model proposes and deterministic host checks decide what is admissible. The code is in src/math/informalizationExtraction.ts, src/math/informalization.ts, src/solver/informalizationExtraction.ts and src/solver/informalization.ts.
-
Freeze.
preparecopies the proof file and its project-local import closure intosources/with their sha256 digests. It also freezes the target theorem, the optional informal statement or approved formalization, the language, phrase alignment, the writer and auditor configurations, batching and limits inrequest.json. It refuses a proof outside--project-root, a module under an excluded path segment (test,reference,solutions,.lakeand the other construction exclusions), a file that uses the Lean module system (it exports no proof bodies to an importing command), repeated auditor ids and an existing directory. The source project is not read again. -
Extract.
runfirst compiles the frozen modules in a fresh project of the pinned environment. Only then does it write a host query command,lean-declaration-outline-v1, which carries a random nonce in its namespace and result file, so a proof module cannot forge the report. The query reads the elaborated environment, never the source text. A unit is a declaration of the proof modules that has a declaration range and is reachable from the target. Compiler auxiliaries (proof_n,match_n, equation lemmas) are folded into the unit that uses them, and awheredeclaration belongs to its prefix. For each unit the outline records its kind, range, source slice, pretty-printed signature, the owned declarations its statement and its proof term use, the external constants it uses, and the signatures of those library constants.collectAxiomsof the target refuses a proof that depends onsorryAx(informalization_proof_incomplete), and anaxiomin the proof modules is refused as well. Units are ordered by dependency (Kahn order, ties in source order) and the target comes last. Mutual recursion is released at its earliest member and markedcyclic. A module that does not compile stops the run withinformalization_proof_does_not_compile: FILE: first error.A last pass,
lean-tactic-goals-v1, elaborates each proof file again with info trees on. It runs as one nonce-bound command per file, which processes the file's header as the frontend does. For every tactic as written, it records the goals before and after, pretty-printed at width 100. Each state keeps up to 4 goals of at most 3000 characters, plus the total count. Grouping nodes are skipped: sequences,by,·,case,calcsteps and rewrite rules. The host assigns each tactic to the smallest unit whose range contains it, keeps one entry per range, and holds each unit to 48 KB, dropping nested tactics before outer ones. The pass is advisory. Each file gets at most 30 minutes. A file whose query fails, times out or writes an invalid report leaves its units withoutgoals. The outline'sgoalStatesthen readstruncated(some files covered) orunavailable(none), with the reasons, and the run goes on. The query exits as soon as it has written its result, because the nested import registers linters and environment extensions that the query's own environment lacks. On the 100-line Hadamard proof (Mathlib), the pass took 6.2 s and 8.7 GB peak memory; a plain compile of the same file took 4.1 s and 6.8 GB. Outlines made before this pass stay valid, and their role inputs and digests are unchanged. -
Batch. Units are grouped greedily in that order, at most
--max-units-per-batchdeclarations (default 12) and--max-batch-source-bytessource bytes (default 60000) per batch. The target is in the final batch. -
Write. For each batch, a writer role receives the batch's units (source, signature, dependencies, required citations and citable library names), the accepted statements of earlier declarations they use, the library theorems with signatures, the recorded goals around each tactic (
goals, when present), and the proof files underproof/. It must state intermediate goals as the recorded ones and may compile scratch copies with the installed Lean for goals that are not recorded. It writes one section per declaration: a title, a statement that translates the Lean signature exactly, and proof steps{text, uses, lean}. Mathematics is written in LaTeX, and Lean names, tactics and expressions as inline code. In the final batch it also writes an overview of how the declarations prove the target. The informal problem statement, when given, is shown to the writer only and only for vocabulary. Lean is the authority. -
Host checks. The host rejects an output unless it explains exactly the batch's declarations in order, gives each theorem at least one step, cites in
usesonly declarations the unit's Lean terms actually use (owned dependencies or non-tactic external constants), cites every owned theorem the proof term applies (mustCite), quotes inleanonly verbatim text of that declaration (modulo whitespace), and includes the overview exactly in the final batch. It also rejects a Lean name written inside a formula, such as$Nat.two_mul n$, which TeX draws as "Nat.two" with a subscript m. Such a name is one the unit can cite, or its last component, and contains.or_, so$a_n$passes. Formulas are found as the page finds them: outside inline code, with\$an escaped dollar sign and bold text read on its own. This rule applies to new submissions only and is not part of the evidence check, so explanations approved before it stay valid. A rejected output is not audited. Its problems become feedback for the next round, and the same check runs inside the writer's turn and steers it once. -
Audit. Each auditor (default 2) gets the Lean units and the explanation. It never sees the informal statement, the writer's feedback or another auditor's audit. Per declaration it judges the statement (
faithful,mismatch,unclear), gives one verdict per step (justified,gap,invented,unclear) and lists omissions: substantive Lean, quoted verbatim, that no step explains. Where goals are recorded, it checks each claim about an intermediate goal against them; a mathematical disagreement isinvented, a different notation is not. Declarations of other batches are out of scope even though the auditor can read the whole proof. It also judges the overview. The host checks the audit's structure: one verdict per step, an explanation for every non-approving verdict, verbatim omissions. A malformed audit is retried, and after three attempts the run stops withinformalization_audit_invalid. -
Revise or accept. A batch is accepted when every auditor approves every statement, step and overview with no omission. Otherwise every finding, attributed to its auditor, goes back to the writer with its previous output.
--max-rounds-per-batch(default 6,0= unlimited) bounds the rounds of each batch. When they run out, the run endsexhaustedwith the last findings in its error. -
Publish. After every batch is accepted, the host renders the Markdown deterministically and writes the artifact. Nothing is published earlier.
proof.md begins with a notice that the text is model-written and model-audited and that Lean checked only the proof. Then come the main theorem's statement and the overview. Under "Definitions and lemmas", definitions come first, then lemmas in dependency order, numbered in one sequence. Each has its Lean name, its statement and its numbered steps. Each step lists the cited declarations as "Lemma 3 double_eq" and the quoted Lean, inline or as a fenced block whose fence is longer than any backtick run inside it. The main theorem's proof comes last, followed by a footer with each source file's sha256, the Lean toolchain, the Mathlib revision and the axioms the target uses. --language zh (the default) writes the prose and headings in Chinese, and --language en writes them in English. Lean names are never translated.
informalization.json has authority: "model", humanReviewed: false and proofCompiledByHost: true. assertInformalizationEvidence re-derives everything from the evidence alone: the outline digest, the batches, every writer check, every audit check and approval, the metrics (declarations, steps, citations and excerptCoverage, the share of non-blank source characters quoted by some step), and the Markdown hash. inspect runs this check and also compares proof.md.
lean-phrase-alignment-v2 ties phrases of the prose to the Lean they translate (src/math/informalizationAlignment.ts). The command line uses it unless --alignment none is given; it is frozen in the request, and requests without it keep their inputs, schemas, instructions and digests. lean-phrase-alignment-v1 differs only in the goals of a step that quotes just the head of a block tactic, such as induction n with, have h : P := by or classical, and none of the tactics inside it. v1 gave such a step the goals before and after the whole block, so a block that closes its goal read "no goals remain" beside a step that only splits it into cases. v2 gives the goals the head leaves to the tactics inside it, in order (each alternative starts at the first inner tactic met while no inner goal is open), then the goals after the block, and the head's lines. It falls back to the v1 goals when the unit's goals were truncated or the inner goals do not all close. A v1 explanation is still accepted and keeps the goals its auditors saw for its checks; its page shows the v2 goals, and says auditors checked them only where both versions agree. The writer adds statementLinks to each section and links to each step, lists of {text, lean}. The host rejects an output unless every text is verbatim in its statement or step text (the first occurrence is the one linked) and every lean is verbatim Lean, modulo whitespace runs, inside what that prose explains: a statement link inside the signature (for a theorem the source before its :=, for any other declaration all of it), a step link inside that step's own placed excerpts. Every theorem needs at least one statement link. The auditors judge each pair: a statement link whose phrase means something else makes the statement mismatch, a step link makes the step invented. They also receive stepGoals, the goals before the first and after the last tactic each step quotes, exactly as the page shows them for that version, and give each step a goals verdict: consistent, inconsistent (explained) or unrecorded, which must be used exactly when no goals are recorded. An inconsistent step blocks approval and reaches the writer as "step N goals inconsistent". The Markdown does not change.
The page draws each link as a dotted phrase. A link that cuts into a formula, inline code or bold text takes all of it, so a formula is never split, and a link overlapping an earlier one is dropped. Clicking a phrase, or pressing Enter or Space on it, chooses its statement or step and highlights the exact Lean text; pointing at it previews the text. A step with recorded goals says how many auditors compared it with them.
--formalization DIR names an approved formalization run or its artifact/. Its original problem becomes the writer's statement (so --statement-file is refused), and the proof must prove what was formalized: the same environment, a target the formalization states, and every declaration of its Statement.lean kept in the proof with the same kind and header (non-theorems verbatim, whitespace aside). Otherwise prepare writes nothing and fails with informalization_formalization_environment_mismatch, _target_missing or _declaration_changed: NAME. prepare copies Statement.lean, original.txt and evidence.json byte for byte to formalization/ (read-only) and records the evidence digest, the problem id and both statement digests in the request and the evidence. Every later read rechecks the copy against the record and the binding against the frozen proof (informalization_formalization_mismatch). The auditors still never see the original problem. The page and the offline report then show 原题: the original with the formalization reviewers' fragments underlined. Each fragment marks the Lean statement fragment it was matched with, wherever it is written in the proof's own copy of the formalized declarations, not a helper lemma that repeats the statement; clicking it again steps out to a longer fragment around it, and the text the chosen pairs quote stays tinted while their Lean is marked. On a phone, where the original is in the other pane, the Lean pane names the chosen fragment with its aspects and relations above the proof, and its button steps out as another click would. The folded list gives every correspondence, including fragments quoted from elaborated types that are not written in the source.
Build once after code changes and keep the printed buildManifestRef, as for formalization. Then prepare a directory outside the source repository. This step is offline:
bun run math informalize --phase prepare \
--directory /absolute/path/informalize-my-proof \
--proof-file /absolute/path/project/MyProof.lean --target MyNamespace.main_theorem \
--build-manifest /absolute/path/to/manifest.json \
[--project-root /absolute/path/project] [--statement-file problem.txt | --formalization /absolute/path/formalization-run] \
[--proof-id ID] [--alignment lean-phrase-alignment-v2|none] [--language zh|en] \
[--environment mathlib|standard] [--auditors 2] [--max-rounds-per-batch 6]--project-root defaults to the proof file's directory; local imports are resolved and frozen from it. --proof-id names the explanation and its report; it defaults to the target with every run of characters other than ASCII letters, digits, _ and - replaced by _, cut to 128 characters. Model flags (--model deepseek-flash, --effort max, --profile, --codex) and limits (--max-run-seconds, --max-turn-seconds, --max-compile-seconds, --max-total-tokens, all 0 = unlimited) work as in formalize. The writer and every auditor use the same model configuration in fresh threads, so their errors are not statistically independent.
bun run math informalize --phase run --directory /absolute/path/informalize-my-proof
bun run math informalize --phase inspect --directory /absolute/path/informalize-my-proofrun exits with code 2 unless the result is approved. The same command resumes a stopped run. The outline, accepted batches and every closed role whose input, instructions, schema and output digests still match are restored; a failed or interrupted role runs again in a fresh workspace. An approved run only re-verifies its artifact. An exhausted run needs a new directory.
bun run math informalize --phase report --directory /absolute/path/informalize-my-proof --output /absolute/path/my-proof.htmlreport writes the approved explanation as one offline page, the same view as the workbench's explanation page: Lean on the left, the prose with its links, goals and auditor notes on the right, 原题 when the request has a formalization, and a Markdown download. The top bar shows the proof id only when --proof-id gave one, since the default repeats the target named below it. It calls no model and needs bun run build:web first. Its line numbers are those of the proof file, so every explained declaration must be written there (informalization_report_multiple_files: NAME otherwise). The file is new, outside the source repository, read-only and self-contained (inlined scripts, styles, Latin fonts and data; system fonts for Chinese; a Content-Security-Policy that forbids loading anything), so it can be sent or archived as is. The JSON summary repeats the request digest, alignment and the formalization record.
Roles run in the same isolated sandbox as formalization roles: a bwrap mount, process and network namespace with read-only INPUT.json, ROLE.md and OUTPUT.schema.json, the pinned Lean and Mathlib, and a host relay for the frozen model only. Real runs therefore currently need the local Sub2API profile. A role can make up to three attempts when the model service fails temporarily. Each retry uses a fresh thread and a short jittered delay without advancing the review round. If the third attempt fails, the run stops with informalization_role_retries_exhausted and closes any audits still in progress. Account, policy and budget errors stop the run. DEEPSCIENTIST_MATH_MODEL_SLOTS and DEEPSCIENTIST_MATH_MODEL_SLOT_DIRECTORY share host admission control with other runs.
When accepted CLI runs are imported with bun run import:math-results, the importer automatically reads their approved artifacts and verifies every source against the accepted commit. The classic proof reader then displays these explanations, including local imports with their actual file names and line numbers, without adding entries to proofWalkthrough*.ts. Public data contains the verified reading projection rather than runtime profiles or host paths.
An accepted workbench run offers “Lean → 自然语言” in the proof header and source toolbar, opening explain.html?run=<id> with a target selector. The report also links each original target directly. These main entries remain available in raw-report mode and do not depend on loading the proof outline. Sample runs expose the same read-only page without generation, and its Back link returns to the sample. The Lean proof is on the left. The explanation opens with the main theorem and the proof outline on the right. “Read the main proof” jumps to the target’s derivation. Open the proof route and review details as needed. Clicking a step marks its quoted Lean lines; clicking a Lean line marks the step that explains it; the panes can scroll together. A click redraws only the sections whose chosen step, statement or note it changes, and scroll sync finds the step at the top of the explanation by halving, which keeps clicks and scrolling quick in a long proof. Clicking a cited lemma of the proof jumps to its section; “Back to where you were” in the explanation’s heading, or the browser's Back, returns to the scroll position, chosen step and pane the reader left, one jump at a time, without changing the address, so an offline report stays open. At 900 pixels or less the page shows one pane at a time without scrolling together, and a long Lean line wraps, its continuation indented 4 characters past the line's own indentation. A Lean name wraps only after a . or _. On a phone at least 360 pixels wide the target name shares a row with the switch between the panes; on a screen 480 pixels high or less, such as a phone held sideways, the bars above the panes are shorter, so the panes keep about two thirds of the height. A long inline formula in the explanation wraps only after a relation, operator or comma outside brackets that stands between two operands, never inside a piece. Printed, the page is one document: the explanation, then the whole Lean proof on a new page, wrapped, in light colours and without controls; folds print as the reader left them. New workbench solves automatically queue all original targets after independent Lean acceptance, and wait for statement review when it is pending. The queue uses the solve credentials only in memory, saves progress before announcing completion, and the conversation reads the audited document as soon as it is ready. Each run freezes the explanation language; a different interface language falls back to the existing explanation. GET requests never start work or backfill historical runs. Queue or quota refusals and generation failures preserve the accepted proof and can be retried manually from the explanation page, which shows an estimate scaled from the reference run (14 declarations, about 4.5 hours, 10.75 million tokens). Set autoExplain: false on a Web run or formalization request to disable automatic generation. It runs in one worker container per explanation (apps/web/explanationWorker.ts) with the run's model and effort (low stays low, medium and high become high, xhigh and max become max), two auditors and no default limits on runtime, tokens or batch rounds. Only runs on the sub2api gateway with deepseek-flash qualify for now. The server re-verifies the returned evidence against the run's accepted proof before approving the explanation, and the page reads a projection of it (apps/web/explanation.ts): sections in file order, each step with the proof-file lines it quotes. A theorem's statement is tied to its signature, from the start of the declaration to the first := or where outside brackets in the code with comments and strings blanked (or the first line of match arms); any other declaration is all statement. Excerpts are placed in step order, so a repeated tactic such as · omega lands on the occurrence after the previous step's, and each excerpt that occurs more than once is counted. Body lines no step quotes, other than lines of only by, ·, brackets and similar, are listed per declaration; the page rings them in a margin beside the line numbers, which also carries step numbers and a bar for the signature. Each cited name is located where it is written: in the step's own excerpt, elsewhere in the declaration, or nowhere (it reached the proof term through notation or automation); written ones carry their token positions so the page can highlight them. The auditors' explanations of each statement and step are shown folded. When the outline has goals, each step also shows, folded, Lean's goals before its first quoted tactic and after its last. Only the outermost tactics inside the quoted text count; when the text lies inside one tactic, that tactic's goals are shown. Explanations made before the goals pass show none. The projection is not stored: each read re-verifies the stored evidence against the run's proof and projects it again, and evidence that no longer verifies yields only a reason code. New workbench explanations use phrase alignment, so their pages carry linked phrases and goal checks; earlier ones keep their unaligned evidence and show neither. Workbench explanation jobs currently read the accepted Lean proof; the 原题 section is available in CLI explanations prepared with --formalization. See the workbench guide for queueing, storage and the browser check.
When repeated model failures stop a Web explanation, the next queued job can start. The page shows the current phase, approved batches, and review round when available. It counts model request failures separately. Open “Usage and limits” for the remaining figures. Retrying with the same proof and compatible worker and model settings reuses the extracted outline, approved batches and finished roles in the open round when a checkpoint was saved. Checkpoints are private to the run and contain no model credentials. Checkpoint support applies to jobs started with the new worker that reach the retry limit.
Each Web explanation model request times out after five minutes without output, including time spent waiting for the first response. Model output renews the timer, so a long review can keep running while it receives output. Gateway keepalive and status events do not renew it. An idle timeout counts toward the same three attempts as a connection failure.
The writer also gives each declaration a summary, one sentence on what it establishes and what it is used for, and in the final batch a route: 2 to 6 stages that narrow the target to what the proof checks, each with a claim and the declarations that carry it out (the last stage lists the target). The host checks that the route names only declarations of the proof. Each auditor judges every summary (faithful or mismatch) and the route (consistent or inconsistent) against the Lean; a mismatch or an inconsistent route sends the batch back like any other finding. --outline-policy none prepares a request without these fields, and requests and evidence made before the policy keep their inputs, role contracts and digests.
The explanation page uses the summaries for its outline reading and the route for the main line of the proof map. For an explanation without them it falls back to the statements and to the longest chain of cited declarations. The page also reads two things from Lean's elaborated terms, not from models: which declarations Lean decided by evaluation (decide in the kernel, native_decide by compiled code) and which library theorems each declaration's term uses.
Lean establishes that the proof compiles and that the target uses no sorryAx. The host establishes that each step quotes real Lean text of its declaration and cites declarations the Lean terms use, and with alignment that each linked phrase and its Lean are verbatim and in the right place. It does not establish that a step's prose is mathematically correct, that a statement translation or a link is faithful, that a step agrees with its goals, or that the explanation is complete. Those are model judgments by auditors that share the writer's model, and the artifact says so. Coverage is reported, not required. A formalization binding establishes only that the proof keeps the formalized declarations; whether those declarations say what the original problem says is the formalization reviewers' judgment.
Current limitations:
- Steps follow the source text. Recorded goals cover tactics only, not term-mode proofs, at most 4 goals per state. In a declaration over the 48 KB budget, nested tactics have no goals.
- Phrase alignment and the formalization binding have run with a real model only on small proofs: a two-step workbench proof (approved in round 1, 200 s, 51,240 tokens, 9 links) and a three-declaration Mathlib proof bound to an approved formalization (round 1, 907 s, 316,819 tokens, 24 links), every link on the right Lean. How often writers produce admissible links on larger proofs, and how many more tokens and rounds alignment costs there, is not measured; the workbench estimate still comes from an unaligned run.
reportneeds every explained declaration in the proof file itself.- The proof must compile in one of the runtime's pinned Lean task environments. CLI automatic generation retains the task receipt's environment, or matches the project's toolchain and Mathlib revision; unsupported environments are reported without changing versions. Module-system files are refused. The offline HTML
reportcurrently supportsstandardandmathlibonly; Markdown and evidence are available for the other pinned environments. omega,simpand similar automation leave many library lemmas in proof terms. They are listed as citable but not required.- Explicit
informalize prepare|runremains available for standalone proofs and custom generation limits.