writing-lean-proofs
Was er macht
Dieser Skill führt durch das Schreiben formaler Beweise in der Sprache Lean 4 und durch die Organisation von Lean-Code als Bibliothek. Er richtet sich an Mathematiker und Ingenieure, die Sätze oder Spezifikationen formalisieren.
Wann du ihn nutzt
- ✓Wenn du in Lean 4 einen Satz beweist und eine klare Struktur für den Beweis willst.
- ✓Wenn ein langer Taktik-Beweis schwer lesbar ist und in kleinere Lemmata aufgeteilt werden muss.
- ✓Wenn du Lean-Code auf Lesbarkeit prüfst oder ihn für Mathlib vorbereitest.
Link zum Skill
https://github.com/trailofbits/skills/blob/main/plugins/writing-lean-proofs/skills/writing-lean-proofs/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Hilf mir, diesen Satz in Lean 4 zu beweisen, und teile den langen Beweis in kleinere Lemmata auf.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Skill folgt einem Top-down-Ansatz. Zuerst entwirfst du die Definitionen und Aussagen, dann füllst du die Beweise Schritt für Schritt aus, mit Platzhaltern, bis jeder vollständig ist.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
Writing Lean Proofs
Contents
- When to Use
- When NOT to Use
- The workflow
- The extraction ladder
- Quick reference
- Rationalizations to reject
- References
Structured Lean 4 proof writing and library design, distilled from Mathlib's style and review conventions and from the methodology of large formalization projects (Liquid Tensor Experiment, PFR, Fermat's Last Theorem).
Core principle: design top-down, prove bottom-up. Lean propositions are
proof-irrelevant — only a theorem's statement can affect later declarations.
Statements are the stable interface; proofs are disposable and freely
replaceable. Put design effort into definitions and statements, then fill in
proofs against skeletons that already compile (modulo sorry).
When to Use
- Proving theorems in Lean 4, from single lemmas to multi-file developments
- Formalizing mathematics, protocols, or software specifications in Lean
- Defining new types, structures, or functions in a Lean library
- Reviewing Lean code for readability, maintainability, or Mathlib readiness
- Refactoring a long or fragile tactic proof into lemmas
- Setting up a formalization project that several people or agents will contribute to in parallel
- Setting up CI, linters, or verification gates for a Lean project — do this at project start, before patterns propagate
- Diagnosing slow proofs,
maxHeartbeatstimeouts, or expensive reduction - Writing custom tactics, macros, or project-specific linters
When NOT to Use
- Lean 4 as a general-purpose programming language (no proofs involved) — most of this skill targets proof and API structure
- Coq, Isabelle, Agda, or Lean 3 — conventions and tactic names differ;
Lean 3 idioms (
ge_or_gtlinting,discrete_field) are obsolete - Verified-software Lean projects with their own house style (e.g. spec-traceability-first codebases): Mathlib conventions are the community default, but check the project's CONTRIBUTING first and defer to it
The workflow
1. Design definitions and their API first
Definitions carry the design weight. Before proving anything about a new concept:
- Prefer total functions with junk values over subtypes or
Optionin signatures (Mathlib:(0 : ℝ)⁻¹ = 0). Side conditions then appear only on the lemmas that need them, not at every use site. - Bundle: new morphism kinds are structures with a
FunLikeinstance; new subobject kinds useSetLike; carry property proofs as structure fields, not separateIsHom-style predicates. - Pick the canonical spelling (simp-normal form) for every concept with multiple equivalent forms, and state all API lemmas for that form only.
- Write the API in the same file, immediately:
ext,@[simp], coercion, and injectivity lemmas — before the definition is used anywhere. Downstream proofs use the API, neverunfold/show ... from rfl.
See library-design.md for the full set of design rules with rationale.
2. Build a sorry skeleton
State everything before proving anything, at every scale:
- Project scale: state the target theorem and the lemmas it needs, all
with
:= sorry, and make the file compile. Eachsorryis now an independent work unit — a contributor (human or LLM) can discharge one without understanding the rest. This is how LTE, PFR, and FLT scale to dozens of parallel contributors. - Proof scale: inside a proof, lay out the
have/suffices/calcskeleton withsorryjustifications, get Lean to accept the structure, then fill each step. Keeping the structure intact is what produces useful error messages while you work.
example (a b c d : ℝ) (h : c = d * a + b) (h' : b = a * d) : c = 2 * a * d := by
calc
c = d * a + b := sorry
_ = d * a + a * d := sorry
_ = 2 * a * d := sorry
3. Fill goals, one focused goal at a time
- Every new subgoal gets a focusing dot
·with an indented block — never leave several goals active in unfocused sequence (Mathlib'smultiGoallinter enforces this). This is what kills fragile goal-ordering dependence. - Open each block with a redundant
showstating its goal. The proof works without it; reviewers and future editors need it. Ifshowwould change the goal, usechangeinstead — keep stated goals honest. - Ch
Häufige Fragen
Was ist die Kernidee?
Zuerst die Aussagen entwerfen, denn sie sind der stabile Teil. Beweise lassen sich später ersetzen, ohne anderen Code zu brechen.
Deckt er die Einrichtung eines Projekts ab?
Ja. Er nennt CI, Linter und die Einrichtung der Verifikation für Projekte, an denen mehrere Personen oder Agenten arbeiten.
Folgt er einem bestimmten Stil?
Er folgt dem Stil und den Review-Konventionen von Mathlib und stützt sich auf große Formalisierungsprojekte.
Details
Originalbeschreibung des Autors
Writes and reviews structured Lean 4 proofs and designs Lean libraries following Mathlib conventions. Use when proving theorems in Lean, formalizing mathematics or specifications in Lean 4, defining new types or definitions in a Lean library, reviewing Lean proofs for readability and maintainability, refactoring long tactic proofs into lemmas, filling in sorry placeholders in a Lean development, setting up CI or linters for a Lean project, diagnosing slow proofs or maxHeartbeats timeouts, or writing custom tactics, macros, or linters.
repo: trailofbits/skills
Beliebtheit
- GitHub-Sterne
- 8.0k
- Platz im Ranking
- #12741
- Lizenz
- CC-BY-SA-4.0
- Aktualisiert
- 2.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
audit-context-building
8.0kHilft deinem Agenten, eine unbekannte Codebasis vor einem Sicherheitsreview zu verstehen, und zeigt, was jede Funktion voraussetzt, garantiert und wovon sie abhängt.
algorand-vulnerability-scanner
8.0kHilft deinem Agenten, Algorand-Smart-Contracts in TEAL oder PyTeal auf 11 häufige Sicherheitsprobleme zu prüfen, etwa Rekeying-Angriffe und ungeprüfte Gebühren.
audit-prep-assistant
8.0kHilft deinem Agenten, eine Codebasis auf ein externes Sicherheitsreview vorzubereiten, mit statischer Analyse, Testabdeckung, Bereinigung von totem Code und klarer Dokumentation.
cairo-vulnerability-scanner
8.0kHilft deinem Agenten, Cairo-Smart-Contracts auf StarkNet auf 6 ernste Probleme zu prüfen, etwa Arithmetik-Überläufe, riskante Nachrichten zwischen Schichten und Signatur-Replay.
Ähnliche Skills
diffs
394kLässt deinen Agenten einen echten, teilbaren Diff seiner Änderungen als Viewer-Link oder Bilddatei erstellen, statt einer handgeschriebenen Zusammenfassung.
coding-agent
394kHilft deinem Agenten, eine größere Programmieraufgabe als Hintergrund-Worker an Codex, Claude Code oder OpenCode zu übergeben und danach den Fortschritt zu prüfen.
gh-issues
394kHilft deinem Agenten, GitHub-Issues zu finden, die zu bearbeitenden auszuwählen und Pull Requests mit Korrekturen zu öffnen, einschließlich der Nacharbeit an Review-Kommentaren.