Skip to main content

LeanCert

v1 overhaul licensing: Post-baseline Python SDK work is source-available under a provisional evaluation license. Personal evaluation, non-commercial research, education, and bounded commercial, governmental, or other organizational proofs of concept are permitted; production and commercial use require written terms. Python SDK versions through v0.3.2-apache-final, LeanCert Core, and LeanCert Bridge remain separately available under Apache-2.0. See LICENSE.

Formal verification for numerical Python code, powered by Lean4.

Write Python, get mathematical proofs. LeanCert proves properties about your code for all inputs, not just test samples.

Installation

pip install leancert

The wheel is pure Python. On the first checked operation, lean-runtime downloads the compatible Bridge ready-to-run program from the ghcr.io/alerad/leancert-bridge-programs program library. The program contains the precompiled Bridge and its runtime libraries, not a Mathlib source/build tree. Later calls reuse it; no Bridge path or system-wide Lean installation is needed.

Full LeanCert and Mathlib environments are hydrated lazily only for independent kernel replay, source rebuild audits, or custom registered-enclosure profiles. Those environments remain distinct from ready programs in result provenance: a program establishes compiled_checker, while successful exported proof replay establishes kernel_replay.

Set LEAN_RUNTIME_AVAILABILITY=required when CI must use a downloadable environment, or LEAN_RUNTIME_AVAILABILITY=local to audit the source-build path. An explicit LEAN_RUNTIME_LIBRARIES value replaces the SDK defaults, including an empty value to disable environment-library lookup.

The v1 overhaul also includes a bridge-independent, exact semantic model under leancert.ast. Its versioned encoding, binder rules, claim closure, and legacy conversion boundary are documented in Semantic AST v1. The typed line-protocol negotiation and checked-response invariants are documented in Python protocol model v2. The semantic claim front door is documented in Unified checked proving. Verified bounds from Bridge Contract 2.1+ can also be exported as independently rebuildable Lean evidence. Bridge Contract 2.3 extends the same workflow to unique nonlinear-system roots certified by exact rational Krawczyk certificates; NumPy and SciPy candidates remain untrusted inputs. Bridge Contract 2.4 adds exact reciprocal-power eventual bounds with supplied or automatically discovered natural-number cutoffs. Bridge Contract 2.5 adds fixed, replayable scalar-root checks for existence, uniqueness, and exclusion on exact rational intervals. Bridge Contract 2.6 adds exact polynomial integral equalities and replayable one-sided integral bounds with fixed checked partitions. Bridge Contract 2.7 adds replayable strict global bounds backed by an exact interior margin and the existing checked non-strict Golden Theorems. Bridge Contract 2.8 adds profile-bound downstream enclosure rules with immutable registry negotiation and candidate-free fixed replay.

Exported projects can be audited without rerunning Python or numerical search:

leancert verify exported_proofs/ --require-trust kernel

After installation, leancert doctor checks the managed environment, negotiated contract, replay support, adaptive checked route, and runtime-owned execution provenance.

Quick Start

import leancert as lc
from leancert import ast

# Define an exact semantic claim
x = ast.var("x")
claim = ast.sin(x) <= 1

# Check it for every x in the closed interval [0, 1]
result = lc.prove(claim, where={x: (0, 1)})
if isinstance(result, lc.Verified):
    print(f"Verified claim {result.claim_id}")
    print(result.provenance)
else:
    print(type(result).__name__, result.reason)

# Two-sided claims use an explicit conjunction.
two_sided = lc.prove(
    ast.all_of(x >= 0, x <= 1),
    where={x: (0, 1)},
)

# Compare two expressions directly; export retains this original theorem.
comparison = lc.prove(ast.sin(x) <= x, where={x: (0, 1)})

# Strict targets retain an exact interior checked bound for replay.
strict = lc.prove(x < 2, where={x: (0, 1)})

# Independent conjunction children are routed and retained separately.
combined = lc.prove(
    ast.all_of(x**2 <= 1, ast.sin(x) <= 1),
    where={x: (-1, 1)},
)

# Discover and certify a cutoff for every n at or beyond it.
from fractions import Fraction
n = ast.var("n", sort=ast.NATURAL)
eventual = lc.prove(
    ast.eventually(3 / n**2 <= Fraction(1, 1000), variable=n)
)

# Prove that one—and only one—root lies in the supplied interval.
unique = lc.prove(ast.unique_root(x, variable=x, within=(-1, 1)))
if isinstance(unique, lc.VerifiedUniqueRoot):
    unique.export_lean_project("verified-unique-root")

