agentleFS
r-irber-irbe/proof-skills/skills/lean-kernel-optimization/SKILL.md

lean-kernel-optimization

Skill3 starsChanged 13 days agoApache-2.0View on GitHub

USE FOR: Lean 4 kernel WHNF optimization, @[csimp] twins, BitVec/SWAR packing, ZDDs, and C++/SIMD codegen. DO NOT USE FOR: high-level Prop refactoring (@lean-proof-refactor) or basic proving (@lean-proof). TRIGGERS: kernel optimization, WHNF, csimp, SWAR, BitVec, ZDD, kernel_decide, instructions:u, lean-project.toml.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Keep Prop specs abstract (<= 1% cost via rfl), while keeping hot defs and hardware targets (PolyBitOp MLIR/PTX/AVX2/C++20) monomorphic and …

    line 31
  2. Very specific:

    Never keep grind, native_decide, unsafe, @[implemented_by], or @[extern] on scored paths.

    line 53

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Lean 4 Kernel WHNF, SWAR & Hardware Codegen (KERNEL-LAW-01..31)

Keep Prop specs abstract (<= 1% cost via rfl), while keeping hot defs and hardware targets (PolyBitOp MLIR/PTX/AVX2/C++20) monomorphic and unboxed (WAVE-13 G1, -31).

Routing

  • USE FOR: whnf/is_def_eq, @Nat.rec/Bool.rec/cond, @[csimp] twins, SWAR/ZDDs, twinlit PMU runs, and checked-small -> NeedsWide lowering.
  • DO NOT USE FOR: general proving (@lean-proof), Prop refactoring (@lean-proof-refactor), or contest-band cutoffs / lookup tables (-29, -30).

Workflow

  1. Static Audit -- Run lean_diagnostics and lean_metrics (action: "altproof") for brecOn (-06), ite (-08), pow2 //% (-14), typeclasses (-23), lookup tables (-30), and Section 1/2/3 splits (-31).
  2. Section-1/2/3 Split -- Put abbrev specs in Sec. 1, zero-Prop defs + raw nat_lits in Sec. 2 (-25B), and rfl/@[csimp] bridges in Sec. 3 (WAVE-13 G1).
  3. WHNF & GMP Scaling -- Pair Nat.succ/Nat.add 1 (ADR-INV-0025), Nat.mul x x on < 2^63 scalars vs wide Nat.pow x 2 (0.58x mpn_sqr, >=30 limbs) + O(L) single-limb scaling, refute huge Kronecker packing (-29B), cap branching step lambdas <= 30 nodes (-28), and emit checked-small -> NeedsWide C++20/PTX.
  4. 3-Axiom no-grind Gate -- Keep grind/eqsat off submission paths; close with kernel_decide (rfl | decide +kernel | omega), set profile = "kernel", and verify real - twinlit (instructions:u).

Recovery & STOP

  • Revert let-sharing (-01B), Kronecker blowup, or unrolling regressing full-pipeline real - twinlit.
  • Never keep grind, native_decide, unsafe, @[implemented_by], or @[extern] on scored paths.

Handoffs

  • Predecessors: lean-proof, lean-proof-refactor.
  • Successors: lean-proof-review, lean-verification-gate.

Detailed reference

  • Card: ../../references/cards/lean-kernel-optimization-tables.md
  • Handbook: ../../references/handbooks/lean-kernel-optimization-handbook.md
  • Templates: ../../templates/core/Template_KernelWHNF.md, ../../templates/core/Template_ProofCarryingCodegen.md

See also

  • ../lean-asymptotic-algorithms/SKILL.md
  • ../lean-computational-reflection/SKILL.md
  • ../lean-egraph-cpsat-superopt/SKILL.md
  • ../lean-unboxed-limbs-swar/SKILL.md
  • ../lean-worker-wrapper-cps/SKILL.md
  • ../lean-proof-refactor/SKILL.md
  • ../lean-core-only/SKILL.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.