Skip to content
Desktop wallpaper
SPONSORED BYPud.dev

A wiki, knowledge base, and microblog... Of sorts...

Hold and drag to move Pud. Arrow keys move, Space curls, and Home returns Pud to the globe.
Widgets

Configured proof assistant adapters

By

Updated

The starting point was a Lean demo whose schema names, sidecar parser, and proof runner all belonged to the same assistant. The configured API uses Pud schemas and passes their premises and result constraints to a ProofAssistant. Its prepare method receives the named export's source snapshot and returns the signature, emitter, and verifier. The adapter still owns the semantics of the TypeScript constructs it admits. Adapter contract

The pud.dev package provides the command and suite API. Lean is its first bundled adapter. The CLI selects the closest pud.config.ts for each sidecar, so future adapters can use the same command and portable declarations. An installed-package regression sends a portable suite through a second configured adapter and checks that its concrete witness produces FAIL. Package and API

Project config is selected relative to each sidecar. Native suites import the config as pud and use that binding for both pud.describe() and schema builders such as pud.bigint() and pud.boolean(). The primitive names follow TypeScript and Zod. The configured binding gives both the schemas and proof helpers the type of the chosen assistant. Pud reads the sidecar statically and checks the same assistant marker when a library call supplies an explicit adapter. The configured import and native tagged template follow Drizzle's driver and query patterns. Zod schemas · Drizzle setup · Drizzle tagged templates

The Lean adapter checks the theorem type against the currently emitted claim and audits its dependencies. The migrated examples certified 23 active properties and reported one TODO. A temporary change from + 1n to + 2n caused the original increment proof to fail. A term using sorry failed the axiom audit. An independent test adapter received the portable claim from a suite, and Pud rejected that suite's Lean predicate and named certificate for the alternate adapter. The installed package typecheck caught the native type mismatch too.

Reloading an imported config option

On Bun 1.4.2 and Lean 4.19.0, a fixture’s pud.config.ts imported replay from ./options.ts and passed it to leanAdapter({ replay }). The function returned n - 1n and its property required n. The original loader cached the adapter using the text of pud.config.ts, so editing the imported option left a long-lived caller using the old setting. Original loader

With a fresh Bun process per configured run, the first check() returned unproved. After enabling replay in options.ts, the second call from the same caller returned disproved with input 0n and result -1n. The CLI found the same witness. Two suites in one checkFiles batch share the config instance. Concurrent calls get independent instances. Config lifetime regression · Reading a proof result

Refinements and quantifiers

The demo had 22 inline Lean templates across 15 sidecars, with 13 predicates and nine certificates. Zod-style .refine() now accepts predicates over result and input values, and the adapter contract represents quantifiers and connectives directly. Lean lowers a universal domain constraint to an implication and an existential one to a conjunction. An array domain uses list membership. The generated claim and the standalone axiom check use the same proposition. Zod refinements · Lean quantifiers

On Lean 4.19.0, the revised examples certify 23 properties and report one TODO with zero inline templates. Eleven predicates moved to Pud and two became named Lean definitions. Definitional equality, simplification after case splits, and standard division and remainder lemmas replace eight inline proofs. The fold proof remains available as a named induction lemma. Changing the membership implementation from equality to inequality caused the named theorem to fail at the generated claim type. Demo sources

Calls, exceptions, and termination

The original Lean model

Pud initially bound a sidecar to one named TypeScript export and translated its body to a Lean function. The claim applied that generated function to every input admitted by the sidecar. For example, the array sum translates bigint to Int and the accumulator loop to List.foldl over a finite List Int. Its generated claim reduces to ∀ values : List Int, impl values = values.sum. The standalone Lean audit checks the certificate at that claim type and checks its axiom dependencies. Pud rechecks the input snapshots before reporting the verdict. Subject lowering · Lean checker · Snapshot checks

At that stage, same-file calls, imported calls, recursion, throw, and while were unsupported, and bigint division accepted only positive literal divisors. The Bun probes returned -2n for -5n / 2n and threw RangeError for 1n / 0n. The lowering needed to preserve both outcomes. TypeScript coverage and runtime probes · Bigint division in ECMAScript

