writing-lean-proofs
Ce qu’il fait
Ce skill guide la rédaction de preuves formelles en langage Lean 4 et l'organisation du code Lean en bibliothèque. Il s'adresse aux mathématiciens et ingénieurs qui formalisent des théorèmes ou des spécifications.
Quand l’utiliser
- ✓Quand vous prouvez un théorème en Lean 4 et voulez une structure claire pour la preuve.
- ✓Quand une longue preuve par tactiques est difficile à lire et doit être découpée en lemmes plus petits.
- ✓Quand vous relisez du code Lean pour sa lisibilité ou le préparez pour Mathlib.
Lien du skill
https://github.com/trailofbits/skills/blob/main/plugins/writing-lean-proofs/skills/writing-lean-proofs/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Aide-moi à prouver ce théorème en Lean 4 et à découper la longue preuve en lemmes plus petits.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
Il suit une approche descendante. Vous concevez d'abord les définitions et les énoncés, puis vous remplissez les preuves étape par étape, avec des espaces réservés jusqu'à ce que chacune soit terminée.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes
Quelle est l'idée centrale ?
Concevoir d'abord les énoncés, car ils forment la partie stable. Les preuves peuvent être remplacées plus tard sans casser le reste du code.
Couvre-t-il la mise en place d'un projet ?
Oui. Il mentionne l'intégration continue, les linters et la configuration de vérification pour les projets sur lesquels travaillent plusieurs personnes ou agents.
Suit-il un style particulier ?
Il suit le style et les conventions de relecture de Mathlib, et s'appuie sur de grands projets de formalisation.
Détails
Description originale de l’auteur
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
Popularité
- Étoiles GitHub
- 8.0k
- Position au classement
- #12741
- Licence
- CC-BY-SA-4.0
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
audit-context-building
8.0kAide votre agent à comprendre un code inconnu avant une revue de sécurité, en cartographiant ce que chaque fonction suppose, garantit et utilise.
algorand-vulnerability-scanner
8.0kAide votre agent à scanner des contrats Algorand (TEAL, PyTeal) pour 11 failles courantes, comme la réaffectation de clé ou les frais non contrôlés.
audit-prep-assistant
8.0kAide votre agent à préparer votre code pour une revue de sécurité externe, avec analyse statique, couverture de tests, nettoyage du code mort et documentation claire.
cairo-vulnerability-scanner
8.0kAide votre agent à scanner les contrats Cairo sur StarkNet pour 6 problèmes graves, comme les dépassements arithmétiques et le rejeu de signature.
Skills similaires
diffs
394kPermet à votre agent de produire un diff réel et partageable de vos modifications, sous forme de lien ou d'image, plutôt qu'un résumé écrit à la main.
coding-agent
394kAide votre agent à confier une tâche de programmation plus importante à Codex, Claude Code ou OpenCode comme travailleur en arrière-plan, puis à suivre sa progression.
gh-issues
394kAide votre agent à trouver des tickets GitHub, choisir ceux à traiter et ouvrir des pull requests avec des correctifs, y compris le suivi des commentaires de relecture.