lean-bridge: paper proposition ↔ Lean theorem
Scope: what to formalise
Formalise the finite algebraic core: identities, support and character arguments,
counting bounds, injectivity and admissibility conditions, cost-ratio identities and
limits. Do not try to formalise lattice hardness, concrete noise distributions or
performance.
If a quantity is only modelled, say so in the table and in the paper. An example is a
noise bound taken as a definition rather than derived from ciphertext semantics. The
paper may then claim only "operation/level counts are machine-checked relative to the
model". It may not claim "noise growth is machine-checked".
Procedure
Start from lib/lean-template/. Copy it and keep lean-toolchain and the Mathlib
rev in sync.
Run a numeric check first (skills/sage-check). Never start formalising a
statement that has not survived toy parameters.
For each proposition, write the Lean statement first, with the proof as a
placeholder on a WIP branch. Get the statement reviewed against the paper text.
Most mismatches are in the statement, not the proof. Common ones: the Lean version
is weaker, uses ℕ where the paper needs ℤ, or adds a hypothesis the paper omits.
Prove it. Useful tactics: decide for tiny concrete finite facts; ring,
field_simp, linear_combination for identities; omega for linear
ℕ/ℤ arithmetic; norm_num, simp for evaluation. Avoid native_decide.
Fill in the table, which is kept in the Lean project README and mirrored in
THEORY.md:
| paper statement |
Lean name (fully qualified) |
file |
modelling notes |
| Lemma 3.2 (support stability) |
Proj.Support.stable |
Support.lean |
coefficient level |
Gate (all must pass before the table is cited in the paper):
lake build is green on a clean checkout at the recorded commit;
scripts_check_no_sorry.sh reports no sorry/admit/axiom/native_decide;
- an axiom audit of every headline theorem (
#print axioms T or lean_verify)
shows only propext, Classical.choice, Quot.sound;
- the table rows match the paper numbering on the final PDF.
Record the Lean commit and the "green build" log in EVIDENCE.md, for example
"N results, zero sorry" as the printed fact and the lake build log as its source.
Lessons
- Lean often finds redundant or insufficient hypotheses. Run
lean_minimal_hypotheses on key theorems. Sometimes a hypothesis the paper states
is not needed, which gives a stronger theorem. Sometimes the Lean proof needs one
the paper forgot, which is a correctness fix. Report both to theorist and
falsifier.
- Formalising the coefficient-level statement is usually much easier than the
polynomial-ring statement. Prove a bridge lemma (for example, the coefficient of
P.comp (C a * X)) once and reuse it.
- Keep each file under a few hundred lines, with one namespace per paper section.
- A cost-ratio "→ 2 as d → ∞" claim can be formalised with
Filter.Tendsto. Pair it
with an explicit finite bound, because reviewers care about concrete sizes.
Mathlib cache pitfalls
See lib/lean-template/README.md. In short: match the toolchain and the Mathlib rev;
run lake exe cache get after every lake update; never import Mathlib in project
files; allow minutes for the first cold import; look up renamed lemmas with search
tools, not from memory.
lean-lsp MCP tools (if configured)
| need |
tool |
tip |
| quick compile of a snippet |
lean_run_code |
self-contained with imports; the server needs lake on PATH |
| goal at a line |
lean_goal |
omit the column to see the state before and after the line |
| errors |
lean_diagnostic_messages |
"no goals to be solved" means delete tactics |
| lemma by name fragment |
lean_local_search |
use before guessing a name |
| lemma by meaning |
lean_leansearch / lean_leanfinder |
rate-limited |
| lemma by type |
lean_loogle |
rate-limited, a few calls per 30 s |
| try tactics |
lean_multi_attempt |
["simp", "ring", "omega", "decide", "norm_num"] |
| which hypotheses are needed |
lean_minimal_hypotheses |
|
| axiom audit |
lean_verify |
fully qualified name |
| after adding imports |
lean_build |
slow; fetch_cache=true only for missing oleans |
1---2name: lean-bridge3description: Connect paper propositions to Lean4/Mathlib theorems with a proposition-to-Lean-name table, a zero-sorry policy and an axiom audit. Use when formalising the algebraic core of a paper, when a reviewer questions a proof, or before claiming "machine-checked" anywhere. Covers Mathlib cache pitfalls and the lean-lsp MCP tools.4metadata:5 source: https://skillmd.com/skills/jiayaoqijia/lean-bridge6---78# lean-bridge: paper proposition ↔ Lean theorem910## Scope: what to formalise1112Formalise the **finite algebraic core**: identities, support and character arguments,13counting bounds, injectivity and admissibility conditions, cost-ratio identities and14limits. Do **not** try to formalise lattice hardness, concrete noise distributions or15performance.1617If a quantity is only *modelled*, say so in the table and in the paper. An example is a18noise bound taken as a definition rather than derived from ciphertext semantics. The19paper may then claim only "operation/level counts are machine-checked relative to the20model". It may **not** claim "noise growth is machine-checked".2122## Procedure23241. Start from `lib/lean-template/`. Copy it and keep `lean-toolchain` and the Mathlib25 `rev` in sync.262. **Run a numeric check first** (`skills/sage-check`). Never start formalising a27 statement that has not survived toy parameters.283. For each proposition, write the Lean *statement* first, with the proof as a29 placeholder on a WIP branch. Get the statement reviewed against the paper text.30 Most mismatches are in the statement, not the proof. Common ones: the Lean version31 is weaker, uses ℕ where the paper needs ℤ, or adds a hypothesis the paper omits.324. Prove it. Useful tactics: `decide` for tiny concrete finite facts; `ring`,33 `field_simp`, `linear_combination` for identities; `omega` for linear34 ℕ/ℤ arithmetic; `norm_num`, `simp` for evaluation. Avoid `native_decide`.355. Fill in the **table**, which is kept in the Lean project README and mirrored in36 THEORY.md:3738 | paper statement | Lean name (fully qualified) | file | modelling notes |39 |---|---|---|---|40 | Lemma 3.2 (support stability) | `Proj.Support.stable` | `Support.lean` | coefficient level |41426. **Gate** (all must pass before the table is cited in the paper):43 - `lake build` is green on a clean checkout at the recorded commit;44 - `scripts_check_no_sorry.sh` reports no `sorry`/`admit`/`axiom`/`native_decide`;45 - an axiom audit of every headline theorem (`#print axioms T` or `lean_verify`)46 shows only `propext`, `Classical.choice`, `Quot.sound`;47 - the table rows match the paper numbering on the final PDF.487. Record the Lean commit and the "green build" log in EVIDENCE.md, for example49 "N results, zero sorry" as the printed fact and the `lake build` log as its source.5051## Lessons5253- Lean often **finds redundant or insufficient hypotheses**. Run54 `lean_minimal_hypotheses` on key theorems. Sometimes a hypothesis the paper states55 is not needed, which gives a stronger theorem. Sometimes the Lean proof needs one56 the paper forgot, which is a correctness fix. Report both to `theorist` and57 `falsifier`.58- Formalising the *coefficient-level* statement is usually much easier than the59 *polynomial-ring* statement. Prove a bridge lemma (for example, the coefficient of60 `P.comp (C a * X)`) once and reuse it.61- Keep each file under a few hundred lines, with one namespace per paper section.62- A cost-ratio "→ 2 as d → ∞" claim can be formalised with `Filter.Tendsto`. Pair it63 with an explicit finite bound, because reviewers care about concrete sizes.6465## Mathlib cache pitfalls6667See `lib/lean-template/README.md`. In short: match the toolchain and the Mathlib rev;68run `lake exe cache get` after every `lake update`; never `import Mathlib` in project69files; allow minutes for the first cold import; look up renamed lemmas with search70tools, not from memory.7172## lean-lsp MCP tools (if configured)7374| need | tool | tip |75|---|---|---|76| quick compile of a snippet | `lean_run_code` | self-contained with imports; the server needs `lake` on PATH |77| goal at a line | `lean_goal` | omit the column to see the state before and after the line |78| errors | `lean_diagnostic_messages` | "no goals to be solved" means delete tactics |79| lemma by name fragment | `lean_local_search` | use before guessing a name |80| lemma by meaning | `lean_leansearch` / `lean_leanfinder` | rate-limited |81| lemma by type | `lean_loogle` | rate-limited, a few calls per 30 s |82| try tactics | `lean_multi_attempt` | `["simp", "ring", "omega", "decide", "norm_num"]` |83| which hypotheses are needed | `lean_minimal_hypotheses` | |84| axiom audit | `lean_verify` | fully qualified name |85| after adding imports | `lean_build` | slow; `fetch_cache=true` only for missing oleans |