What LemmaScript models

LemmaScript generates Lean and Velvet 2 implementations from TypeScript and its inline contracts. Its conditionalCalls example generates the callee and caller, with a call's precondition checked on the branch that invokes it. Its binary search uses Velvet's total-correctness mode, with loop invariants and the decreasing measure (hi - lo + 1).toNat. Pure recursive definitions use Lean's termination checking. Conditional call model · Binary search model · Lean backend specification

For cross-file calls, the frontend resolves the symbol and scans for further externs. The Lean backend emits an opaque function and, when there is a contract, an axiom for that contract. A caller proof then depends on the callee satisfying the declared contract. The compiler translates throw to an assertion of false, so the proof must establish that the throw is unreachable under the method's preconditions. The exception payload is outside that model. Extern discovery · Lean extern emitter · Throw lowering

What Lynx models

Lynx recovers Core Erlang from compiled BEAM debug information and follows supported reachable callees, including calls across modules. Core Erlang extraction · Call translation

Pure computations produce an Except outcome. The exception model includes handlers, with a distinct exhaustion outcome that handlers propagate. In the generated sum example, the law must evaluate to Except.ok Lynx.Term.true. A throw or an exhausted computation cannot satisfy that goal. Lynx supports termination arguments and partial fixpoints for recursive functions. Exception model · Generated law · Lynx features

What Pud implements

  1. Link direct calls. Pud follows same-file calls and relative named imports from modules with inert initialization. The ZigZag sidecar proves decode(encode(x)) === x against both generated bodies. Changing either body made the same proof fail. A separate test edits a transitive dependency or changes its import resolution during a check and verifies that Pud invalidates the verdict. ZigZag sidecar
  2. Represent observable throws. Bigint division and remainder use Except when the divisor can be zero. Calls preserve the order of throws, and a restricted try/catch can recover from one. A return property requires .ok and an exception property requires the specified error class. The division example proves the signed return and zero-divisor throw over all numerators. Division sidecar
  3. Check termination in Lean. The supported while form subtracts a positive literal and uses the distance to its lower bound as a measure. Pure direct recursion uses the first bigint parameter's .toNat. Lean checks the decrease for all inputs to the generated definition. The demo separately checks a base case and a positive result. Reversing the loop or recursion step prevents a pass. Termination examples · Lean recursion reference
  4. Compare with Bun. The regression suite compared 280 return or exception outcomes on Bun 1.4.2 and Lean 4.19.0. It exercises signed arithmetic and zero divisors, call ordering, short circuits, a catch, loops with multiple mutable locals, and recursion. The remaining general guarantee requires a correspondence proof against explicit JavaScript semantics for the admitted fragment. Conformance tests · Coverage measurements

The standalone sketch below shows the division model before its integration into the adapter. Here the zero-divisor tag represents the runtime's RangeError. The compiler generalizes the same return and throw distinction to expressions and call chains.

import Std

inductive DivisionError where
  | zeroDivisor

def divide (n d : Int) : Except DivisionError Int :=
  if d = 0 then .error .zeroDivisor else .ok (Int.tdiv n d)

example (n : Int) : divide n 0 = .error .zeroDivisor := by simp [divide]

example (n d : Int) (nonzero : d ≠ 0) :
    divide n d = .ok (Int.tdiv n d) := by simp [divide, nonzero]

example : divide (-5) 2 = .ok (-2) := by rfl

