شعار Lean Verify

Lean Verify

المجتمع
hirosassa
lean-verify

Use the Lean 4 theorem prover to find software bugs with counterexamples (integer overflow, bit manipulation, boundary conditions, spec/implementation mismatches) and to prove that an optimization or refactoring is equivalent to the original, so performance work can land safely. Also covers installing Lean and creating a minimal project. Use this skill proactively, even when Lean is not mentioned by name, when the user mentions Lean / lake / elan / formal verification / theorem proving / bv_decide / counterexample search / "is this optimization equivalent?" / "check that it holds for all inputs" / "find bugs tests can't catch" / "safely swap out a bit-twiddling or arithmetic trick", or wants to confirm the correctness of a peephole optimization, strength reduction, bounds-check elimination, or algorithm rewrite. Language-agnostic (Rust, C, Go, TypeScript, ...).

نظرة عامة

الناشرhirosassa
المستودعlean-verify
اسم المهارةlean-verify
النجوم
66
التفريعات
2
الملفات المرفقة
8
الترخيصMIT
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 8

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها hirosassa على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Lean Verify في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/hirosassa/lean-verify/tree/main/skills/lean-verify
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/hirosassa/lean-verify.git /tmp/lean-verify
mkdir -p .claude/skills
cp -r /tmp/lean-verify/skills/lean-verify .claude/skills/lean-verify
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Lean Verify في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Lean Verify تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Lean Verify بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

lean-verify: Find bugs and speed up code safely with Lean 4

Tests only guarantee the inputs you tried. Lean can mechanically answer whether a property holds for all inputs, or hand back a counterexample. This skill uses Lean not as a heavyweight verification framework but as a tool for small functions and single rewrite rules. Do not try to prove a whole program: the proof cost explodes and you learn nothing extra.

When to use it

SituationFitMode
Correctness of integer ops, bit ops, shifts, rotations, wrapping arithmeticExcellentA: bv_decide
"Is the optimized version equal to the naive one?" (strength reduction, bit tricks, expression rewrites)ExcellentB: equivalence
Bounds-check elimination, index range validityGoodB + omega
Loop/recursion invariants, algorithm rewritesGood (needs induction)B + induction
Exhaustive search over a small finite domainGooddecide / #eval
I/O, concurrency, networking, code with huge statePoorRecommend ordinary tests / fuzzing

If the target is a poor fit, don't force it into Lean. Say so and propose another approach.

Workflow

  1. Check the environment → run scripts/check_lean.sh. If it prints found (not on PATH) and a hint: export PATH=... line, Lean is in ~/.elan/bin but not on PATH: run that export in the same Bash call as lean / lake. If Lean is missing, follow references/setup.md (ask the user before installing). If plausible looks necessary (searching for properties over structured data such as lists), read the plausible: line of the output: available means use it, not installed means follow references/setup.md §4 (ask the user first). Don't propose it when bv_decide or #eval can do the job (fixed-width integers, small finite domains).
  2. Narrow the target: verify one function or one rewrite rule. Split anything larger.
  3. Model it: translate the target into Lean definitions. Watch for semantic differences (see "Modeling pitfalls" below). Start the file from this minimal template; forgetting the import is the most common first error (error: "to use bv_decide, please include import Std.Tactic.BVDecide"):
    lean
    import Std.Tactic.BVDecide
    
    theorem t (x : BitVec 32) : (x <<< 1) = x * 2 := by bv_decide
  4. State the property: for bug hunting, the property the code should satisfy; for optimization, fast x = slow x.
  5. Look for a counterexample first: before proving, try bv_decide / plausible / #eval. A counterexample saves the proof effort and is directly usable as a bug report.
  6. Prove it: try the tactics in the order given in references/tactics.md (bv_decide → omega → decide +kernel → simp → induction). Once it is proved, run a mutation check: change one constant or operator (e.g. <<< 3 → <<< 2) and confirm Lean now reports a counterexample. If the mutant is still proved, the proof is probably vacuous (details in references/perf-equivalence.md).
  7. Translate the result back: turn a counterexample into concrete inputs in the original language and write a test that reproduces it in the original code (don't take Lean's output on faith; a modeling gap can cause a false positive). Don't call it a bug until it reproduces in the real code (see "potentially spurious counterexample" under Known limitations). A successful proof means "equivalent in the model"; state explicitly that the correspondence between the model and the real code is a human guarantee.

Modes

A. Bug hunting (go get a counterexample)

Write the spec a different way (more naive, or computed in a wider type) and compare it with the implementation. When bv_decide fails it returns a counterexample assignment:

lean
def avgBad (a b : BitVec 32) : BitVec 32 := (a + b) >>> 1          -- a+b overflows 32 bits
def avgSpec (a b : BitVec 32) : BitVec 32 :=
  ((a.zeroExtend 33 + b.zeroExtend 33) >>> 1).truncate 32          -- compute in 33 bits
