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.
In this repository43 other files it gives its agents.
- AGENTS.mdAGENTS.md
- counterexample-first-provingSkill
- hol-metamath-adapterSkill
- isabelle-isar-adapterSkill
- itp-cross-portingSkill
- lean-ai-formalizationSkill
- lean-asymptotic-algorithmsSkill
- lean-bisectSkill
- lean-blueprintSkill
- lean-buildSkill
- lean-computational-reflectionSkill
- lean-core-onlySkill
- lean-corpus-auditSkill
- lean-dependency-managementSkill
- lean-doc-syncSkill
- lean-egraph-cpsat-superoptSkill
- lean-gatewaySkill
- lean-knowledge-formalizationSkill
- lean-math-analysisSkill
- lean-math-discreteSkill
- lean-math-dynamicalSkill
- lean-math-foundationsSkill
- lean-math-optimizationSkill
- lean-math-stochasticSkill
- lean-mweSkill
- lean-pedagogical-expositionSkill
- lean-proof-refactorSkill
- lean-proof-repairSkill
- lean-proof-reviewSkill
- lean-proofSkill
- lean-researchSkill
- lean-retro-methodologySkill
- lean-review-councilSkill
- lean-security-formalizationSkill
- lean-setupSkill
- lean-specificationSkill
- lean-tautology-triageSkill
- lean-unboxed-limbs-swarSkill
- lean-upstream-prSkill
- lean-verification-gateSkill
- lean-worker-wrapper-cpsSkill
- research-councilSkill
- rocq-proof-adapterSkill
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
- Very specific: line 31
Keep Prop specs abstract (<= 1% cost via rfl), while keeping hot defs and hardware targets (PolyBitOp MLIR/PTX/AVX2/C++20) monomorphic and …
- Very specific: line 53
Never keep grind, native_decide, unsafe, @[implemented_by], or @[extern] on scored paths.
≈ “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.
Files
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,twinlitPMU runs, andchecked-small -> NeedsWidelowering. - DO NOT USE FOR: general proving (
@lean-proof),Proprefactoring (@lean-proof-refactor), or contest-band cutoffs / lookup tables (-29,-30).
Workflow
- Static Audit -- Run
lean_diagnosticsandlean_metrics(action: "altproof") forbrecOn(-06),ite(-08), pow2//%(-14), typeclasses (-23), lookup tables (-30), and Section 1/2/3 splits (-31). - Section-1/2/3 Split -- Put
abbrevspecs in Sec. 1, zero-Propdefs + rawnat_lits in Sec. 2 (-25B), andrfl/@[csimp]bridges in Sec. 3 (WAVE-13 G1). - WHNF & GMP Scaling -- Pair
Nat.succ/Nat.add 1(ADR-INV-0025),Nat.mul x xon< 2^63scalars vs wideNat.pow x 2(0.58xmpn_sqr, >=30 limbs) +O(L)single-limb scaling, refute huge Kronecker packing (-29B), cap branching step lambdas<= 30nodes (-28), and emitchecked-small -> NeedsWideC++20/PTX. - 3-Axiom
no-grindGate -- Keepgrind/eqsat off submission paths; close withkernel_decide(rfl | decide +kernel | omega), setprofile = "kernel", and verifyreal - twinlit(instructions:u).
Recovery & STOP
- Revert
let-sharing (-01B), Kronecker blowup, or unrolling regressing full-pipelinereal - 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
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
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.