# Exact polynomial integration and checked one-sided bounds.
area = ast.integral(x**2, x, 0, 1)
exact_area = lc.prove(ast.eq(area, Fraction(1, 3)))
bounded_area = lc.prove(area <= Fraction(1, 2))

Neural Network Verification

Verify properties of neural networks across entire input domains:

import leancert as lc
from leancert.nn import TwoLayerReLUNetwork, Layer
import numpy as np

# Create/load a neural network
layer1 = Layer.from_numpy(
    weights=np.array([[2.0, -2.0], [-2.0, 2.0]]),
    bias=np.array([0.0, 0.0]),
    activation='relu'
)
layer2 = Layer.from_numpy(
    weights=np.array([[1.0, 1.0]]),
    bias=np.array([0.0]),
    activation='none'
)
network = TwoLayerReLUNetwork(layer1=layer1, layer2=layer2)

# Prove output bounds for ALL inputs in domain
verified = lc.verify_nn_bounds(
    network,
    {'x0': (-1, 1), 'x1': (-1, 1)},
    output_lower=-5,
    output_upper=5,
)
print(verified)  # True - proven for every possible input!

Key Features

  • Checked Bounds: Typed LeanCert checker outcomes with exact provenance
  • Neural Networks: Verify ReLU networks, transformers
  • Root Finding: Locate and isolate roots with guaranteed correctness
  • Integration: Compute integral bounds
  • Independent Audit: Rebuild exported fixed certificates with leancert verify
  • PyTorch Import: Load weights directly from PyTorch models

Supported Functions

sin, cos, tan, exp, log, sqrt, abs, sinh, cosh, tanh, atan, erf, sinc, and more.

Why LeanCert?

Traditional testing samples inputs: f(0.5), f(1.0), etc. You can never test f(0.7) and the infinitely many values in between.

LeanCert uses interval arithmetic to check properties for all inputs simultaneously. Every Verified result identifies the checker, Golden Theorem, verification route, numerical backend, and exact bridge build that accepted the certificate. Independently rebuildable Lean projects are a separate export milestone rather than an implicit claim of this runtime API.

Verified, Rejected, Unsupported, DomainObstruction, and Inconclusive are distinct outcomes. An enclosure that is too wide produces Inconclusive; failure to find a counterexample is never reported as proof. Bridge Contract 2.2 provides a separate typed adaptive certificate route backed by LeanCert's checked rational optimizer. It can close subdivision leaves that the fixed replayable checker cannot, but is not mislabeled as a replayable bound-check/2 certificate.

Links

License

Post-baseline v1 Python SDK material is source-available under the provisional LeanCert Evaluation License 1.0. Personal evaluation, education, non-commercial research, and a bounded 90-day commercial, governmental, or other organizational proof of concept are permitted. Qualifying nonprofit education and non-commercial research are not subject to that 90-day limit. Production deployment, commercial product development, customer services, and SaaS/API deployment require a separate written commercial license. Generated reports, certificates, and proof artifacts lawfully created during permitted use remain free to retain, publish, and use, including commercially; this does not grant continued rights to execute the SDK. See COMMERCIAL.md for the commercial boundary and LICENSE_SCOPE.toml for the authoritative source classification.

Python SDK material through commit 716cb2d, preserved by the tag v0.3.2-apache-final, remains available under Apache-2.0. LeanCert Core, LeanCert Bridge, and third-party components retain their separate licenses. See LICENSE, LICENSES/LeanCert-Evaluation-1.0.txt, and LICENSES/Apache-2.0.txt.

Metadata

Release files for leancert 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for leancert 2.0.0
File Size Uploaded Provenance
leancert-2.0.0.tar.gz 178.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for leancert 2.0.0
File Interpreter ABI Platform
leancert-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 377.8 kB

Release files / leancert-2.0.0.tar.gz

Download URL leancert-2.0.0.tar.gz
Size 178.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c7bdb2898cab367d3c2f30f12197855e856b06608b74b040c1c46e12a5fde49a
BLAKE2b-256 checksum
How to use checksums
470e016f596a94e79983d18ce57ae02f457af31750e6839198d9183c44136c3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 6, 2026.

Transparency log

Release files / leancert-2.0.0-py3-none-any.whl

Download URL leancert-2.0.0-py3-none-any.whl
Size 199.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3820595a80ee35eafc6bd644fffe78012e4f527e8751ef3ace8f929f894a4298
BLAKE2b-256 checksum
How to use checksums
a5c6ddda79ef434aff97ad32e14b5ac7025e614ea259cba9b1053e42bceeeb35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 6, 2026.

Transparency log

Security for leancert 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for leancert-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page