theorem t (a b : BitVec 32) : avgBad a b = avgSpec a b := by unfold avgBad avgSpec; bv_decide
-- error: The prover found a counterexample: a = 4294967295#32, b = 4294967295#32

If bv_decide can neither prove the property nor produce a counterexample, suspect how the spec is written or a missing precondition (e.g. h : x ≠ 0). Full examples are in assets/examples/ and have been run. Detailed steps are in references/bug-hunting.md.

B. Proving an optimization equivalent

Optimizations risk being "faster but subtly different". Treat the naive implementation as the spec and the optimized one as the implementation, prove they are equal, and the rewrite can be adopted with confidence:

lean
theorem mul10 (x : BitVec 32) : (x <<< 3) + (x <<< 1) = x * 10 := by bv_decide
theorem mod8  (x : BitVec 32) : x % 8 = x &&& 7 := by bv_decide

For optimizations with preconditions (e.g. "only holds when x is a power of two"), state the precondition as a hypothesis (h : ...). Whether callers actually guarantee it must be checked separately. Rewrites of recursion or loops use induction. Details in references/perf-equivalence.md.

Modeling pitfalls (the main source of false positives/negatives)

  • Lean's BitVec is two's-complement wrapping arithmetic. Rust's + panics in debug builds; wrapping_add is what matches Lean. Map to the semantics of the target language and build mode.
  • Shift amounts behave differently. Shifting a BitVec by its width or more gives 0 in Lean, but Rust's <</>> panic at width or more (masked in release), and C is undefined behavior. Reduce the shift amount with % 32 or put it in a precondition so it matches the original language.
  • Signed division/remainder rounding (toward zero vs. floor) differs by language. Check which of BitVec.sdiv / srem / smod corresponds.
  • Floating point is outside bv_decide's scope. Extract only the integer part.
  • Nat / Int have unbounded precision. Use BitVec n to study fixed-width behavior.

Known limitations (hit in practice)

  • Plausible (property-based testing) is not part of core. If check_lean.sh reports plausible: not installed and you need it, ask the user for permission before adding it (it edits lakefile.toml and downloads from the network; see references/setup.md §4). Never add it unasked. If the user declines, or for a single file, an exhaustive #eval search can stand in.

  • ring_nf / nlinarith / linarith and friends are Mathlib-only. To stay within core, use simp only [Nat.add_mul, ...] + omega. Mathlib's first build is heavy, so don't add it until it is needed.

  • Using decide for an exhaustive search as small as Fin 256 can hit the recursion limit. Use decide +kernel or set_option maxRecDepth N in decide.

  • The first lean run downloads the toolchain and can take minutes, and concurrent elan invocations wait on a lock. Watch for timeouts and use background execution.

  • bv_decide uses a SAT solver (cadical); 64-bit expressions with many multiplications or divisions can be slow. If so, shrink the width to 8/16 bits and check first whether a counterexample exists (the structure of a bug often doesn't depend on width).

  • "potentially spurious counterexample" from bv_decide means the counterexample may not be real. It appears when the goal contains something the solver treats as opaque: an opaque / abstracted variable, an expression you abstracted away (e.g. a hash or call replaced by a free variable), or floating-point values. Treat it as a lead only: reproduce it in the real code (or model the abstracted part / add the precondition) before reporting a bug. Steps in references/bug-hunting.md.

Report format

Return results to the user in this form:

  1. What was verified, and the assumptions made while modeling
  2. Result: counterexample found (input values and how to reproduce in the original code) / proved (under which preconditions) / undecided (what blocked it)
  3. Next action (fix proposal, tests to add, whether to adopt the optimization)

Do not rephrase "proved" as "the original code is correct". The guarantee only extends to the model.

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة ما دامت المهارة محمّلة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Lean Verify؟

Use the Lean 4 theorem prover to find software bugs with counterexamples (integer overflow, bit manipulation, boundary conditions, spec/implementation mismatches) and to prove that an optimization or refactoring is equivalent to the original, so performance work can land safely. Also covers installing Lean and creating a minimal project. Use this skill proactively, even when Lean is not mentioned by name, when the user mentions Lean / lake / elan / formal verification / theorem proving / bv_decide / counterexample search / "is this optimization equivalent?" / "check that it holds for all in...

لماذا تستخدم Lean Verify على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Lean Verify عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Lean Verify في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/hirosassa/lean-verify/tree/main/skills/lean-verify. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Lean Verify؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Lean Verify؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Lean Verify معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Lean Verify مجانية؟

نعم. نشرها hirosassa على GitHub بموجب ترخيص MIT. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