Logo vun Lean Model

Lean Model

Organisatioun
opum-ai
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.

Iwwersiicht

Editeuropum-ai
Repositoryproof-skills
Skill-Nummlean-model
Stären
27
Forks
6
Matgeliwwert Fichieren
28
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 28 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    Vum opum-ai op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Lean Model an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/opum-ai/proof-skills/tree/main/skills/lean-model
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/opum-ai/proof-skills.git /tmp/proof-skills
mkdir -p .claude/skills
cp -r /tmp/proof-skills/skills/lean-model .claude/skills/lean-model
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Lean Model an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Lean Model automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Lean Model net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

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

bash
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

  1. State and steps. Write the component's state as a structure S deriving DecidableEq and Repr. Keep only what the properties read. Write the steps as an inductive 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.

  2. Executable twin. Write next : S → List (String × S) with action labels, and prove next_sound (every executable move is a Step) so the twins cannot drift apart. The template includes this.

  3. Refute first. It is cheaper than proving.

    • #eval Explore.bfs next bad init returns 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 +kernel runs exhaustive bounded checks and trusts only propext.
    • plausible does property-based testing of pure functions.

    Most bugs appear here, in seconds. Hand real ones to formal-verify for reproduction.

  4. State the property and freeze it in Properties.lean, citing its source. Also write a non-vacuity witness: a path, checked by decide, to a state where the interesting thing happens. A safety theorem over a model where nothing can happen is worthless.

  5. Prove by an inductive invariant.

    • Prove inv_init, then inv_step (cases hs <;> grind [Inv, …]), then lift the result with Explore.Reach.inv.
    • When grind or simp_all fails on one constructor, the leftover goal is a counterexample to induction: a state that satisfies Inv but is unreachable, whose successor breaks Inv. Add the missing fact to Inv and 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.
  6. Audit trust.

    • check_trust.sh must report 0 problems for any theorem called "proven".
    • Standard axioms (propext, Classical.choice, Quot.sound) are fine.
    • sorryAx is not a proof.
    • native_decide trusts the compiler: allow it only with --allow-native, and disclose it.
  7. Connect to the code. Mirror fixes in the model and re-prove. Use lake exe replay (the differential-testing driver in assets/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.

FileShowsHeadline results
Explore.leanReach, invariant induction, BFS with traces, trace → theoremReach.inv, validPath_reach
Counter.leanlost update vs. mutex; interleavings as a step relationracy_lost_update (bug as proof term), no_lost_update
Idempotency.leanasync check-then-act across await; retriesbuggy_double_apply, applied_nodup
Queue.leanFIFO: no loss, reordering, or duplicationrecvd_prefix
Pipeline.leanbatching stage drops its tail; generalized fold lemmabatch_lossless
Graph.leanacyclicity and topological order by certificate checkingacyclic_of_check
StateMachine.leantransition table + read-decide-write race; CAS fixtransitions_allowed
DagScheduler.leandependency-respecting dispatch for every graphdeps_respected
RedundantGuard.leanproving a defensive check is dead, then deleting itguard_implied, reach_iff

When to use Lean vs. TLA+

Use Lean for:

  • algorithmic cores,
  • data transformations,
  • graph properties for all graphs,
  • unbounded "for every N" safety,
  • certificate checkers, and
  • executable reference models.

Use TLA+ for:

  • quick exhaustive interleaving search,
  • liveness and fairness (Lean has no mature temporal-logic library), and
  • protocol exploration.

Combined: TLA+ finds the trace fast; Lean proves the fixed invariant for every size. Keep TLC traces as decide regression examples in Lean. See formal-verify/references/choosing-tools.md.

Rules that keep proofs honest

  • The model is the claim. Review theorem statements as carefully as code, and never edit a frozen statement to make a proof go through. Report it instead.
  • Do not make read-modify-write atomic in the model unless the code makes it atomic. That single abstraction hides most concurrency bugs.
  • partial def cannot be unfolded in proofs. Use fuel (as Explore.bfs does) or well-founded recursion for anything you reason about.
  • A name like id can silently resolve to a builtin. Inside match/∀, write PC.awaiting rather than .awaiting when the expected type is unknown.
  • Destructure invariant conjunctions (obtain ⟨h1, h2, h3⟩ := h) and case-split on actor and program counter before calling grind or simp_all.

Reference files

  • references/patterns.md — each pattern: the code shape, the bug, the proof strategy, and how to adapt it.
  • references/proving.md — the tactic playbook, the invariant-strengthening loop, stuck-proof strategies, AI provers.
  • references/pitfalls.md — vacuity, trust base, drift, over-abstraction, spec gaming.
  • references/differential-testing.md — executable models against production: replay, random inputs, CI.
  • references/setup.md — elan, lake, toolchain pinning, Mathlib trade-offs, lean-lsp-mcp for agents.

Matgeliwwert Fichieren

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill 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 different...

Firwat Lean Model op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Lean Model besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Lean Model an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/opum-ai/proof-skills/tree/main/skills/lean-model an. TypingMind liest d'Datei SKILL.md, bündelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Lean Model benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Lean Model benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Lean Model domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Lean Model gratis?

Jo. De Skill gëtt vum opum-ai ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