Road to semantic preservation

  1. Define observable outcomes for scalar source expressions. A typed Lean AST represents bigint and boolean operations, conditionals, local binding and assignment, ordered call arguments, throws, and catch recovery. Its evaluator specifies which subexpressions execute and where evaluation stops after a throw. Scalar source evaluator · ECMAScript logical operators
  2. Prove the primitive rewrites. The source quotient uses sign and magnitude, and its remainder is the difference after subtracting the divisor times that quotient. Lean proves these agree with Int.tdiv and Int.tmod on nonzero inputs and preserves the modeled throw at zero. A separate theorem equates selecting the low bits of a finite two's-complement word with the emitted modulo. Scalar primitive proofs · ECMAScript bigint operations
  3. Prove expression preservation. By induction on the source expression, its explicit evaluation rules agree with a target denotation using Lean's Except sequencing. This covers short-circuit branches, left-to-right operand evaluation, and recovery after a modeled throw. Preservation theorem
  4. Check the actual emitted functions. Pud reifies the frozen AST independently of the ordinary Lean printer. The generated unit checks each eligible function against that reification and uses the certificates for callees when checking a linked call. The ZigZag roundtrip includes a certificate for the composed observation. Source reifier · Lean emitter and audit
  5. Transfer and audit the sidecar property. The generated sourceChecked theorem rewrites the proved property over the modeled source evaluation. A fresh Lean module checks the types and axiom dependencies of both the lowering and source-property certificates. A regression changes only the emitted zero-divisor exception. Lean still accepts the ordinary nonzero property in isolation and rejects the lowering certificate. Certificate regression
  6. Prove the loop helpers. The emitted countdown helper agrees with a deterministic execution relation for guard failure, another iteration, and an abrupt throw. The dense-array fold helper agrees with left-to-right iteration and a unique final accumulator. These theorems handle the helper semantics. The AST-to-loop mapping and lowering of a particular loop's body and state still need program-level certificates. Iteration proofs
  7. Check source observations against the runtime. The differential suite runs signed arithmetic, calls, short circuits, exceptions, and loops in Bun 1.4.2 and in the emitted model on 280 input and function pairs. It also evaluates the reified source model on the scalar cases. These checks give evidence about the model and the AST bridge. Differential tests

The demo has 19 active properties with a whole-observation scalar certificate, five with an audited iteration helper theorem, and eight with a model-level property proof. These are counts for the demo, with one additional TODO. General array control flow, the opaque string-or-array case, and the bodies of recursive functions still need preservation proofs. The next compiler obligation is to verify source reification, name resolution, and the mapping from source loop state to the iteration relation. A runtime guarantee also needs correspondence with the admitted JavaScript semantics, including assumptions about dense arrays and standard built-ins. Coverage measurements

Reuse proofs across equivalent refactors

sumPositive originally used total += value > 0n ? value : 0n. Pud emits List.foldl for that single assignment, which matches PositiveSum.nonnegative after reduction. The equivalent if (value > 0n) { total = total + value } emits a Lean for loop. The direct theorem reference previously yielded unproved for that form. Loop lowering · Fold theorem

In a temporary copy, Lean 4.19.0 certified the refactor using a proof that the guarded loop and the fold give equal totals for every list and initial accumulator. The proof uses induction on the list and splits the step on 0 < value. Rewriting with that equality lets the claim reuse PositiveSum.nonnegative. Changing the guard to value < 0n made the same certificate fail.

The reusable theorem now checks both forms with the same sidecar. For a pure for…of on a dense bigint array with a guarded update of one scalar local, Pud emits a conformance theorem alongside the ordinary loop. Lean checks that the loop body produces the fold's next state at every step. The iteration theorem lifts this equality to the result of the entire traversal. For additive updates, this lets if positive then total + value else total use the same fold step as total + (if positive then value else 0). Dense iteration proof

Named proofs can apply directly to the emitted claim or use the checked equalities to rewrite it. The audit checks the law and the conformance theorems. The regression checks the generated conformance theorem and the use of PositiveSum.nonnegative for a guarded for…of. It certifies the conditional operand, the conditional statement, and the guarded addition through an imported call. It rejects the reversed guard. The checked-in example now uses a counted loop and reports UNSUPPORTED. Refactor regression · Indexed traversal

The reusable proof depends on the fold specification. Each implementation supplies checked evidence of its behavior in the emitted model. The TypeScript-to-Lean loop translation still relies on the dense-array model and AST lowering. Loops with multiple updated locals, abrupt control flow, or potentially throwing steps use the general model without this fold rewrite. Any extension needs to preserve the outcomes its laws observe, including throws and termination.

Lynx recommends laws that compare a replacement to a reference implementation. Its sum proof also shows how a certificate can depend on the shape of generated code through the recursive function's induction theorem. An Erlang port of the accumulator rewrite produced distinct Core Erlang bodies on OTP 27, using the same BEAM debug information extraction as Lynx. This comparison covers the compiler input to Lynx's translator. Lynx sum proof · Core Erlang extraction

