Semantic version control
Git was designed for humans editing text files line by line. When an AI coding agent generates a 3,000-line pull request, git diff tells you which characters moved, but not what actually changed in meaning.
Lema includes its own store-native Semantic Version Control (SVC), independent of Git*. By versioning immutable declarations, contracts, and proof receipts directly in the store, routine updates can be accepted automatically while reviewers focus on what matters:
- Implementation or specification? Did the agent only rewrite implementation code and proofs, or did it change a contract or law?
- Safe replacement: If an implementation was swapped, is there a machine-checked proof that it satisfies the exact same contracts?
- Intact guarantees: Are all previously proved guarantees still intact, or was an obligation weakened or dropped?
Software you can trust in the age of AI.
AI agents can write code at unimaginable speeds but can you trust it?
Lema (pronounced Lemma) is a new* programming language focusing on building software you can trust in this new economy.
The idea is that humans keep control, writing high-level contracts and laws and agents write implementations and, where necessary, proofs.
The guarantees are designed to be composable so we can efficiently build up large robust structures, similarly to how mathematicians have done for millennia.
Composable guarantees
Mathematicians build vast structures that can keep growing indefinitely - they can do this because they prove what they have done is correct, then build on it without re-verifying everything from scratch. Lemmas compose into larger theorems, combining to form vast, elegant theories.
Software usually doesn’t accumulate this way because it’s written in languages that aren’t quite powerful enough* to express the guarantees we need, living in mutable source files and tested by checking cases. Traditionally when you refactor a parser, swap a storage engine, or optimise a cryptographic routine, downstream callers can break in subtle ways because nothing in the language recorded which exact behavioral laws the rest of the system depended on.
Lema’s aim is to enable software developers to accumulate software as mathematicians do mathematics.
Humans maintain control
Humans are responsible for writing high-level contracts, laws and interfaces which can be implemented and optionally proved by agents.
For example, if writing a sorting function we might just state what a sorting function must guarantee: the output is ordered, and that it’s a permutation, i.e. it just reorders the values without adding or removing any.
law sort_ordered(xs: List(Nat)):
Pairwise(fn(a: Nat, b: Nat) -> a <= b,
sort(xs))
law sort_preserves(xs: List(Nat)):
Perm(sort(xs), xs)Agents do the heavy lifting
Once humans have written the high level contracts, laws and interfaces, the intention is that agents write the implementations and optionally proofs. Humans usually don’t need to read these implementations or proofs, which are currently written in Lean. Agents are experts at writing Lean and, in fact thrive on the mathematically structured Lean language.
For example, an agent implements a sorting function and proves it obeys the ‘sorting laws’, then Lema checks correctness of the proof with the Lean proof checker.
def sort (xs : List Nat) : List Nat :=
sortBy (fun a b => decide (a ≤ b)) xs
theorem sort_preserves (xs : List Nat) :
(sort xs).Perm xs :=
sortBy_perm (fun a b => decide (a ≤ b)) xs- Agent submits
- Lean checks
- Store accepts
From low level to high
Build up low level primitives working with bits and bytes or write high level business rules. The same principles and composable guarantees apply.
Low-level cryptography
Prove byte-level and 32-bit word laws for standard primitives like RFC 8439 ChaCha20-Poly1305 authenticated encryption.
High-level business rules
Build on checked libraries in the same Pythonic syntax. An escrow contract keeps every unit accounted for across state transitions.
law aead_roundtrip_checked(key: ByteArray, nonce: ByteArray,
aad: ByteArray, pt: ByteArray, ct: ByteArray):
requires sealChecked(key, nonce, aad, pt) == some(ct)
ensures openChecked(key, nonce, aad, ct) == some(pt) law conservation(a: Nat, b: Nat, s: State):
requires Reachable(a, b, s)
ensures s.a + s.b + escrow(s) == a + b Codebase API
Lema is a ‘content addressed’ language, which means that the fundamental source of truth for the language is an abstract syntax tree of hashes. This may make you feel rather uncomfortable, but it unlocks many advantages and new ways of working that are perfect for agentic workflows including:
- Pluggable syntax for the human-focused contract layer currently Pythonic and Lean
- Interaction with the codebase is via a first-class API - perfect for agents
- Semantic code-graph is built in including granular search, neighbourhood expansion and surgical updates, resulting in unparalleled token efficiency.
Granular search
Find a match, then request its definition.
lema search sortBy --limit 1 lema context "$SORT_ID" --limit 4 Neighbourhood discovery
Expand the selected object into nearby dependencies and proofs.
lema neighborhood "$SORT_ID" --direction both --depth 3 --limit 24 Surgical update
Replace the fold with recursion. Keep the contract; update its proofs.
lema call publish --params-file sort-update.json Definition · Pythonic view
def sortBy[α](le: α -> α -> Bool,
l: List(α)) -> List(α):
List.foldr(insertBy(le), [], l) sortByLean · function bodyl.foldr (insertBy le) []match l with
| [] => []
| x :: xs =>
insertBy le x (sortBy le xs)Four concurrency pillars
Four concurrency models, each with laws you can prove. Compose local guarantees through explicit ownership and protocol rules.
Structured parallelism
Split work across disjoint resources. Prove each task safe, then compose their guarantees.
State-owning actors
Each actor owns its state. Prove one step preserves its rules across every message order in the model.
Session-typed channels
Make the conversation a contract. Prove that each send and receive follows a matching protocol.
Commutative concurrency
Prove independent operations can change order with the same replies and final state. Automatic batching is planned.
Pluggable backends
Lema separates proof checking from program execution. Once declarations are verified and accepted into the store, Lema erases all proof terms and lowers the executable code into a small, content-addressed intermediate representation that different execution backends can plug into.
Today Lema ships with a bundled VM backend designed for rapid development, with a native binary backend on the way for maximum throughput. Over time, custom backends can even be tailored to the specific latency, footprint, or deployment requirements of your application.
Bundled VM backend
- Instant, cached rebuilds
- Compiled units are cached by content hash. When a function changes, only that unit is lowered and runs immediately without invoking Lean, a C compiler, or a linker.
- No tracing garbage collector
- Memory is managed by deterministic reference counting with no GC pause spikes. Uniquely owned buffers update in place; shared buffers copy on write.
- Cross-platform foundation
- A register-based bytecode engine and narrow host interface decouple your application logic from the underlying OS and hardware.
Pluggable syntax
Lema is a content-addressed language. Instead of storing code as lines of text in source files, Lema stores the underlying abstract syntax tree and identifies every function, definition, contract, and law by the hash of what it means.
A nice benefit of this is that the contracts, laws, and interfaces layer that humans interact with can be rendered in multiple notations over the exact same codebase:
- Pythonic: Similar to Python, with first-class types and extras for expressing contracts and laws clearly and concisely.
- Lean: Direct mathematical notation matching the underlying proof kernel.
- Future syntaxes: C-like, TypeScript-style, and other notations could be added so developers get the power of Lema in a familiar syntax.
Ecosystem
Storage, cryptography, TLS, HTTP and S3 are built in Lema above six host capabilities. Their contracts and proofs support real applications, from an object server to an escrow ledger.
Get started
Paste this into your coding agent. It installs the prebuilt CLI and VM, completes setup, then runs and changes the echo starter. Rust is not required.
Lema 0.3.2 includes a prebuilt CLI and VM for Linux x86_64 and Apple Silicon macOS.
The prompt asks your agent to:
- Check your machine type.
- Install missing prerequisites, such as OpenSSL and curl.
- Install the CLI and VM, then run
lema setupfor the checker and library pack. - Create an app with
lema new echoand start it withlema run echo. - Test the HTTPS response with
curl.