Lean 4 Kernel WHNF, SWAR & Proof-Carrying Codegen (SAIR-LAW-01..25B)
Enforce the concrete half of Abstraction-Concrete Duality (WAVE-13 G1): keep Prop specs abstract (<= 1% cost via rfl bridges), while making hot def
kernels and hardware targets (PolyBitOp MLIR / CUDA sm_89 / AVX2 / C++20) monomorphic and unboxed (avoiding the 1,600x..3,345x parametric hot penalty).
Routing
- USE FOR: speeding up
whnf/is_def_eq, explicitNat.rec/Bool.rec/condlowering,@[csimp]twins, SWAR packing (width-2 + 1-bit), ZDD bitboards, sum-of-medians-of-threetwinlitPMU profiling, and proof-carrying SWAR/SIMD/SIMT/C++20 codegen (checked-small -> NeedsWide). - DO NOT USE FOR: general theorem proving (
@lean-proof) or splitting longPropproofs (@lean-proof-refactor).
Workflow
- Static Audit -- Run
lean_diagnosticsandlean_metrics(action: "altproof") to detectbrecOn(SAIR-LAW-06),ite(SAIR-LAW-08), power-of-two/or%(SAIR-LAW-14), typeclass dictionaries (SAIR-LAW-23), andProp/Finin hot cones (SAIR-LAW-22). WAVE-13 G1Section-1/2/3 Split -- Put readableabbrevformulas in Section 1, specialize hotdefs in Section 2 to primitiveNat.*ops + rawnat_litconstants (SAIR-LAW-25B), and bridge to abstract theorems in Section 3 viarfl(@[csimp]for LCNF).- WHNF, SWAR & Lowering Laws -- Use
Nat.succforNat.recstep accumulators vsNat.add 1for counters, share multi-limb squares only above ~30 limbs (SAIR-LAW-13), useNat.land w (Nat.shiftRight w s)orw &&& (w - 1)onNat(SAIR-LAW-18B), and enforcechecked-small -> NeedsWide+ operand snapshotting in C++20/PTX (Template_ProofCarryingCodegen.md). - 3-Axiom & PMU Gate -- Close checks with
sair_decide(first | rfl | decide +kernel | omega), nevernative_decide, and verify netreal - twinlitgain via sum-of-per-slot-medians-of-three (perf stat -e instructions:u).
Recovery & STOP
- Revert any
let-sharing (SAIR-LAW-01B) or unrolling rewrite that regresses full-pipelinereal - twinlitinstructions. - Never alter public theorem signatures or introduce
unsafe/@[implemented_by]/@[extern]escapes on kernel-scored paths.
Handoffs
- Predecessors:
lean-proof,lean-proof-refactor. - Successors:
lean-proof-review,lean-verification-gate.
Detailed reference
- Fast lookup card:
../../references/cards/lean-sair-kernel-optimization-tables.md - Full handbook:
../../references/handbooks/lean-sair-kernel-optimization-handbook.md - Templates:
../../templates/core/Template_KernelWHNF_SAIR.md,../../templates/core/Template_ProofCarryingCodegen.md