How close to the runtime

  • Pud starts at a frozen TypeScript AST and follows concrete source definitions for supported calls. It now validates the emitted scalar observation against a Lean model of source evaluation. Parsing, source reification, the host runtime's implementation of JavaScript semantics, and the remainder of the lowering remain trusted.
  • Lynx starts downstream of an Elixir or Erlang front end. It extracts Core Erlang from compiled BEAM debug information and models more of the runtime, including exception handling, effects, and concurrency. That is closer to the compiled program. Its own design describes the Core Erlang-to-Lean translation as a trust boundary. Lynx design · Core Erlang extraction
  • LemmaScript starts at TypeScript source and emits verification artifacts for Dafny or Lean with Velvet. It supports a broader set of imperative TypeScript constructs and contract-driven verification. Its Lean backend can model external calls using contracts and turn throws into unreachable-branch obligations. Its design identifies lowerings as trusted and uses source, generated output, and proof regressions to check correspondence. LemmaScript trust model · Lean backend

Benchmark for unchanged TypeScript

LemmaScript is the direct TypeScript comparison. It has published case studies in existing projects, including node-casbin. Its companion tools can replay differences between Dafny models and JavaScript and flag changes to frozen contracts. A Pud benchmark should therefore measure the entire workflow of checking a reviewed law through a refactor. Lynx is a reference for the assurance of the proof pipeline. It translates compiled Core Erlang and models exceptions and OTP interleavings. Its translation to Lean remains part of its trust boundary. LemmaScript case studies · Crosscheck · Seal · Lynx

Pin a small corpus from existing synchronous TypeScript domain modules. For each export, fix one reviewed law and its input domain. Check the baseline, a behavior-preserving edit, and a behavior-changing edit. Keep the executable source and law equivalent across tools. Record first admission blockers, time to a checked law, native proof edits after the refactor, and which broken edits yield reproducible runtime witnesses. A sampled execution earns a FAIL only when it actually violates the reviewed property. Keep compiler or model disagreements visible alongside the proof verdicts. Verdict meanings

The first implementation target is a law across two files with supported module initialization and a dense-array traversal. Add only the binding and value rules needed by the pinned cases. The counted sumPositive loop is a local regression target for bounded integer indices, array length, out-of-bounds reads, and truthiness. An exact positive-sum law would also reject a body that always returns zero. Extend the Lean translation certificate to the same admitted loop and check edge-case agreement in Bun. A pilot pull request can then show one unchanged law passing before and after an equivalent edit, plus a concrete witness from replay of a wrong edit. Admission baseline · Indexed traversal conditions

Availability tally refactor

Quorum's countFree and Lynx's list sum share an additivity law that makes independent batch counts composable. The Pud example checks one scheduling slot over two dense arrays of bigint masks. The low bit of each mask contributes zero or one. The sidecar compares the tally against a separate TypeScript reference, which also rules out a constant zero implementation. Quorum case study · Lynx sum law

Lean 4.19.0 certified the one-accumulator scan and the split refactor with the same sidecar and Lean lemmas. The refactor calls an imported batch tally and adds the right total before the left. With the right batch removed, Bun 1.4.2 produced 0n on left = [] and right = [1n], while the reference produced 1n. The configured CLI reported FAIL and exit 1. The regression also added a premise excluding that witness and checked that the claim stayed UNPROVED. Example and commands · CLI regression

Other adapters

A future assistant can implement ProofAssistant for the types and expressions it supports. The CLI uses the same reporting and snapshot validation for every adapter, while the adapter supplies its proof semantics and verdicts. The database experiment preserves its PostgreSQL replay and source lowering as groundwork for a Lean port. Debit transaction port plan · Checking TypeScript with Lean · Reading a proof result

#verification#typescript#lean#adapters#quantifiers#call-graphs#exceptions#termination#semantics#translation-validation#proof-reuse#lemmascript#lynx

Linked from

48 entries · 259 links

Melted

You melted the page.