Basalt is a foundational representation of random data generators for property-based testing (PBT), together with machine-checked proofs about them, in Lean 4. A single generator term is given a precise semantics you can both run and reason about, so a generator can be proved sound, complete, almost-surely terminating, and cost-bounded.
This is research code. APIs are unstable and may change without notice.
A generator is a term polymorphic in its monad, not a value of a fixed generator type:
def myGen [Gen G] : G α := ...Gen bundles the operations a generator needs (Monad, RandomChoice, CCPO, MonoBind,
Inhabited). The same term is then interpreted at whichever monad the task calls for:
| Interpretation | What it gives you |
|---|---|
Plausible.Gen / IO |
run it and get values |
SPMF |
a sub-probability mass function — reason about the distribution and its support |
SPMF.Cost |
the same, plus a count of random choices |
GenStats.StatGen |
seeded, fuel-guarded execution that counts choices (drives #genstats) |
RandomChoice.choose is the only source of randomness; every combinator (pick, elements,
oneOf, frequency, listOf, …) is built on it. Recursive generators are defined by
partial_fixpoint over the CCPO.
Basalt/Laws.lean states the properties a generator may have as plain predicates; which apply
depends on the generator, and you prove the ones that do:
IsSoundAndComplete g P— the support ofgis exactlyP(nothing invalid, nothing missed).IsAlmostSurelyTerminating g—gterminates with probability 1.IsCostBounded g c— producingvtakes at mostc vrandom choices.IsFilterFree g/IsProductive g— for filtering (Option-valued) generators.
BasaltExamples/ is a cookbook of worked generators, each carrying proofs of the properties that
apply to it. WORKFLOW.md walks through writing a generator and proving it correct, with a recipe
for each obligation.
Lean and Mathlib are pinned in lean-toolchain / lakefile.toml / lake-manifest.json.
lake build # library + examples + tests
lake build Basalt # library only
lake build BasaltExamples # the cookbook
lake build BasaltTest # regression testsBasalt/— the library.BasaltExamples/— worked generators with correctness proofs. Because each file proves its generator's laws, this directory is also most of the effective regression suite for the library's lemma sets and tactics.BasaltTest/— regression tests, named for the library module they guard when one exists;LawLine.leanhas no library counterpart (it pins the#genstatslaw-reporting contract).BasaltExperiments/— spikes; the only place withsorrys, and not built by default.
Released under the MIT license; see LICENSE.
If you are interested in this work, please get in touch with Harry Goldstein.