lean-model
БесплатноЗапускает вложенные скриптыНе проверенUse this skill to prove or refute properties of real software in Lean 4. The target is the user's own code, not textbook math. It covers state machines…
от opum-ai★ 30 звёзд на GitHubОб этом скилле
lean-model
Lean gives three things at once, all from one language:
- an executable model that runs as a bounded model checker and a differential-testing oracle,
- theorems that cover every input, size, and interleaving, and
- a kernel that checks the proofs, so the only thing to trust is the statements.
Agents are now good at the proof engineering. The human-level decisions are what to model and which statements to believe. This skill is organized around those decisions.
For a full bug hunt (scoping, the correspondence map, reproduction in real code, the fix, and
the Artifact report), follow formal-verify and use this skill for the model.
Setup
S=${CLAUDE_SKILL_DIR}/scripts
$S/setup_lean.sh # elan (no sudo); projects pin their own toolchain
$S/new_project.sh formal/<concern>/lean JobLease # template: Explore + System + Properties
cd formal/<concern>/lean && lake build
$S/check_trust.sh . # sorry/axiom/native_decide audit; --json for findings
The template has no Mathlib, only core Lean plus optional plausible. Software models rarely
need Mathlib: core has List, Array, Std.HashMap, omega, grind, decide,
bv_decide, simp, and Relation.TransGen. Mathlib adds about 8 GB of build cache.
See references/setup.md. lake env lean F.lean does not build dependencies, so run
lake build first.
The loop: model, then refute, then prove
State and steps. Write the component's state as a
structure SderivingDecidableEqandRepr. Keep only what the properties read. Write the steps as aninductive Step : S → S → Prop:- one constructor per atomic region of the code (between
awaits, a locked section, one SQL statement, one handler); - a per-actor program counter wherever the code can yield;
- retries, duplicates, and crashes as their own constructors.
Tag each constructor's docstring
src: path:lines.- one constructor per atomic region of the code (between
Executable twin. Write
next : S → List (String × S)with action labels, and provenext_sound(every executable move is aStep) so the twins cannot drift apart. The template includes this.Refute first. It is cheaper than proving.
#eval Explore.bfs next bad initreturns the shortest labeled trace to a bad state.Explore.validPath_reach … (by decide)turns that trace into a kernel-checked theorem that the bug is reachable.decide +kernelruns exhaustive bounded checks and trusts onlypropext.plausibledoes property-based testing of pure functions.
Most bugs appear here, in seconds. Hand real ones to
formal-verifyfor reproduction.State the property and freeze it in
Properties.lean, citing its source. Also write a non-vacuity witness: a path, checked bydecide, to a state where the interesting thing happens. A safety theorem over a model where nothing can happen is worthless.Prove by an inductive invariant.
- Prove
inv_init, theninv_step(cases hs <;> grind [Inv, …]), then lift the result withExplore.Reach.inv. - When
grindorsimp_allfails on one constructor, the leftover goal is a counterexample to induction: a state that satisfiesInvbut is unreachable, whose successor breaksInv. Add the missing fact toInvand repeat. This loop is the heart of the method, and the missing fact is often a real edge case worth checking in the code. - Details and stuck-proof tactics:
references/proving.md.
- Prove
Audit trust.
check_trust.shmust report 0 problems for any theorem called "proven".- Standard axioms (
propext,Classical.choice,Quot.sound) are fine. sorryAxis not a proof.native_decidetrusts the compiler: allow it only with--allow-native, and disclose it.
Connect to the code. Mirror fixes in the model and re-prove. Use
lake exe replay(the differential-testing driver inassets/lean-patterns/Replay.lean) to compare model outputs with production traces (references/differential-testing.md).
Patterns: all compile on Lean 4.34.0, with 0 sorry
assets/lean-patterns/ProofPatterns/, one file per pattern. references/patterns.md
explains each one.
| File | Shows | Headline results |
|---|---|---|
Explore.lean |
Reach, invariant induction, BFS with traces, trace → theorem | Reach.inv, validPath_reach |
Counter.lean |
lost update vs. mutex; interleavings as a step relation | racy_lost_update (bug as proof term), no_lost_update |
Idempotency.lean |
async check-then-act across await; retries |
buggy_double_apply, applied_nodup |
Queue.lean |
FIFO: no loss, reordering, or duplication | recvd_prefix |
Pipeline.lean |
batching stage drops its tail; generalized fold lemma | batch_lossless |
Graph.lean |
acyclicity and topological order by certificate checking | acyclic_of_check |
StateMachine.lean |
transition table + read-decide-wr |
Установить lean-model в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл lean-model?
Use this skill to prove or refute properties of real software in Lean 4. The target is the user's own code, not textbook math. It covers state machines, concurrency and interleavings, async handlers, retries and idempotency, queues, batching pipelines, and graph algorithms such as topological order, acyclicity and DAG scheduling. Trigger it when the user wants a guarantee for every input or size ("holds for all N"), beyond what TLC, tests or a model checker showed. Also trigger it for invariant proofs by induction, a concrete counterexample trace, an executable reference model for differential testing, or setting up a Lean/lake project to model code. Also use it to audit a Lean development's trust base: sorry, axioms, native_decide. Do NOT use it for pure mathematics such as analysis, algebra or Mathlib coursework and homework. Do NOT use it to translate code into Lean syntax, or for other provers like Dafny, Coq or Isabelle. Pairs with formal-verify for bug hunts and tlaplus-model for protocol exploration.
Как установить скилл lean-model?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл lean-model запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic