Repository navigation
Conversation
Adds `Lean.KernelVM.run`, a small imperative machine whose reference semantics is defined in Lean and which the kernel evaluates natively, plus native `Nat.getByte`/`Nat.getUInt64`. 🤖 Built with Claude Code
…experiment Adds partial-correctness rules for `Lean.KernelVM` programs with a verified trial-division example, and an experimental `grind.lia.vm` option that checks the linear steps of a `lia` refutation in one run of a cutting-planes checker. Its soundness theorem `unsat_of_linCheck` is still an axiom. 🤖 Built with Claude Code Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds `Std.Tactic.BVDecide.LRAT.KernelVM.lratVMProg`, a flat-array LRAT checker (RUP and deletion steps) for `Lean.KernelVM`, with encoders for CNFs and proofs, and moves the notation for writing VM programs to `Lean.KernelVM.DSL`. The kernel VM now flattens chains of `seq`, evaluates register and constant operands inline, and copies inputs into byte buffers. 🤖 Built with Claude Code Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Lean.KernelVM.run` now takes the program as a numeral holding a flat register-machine bytecode, with fuel counting instructions, and its inputs are numerals or strings. The structured language becomes an untrusted source language with a compiler (`Lean.KernelVM.Stmt.compile`), and the library programs are stored as compiled literals. Adds `ByteArray.toNatLE`, implemented natively, for encoding inputs. Removes the Hoare rules for the previous semantics. 🤖 Built with Claude Code Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds `Std.Tactic.BVDecide.KernelVM.bvVMProg`, which bitblasts a `BVLogicalExpr` into an AIG with structural hashing, emits the Tseitin encoding of the cone of influence of its output, and checks an LRAT proof against it. In mode 1 it stops after building the CNF, which the new `Lean.KernelVM.runMem` can read at elaboration time. The LRAT checker now skips satisfied hints. 🤖 Built with Claude Code Co-Authored-By: Claude Opus 5.5 <[email protected]>
The kernel VM bitblaster now builds the same AIG as `BVLogicalExpr.bitblast` and the same CNF as `Std.Sat.AIG.toCNF`, so the SAT solver sees exactly the problem it sees with `bv_decide` today. The circuits follow the `blast*` functions, and the CNF is produced by the same depth-first traversal with if-then-else detection. The test compares both on random expressions. 🤖 Built with Claude Code Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds `BinOp.umulh`, the high 64 bits of the 128-bit product of two words, so that bytecode can implement multi-word arithmetic with four multiplications per limb product instead of sixteen. 🤖 Built with Claude Code Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/runtime/mpz.cpp # src/runtime/mpz.h
Collaborator
Author
|
(This was an experiment to see what’s possible, but will likely not go forward in this form, so just storing it here.) |
`List.foldr` is only computable after `Init.Data.List.Impl`, which this module precedes. 🤖 Built with Claude Code Co-Authored-By: Claude Opus 5.5 <[email protected]>
4 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds an experimental small register machine to the kernel,
Lean.KernelVM.run, which the kernel evaluates natively, and uses it to checkbv_decidecertificates (bitblasting, CNF conversion and LRAT checking) inside the kernel. This is a parking spot for the prototype; it is not meant to be merged as is.The VM.
Lean.KernelVM.run (p : Nat) (inputs : List Input) (fuel : Nat) : Boolis an ordinary Lean definition giving the reference semantics. The kernel evaluates it natively (src/kernel/kernel_vm.cpp) when the program and fuel are numerals and the inputs are numeral or string literals; a checker without the native implementation can still unfold it, so there is no new axiom.Natliteral: 64-bit words, 65536 registers, a word-addressed memory that grows on demand. Instructions are constants, binary operations with register or immediate operands (wrapping arithmetic, the high word of an unsigned product, bitwise operations, comparisons, and signed arithmetic that fails on overflow), loads and stores, input byte/size reads, jumps andassert. Fuel counts executed instructions.Exp/StmtinInit/KernelVM/Asm.lean) compiles to bytecode. The compiler is untrusted: library programs are stored as bytecode literals, andtests/elab/kernelVMPrograms.leanchecks that they match their compiled source.Lean.KernelVM.runMemruns the same C++ interpreter at elaboration time and returns the final memory.Nat.getByteandNat.getUInt64natively, andByteArray.toNatLE(backed bympz_import) makes encoding inputs cheap.tests/elab/kernelVM.lean).Programs in this PR.
Std.Tactic.BVDecide.LRAT.KernelVM.lratVMProg: a flat-array LRAT checker (RUP and deletion steps).Std.Tactic.BVDecide.KernelVM.bvVMProg: bitblasts aBVLogicalExpr, converts it to CNF and checks an LRAT proof. It builds exactly the AIG ofBVLogicalExpr.bitblastand the CNF ofStd.Sat.AIG.toCNF;tests/elab/kernelVMBitblast.leanchecks this on random expressions, along with evaluation againstBVLogicalExpr.eval.Int.Internal.Linear.linCheckProgand the optiongrind.lia.vm: an experiment that checks the linear steps ofliarefutations in one VM run. It was slower than the current kernel-reducible certificates, because those steps are cheap and linking the inputs to the goal dominates. Its soundness theorem is an axiom.Measurements on the
bv_decidebenchmarks (medians of 7 runs; SAT solving excluded and identical, since the CNF is identical):bv_decide_mulbv_decide_realworld#2bv_decide_inequality#7bv_decide_modThe difference comes from not parsing the text certificate (about 25% of today's time). On the LRAT check alone, the interpreted flat-array checker and the compiled verified checker are at parity.
Measurements on zeta. zeta verifies zeros of the Riemann zeta function in two layers. Its "Kernel" layer writes explicit interval-arithmetic proof terms, which grow like √t per zero; at height 10⁸ these took 3,545 CPU-ms per zero, against 58 CPU-ms for the "Native" layer, a reflective checker run via
native_decide. The proofs are too large to keep, so independent re-checking is impractical. A kernel VM could run a native-style checker inside the kernel instead, with proofs about the size of the input data. To estimate the cost, the dominant part, the Riemann–Siegel main-sum loop, was written as VM bytecode with 128-bit fixed-point arithmetic (zeta uses the gridQ = 2⁶⁶). The run asserts that it reproduces the result of zeta's compiled Lean code (Fx) exactly, on identical inputs:Fxcode)umulhumulhThese are best-of-5 for the VM and best-of-20 for compiled Lean. The benchmark covers the composite-
nphases and the sums; the prime phases (Taylor series) and per-endpoint constant work are left out on both sides. A full port would plausibly cost 65–110 CPU-ms per zero at 10⁸ in the kernel, compared with 3,545 CPU-ms for zeta's kernel layer today. Withoutumulh, the high word of a 64×64 product has to be emulated with 32-bit pieces. The benchmark code is not part of this PR.Not done.
bv_decidedoes not yet produce proofs through the VM: that needs a kernel-reduced check that the encoded expression matches the reflected term, and a soundness statement forbvVMProg. The bitblaster bytecode is large (about 200 KB) because gate operations are expanded inline; a call instruction would shrink it.🤖 Generated with Claude Code