Where the ideas come from
The languages, theorem provers, and computer science papers that shaped Lema, how Lema compares with Lean, Unison, and Bend 2, and the roots of the program core.
Like mathematics itself, programming language design moves forward by combining ideas tested across decades of systems and logic research. Lema brings together ideas from interactive theorem provers, content-addressed languages, AI-native specification workflows, and classic papers on concurrency and program verification, pairing them with a semantic store, a deterministic proof assistant, a register VM, and an in-language storage and HTTPS stack.
Three modern language influences
Lean and Mathlib
Lean (building on Coq/Rocq, Agda, and Idris) separates a rich elaboration and tactic engine from a small kernel that checks completed proof terms. Through Mathlib, the Lean community showed that formal proofs can scale to hundreds of thousands of theorems when new results build on statements proved earlier.
- What Lema adopts: Lema uses the pinned Lean 4.34.1 kernel (
addDeclCoreat--trust=0) as its mechanical proof arbiter, supports Lean syntax for implementations and proofs, and builds libraries cumulatively by composing earlier laws. - Where Lema differs: Standard Lean projects live in text files where editing an internal proof triggers downstream file rebuilds, and native binaries compile through C (
leanc). Lema stores declarations by content hash, splitsstatement,template, andproofidentities, replays canonical objects with zero source text (How the store accepts code), and compiles accepted closures directly to bytecode on its Rust register VM (Decision 0052).
Unison
Unison pioneered storing functions and types in a database by the cryptographic hash of their syntax tree rather than in mutable text files, keeping human-readable names as separate metadata aliases so renames never break callers, and modeling external interaction through typed algebraic abilities and handlers.
- What Lema adopts: Content-addressed definitions, immutable store objects, project bindings kept outside object identity, syntax treated as a view over stored code (Code stored by identity), and tracking external effects explicitly through command signatures and handlers rather than ambient I/O.
- Where Lema differs: Because Unison does not carry formal proofs, hashing each definition as a single tree is enough there. In Lema, hashing a theorem and its proof together would cause proof refactors to churn downstream hashes. Splitting
statement,template(with proof holes cut out), andproofinto separate SHA-256 objects lets proofs change freely without invalidating callers or VM caches, and powers 7-category Semantic version control.
Bend 2
Bend 2 (by Victor Taelin and HigherOrderCO) explored an explicitly AI-native workflow: pairing human-readable law files (LAWS.bend) with agent-written code and proofs (PROOF.bend) in a Python-flavored functional language targeting C and GPU kernels.
- What Lema adopts: The core division of labor between humans and AI agents: humans read, write, and review compact specifications, while automated tools and coding agents handle implementation code and formal proofs.
- Where Lema differs: Bend 2 focuses on implicit data-parallel GPU compute (“feels like Python, scales like CUDA”), whereas Lema focuses on composable specifications, proof-optional shipping, and stateful networked systems (storage crash recovery, cryptography, TLS 1.3, HTTP/1.1, S3, and concurrent actors).
How Lema compares to Bend 2 in detail
| Dimension | Bend 2 (BendTT & BendRT) | Lema |
|---|---|---|
| Primary workload | Data-parallel compute kernels compiled to C, CUDA, and Metal. | Stateful services, protocols, cryptography, and crash-safe storage on the Lema register VM. |
| Who writes routine proofs | Single-pass checker with no tactic search; the AI agent writes out every proof step explicitly in PROOF.bend. | Two-stage split: Lema’s deterministic Rust proof synthesizer automatically discharges routine bounded case splits, linear arithmetic, and congruence with zero LLM calls, reserving agents for inductive invariants and simulations. |
| Proof gate & workflow | File-level all-or-nothing check (bend --verdict). | Proof-optional selections (open, checked, waived): code builds and runs on the VM on day one while laws are proved incrementally. |
| Identity & version control | Source files tracked with line-based Git diffs. | Sub-declaration statement/template/proof hashes, isolated multi-agent store workspaces, and 7-category semantic lema diff. |
| Trust boundary | Trusts the BendTT source checker, BendRT codegen, and C/CUDA compilers. | Discards source text before Lean 4.34.1 kernel replay, audits axioms against a fixed floor, and pushes the host boundary down to 6 flat-byte OS capabilities. |
-
Stage 1 · Human surface
Concise contracts in Pythonic syntax
Engineers state interfaces, laws, preconditions, and contract selections on a single readable screen.
-
Stage 2 · Deterministic prover
Zero-LLM discharge of routine laws
Lema automatically proves bounded non-recursive case splits, conditionals, arithmetic, and multi-law contract packaging.
-
Stage 3 · Coding agents
Creative invariants & simulations
Agents focus their tokens on recursive loop invariants, crash-recovery state machines, and Replaces simulation relations.
-
Stage 4 · Kernel arbiter
Source-free Lean 4.34.1 replay
Neither the deterministic synthesizer nor the agent is trusted; the kernel replays exported canonical objects from scratch.
Foundational computer science roots
Beneath those modern influences sit several classic results in logic and programming language semantics:
- The LCF kernel firewall (Milner, 1972): Edinburgh LCF showed that untrusted proof automation can use arbitrary heuristics safely so long as every theorem passes through a tiny, uncompromising kernel. Lema enforces that boundary across isolated OS processes (How the store accepts code).
- Dependent types and proof erasure (Martin-Löf, 1972; Coquand & Huet, 1988): Representing propositions as types allows universal theorems (
twice_id,sound,commit_all_or_nothing) to compose like ordinary functions while erasing everyPropterm before runtime execution (Types and invariants). - Persistent object stores and Merkle DAGs (Smalltalk-80; Merkle, 1987): Treating immutable hash-addressed expression DAGs rather than text files as the unit of storage lets one SHA-256 hash pin an entire semantic dependency closure.
- Pure effects and verified systems stacks (Haskell, Koka, F* / Project Everest, Fiat-Crypto): Separating pure code from monadic or algebraic effects (Haskell, Eff, Koka, Unison) and proving cryptography, TLS, and crash-safe storage inside a theorem prover rather than across C FFI shims (Project Everest / EverCrypt / miTLS, Fiat-Crypto, FSCQ) directly shaped Lema’s six-tag capability boundary and proved HTTPS stack.
Roots of the Prog and Contract core
The five building blocks in Anatomy of a Lema program and Evolving programs, handles and concurrency bring five lines of semantics research together into one small library:
| Lema building block | Classic concept | Seminal papers and how Lema applies them |
|---|---|---|
Command vocabulary (C, R) | Command-response containers | Hancock & Setzer (2000) and Abbott, Altenkirch & Ghani (2005). Models external interaction as a command c : C chosen by the caller and a command-dependent reply r : R c returned by the environment. |
Prog, bind, interp | Algebraic effects & Interaction Trees | Plotkin & Pretnar (2009) and Xia et al. (POPL 2020). Separates pure command trees (Prog) from step-by-step translation (interp) and execution (run), kept finite so proofs go by straightforward induction. |
Contract and Safe | Extrinsic weakest preconditions | Dijkstra (1975) and Maillard et al. (ICFP 2019). Keeps safety proofs (Safe) outside the Prog data structure rather than baking state indices into program types, so proving a new contract never changes a program’s hash. |
Impl, Implements, Replaces, Refines | Data refinement & forward simulation | Milner (1971) and Hoare (1972). Connects private concrete memory M to simple conceptual state S via an invariant or simulation relation so engines and contracts upgrade without breaking callers. |
Handles, Tickets, Sessions, Actor | Typestate, session types & linearizability | Strom & Yemini (1986), Honda (1993), and Herlihy & Wing (1990). Expresses single-owner handles, in-flight busy locks, dual session channels, and linearizable actor mailboxes directly as Contracts proved via Safe. |
Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility