LeanCert
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
That's it! The package includes pre-built binaries - no Lean installation required.
Bridge binaries are sourced from the decoupled leancert-bridge release tag
pinned in bridge-version.txt.
Quick Start
import leancert as lc
# Define a symbolic expression
x = lc.var('x')
expr = x**2 + lc.sin(x)
# Check a bound for ALL x in [-2, 2]
result = lc.verify_bound(expr, {'x': (-2, 2)}, lower=-0.25)
if isinstance(result, lc.Verified):
print("The checked interval route verified the bound.")
elif isinstance(result, lc.Rejected):
print("A checked point enclosure disproved the bound.")
else:
print("The available enclosure was inconclusive.")
# Find rigorous bounds
result = lc.find_bounds(expr, {'x': (-2, 2)})
print(f"min in [{result.min_lo}, {result.min_hi}]")
print(f"max in [{result.max_lo}, {result.max_hi}]")
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
- Interval Arithmetic: Rigorous bounds using machine-verified Lean4 kernel
- Neural Networks: Verify ReLU networks, transformers
- Root Finding: Locate and isolate roots with guaranteed correctness
- Integration: Compute integral bounds
- 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 prove properties for all inputs simultaneously. The heavy lifting happens in Lean4's kernel, which has a small, trusted core verified to be mathematically sound.
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. Adaptive
optimization remains discovery-only in this SDK until its typed bridge
certificate route is released and pinned.
Links
License
Apache 2.0
Metadata
Release files for leancert 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| leancert-0.3.2.tar.gz | 86.4 kB | With provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| leancert-0.3.2-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| leancert-0.3.2-py3-none-manylinux2014_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details |
| leancert-0.3.2-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
| leancert-0.3.2-py3-none-macosx_10_15_x86_64.whl | Python 3 | none | macOS 10.15+ x86-64 | Details |
Total release size: 146.6 MB
Release files / leancert-0.3.2.tar.gz
| Download URL | leancert-0.3.2.tar.gz |
|---|---|
| Size | 86.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48a5c0f5302d688e5aa388a9a0c8e99f34820f27d6e90b5abbcb2c40197f03b4
|
|
BLAKE2b-256 checksum How to use checksums |
ed599e8fee30d566765983f4013c361f953b91e654b88c9fb406e91996167ec9
|
| 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 Jul 31, 2026.
Transparency logRelease files / leancert-0.3.2-py3-none-win_amd64.whl
| Download URL | leancert-0.3.2-py3-none-win_amd64.whl |
|---|---|
| Size | 39.3 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e193ee2b130b1e553a948f9a9313ce61defe996f9705d30683abbf21c8ad2db8
|
|
BLAKE2b-256 checksum How to use checksums |
7487574547b1b4a5d7ede63d6e1d504421fd639ef2cc52dd866b4a1cc1d7ae17
|
| 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 Jul 31, 2026.
Transparency logRelease files / leancert-0.3.2-py3-none-manylinux2014_x86_64.whl
| Download URL | leancert-0.3.2-py3-none-manylinux2014_x86_64.whl |
|---|---|
| Size | 38.6 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
b272b20b93a25fd4d95903c76af392b1b9476294c1ea7e39a72c49f45c7a7982
|
|
BLAKE2b-256 checksum How to use checksums |
12090a8e3a3450c66993fbbb9723433e8e1d660c004bdafa67846da6ea9f4cc0
|
| 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 Jul 31, 2026.
Transparency logRelease files / leancert-0.3.2-py3-none-macosx_11_0_arm64.whl
| Download URL | leancert-0.3.2-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 34.3 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
45ac0a86cdc0dc5e5207f3d22aaf0d3badef18f825acc24c249489dfba3f9678
|
|
BLAKE2b-256 checksum How to use checksums |
de7ac8830758ce0fd82bb4e8dcbbf327fb60926b511bd9ff299cd7b4ad386299
|
| 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 Jul 31, 2026.
Transparency logRelease files / leancert-0.3.2-py3-none-macosx_10_15_x86_64.whl
| Download URL | leancert-0.3.2-py3-none-macosx_10_15_x86_64.whl |
|---|---|
| Size | 34.3 MB |
| Tags | Python 3 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
c56c09e175011a8934406e20accb3e4ab6a85db195d2c8a6945a4145aeb4435a
|
|
BLAKE2b-256 checksum How to use checksums |
ec25454a60765b7ad9c4ebbe8222f4205fc0117e9669771e3541e7259a2ab9d5
|
| 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 Jul 31, 2026.
Transparency logSecurity for leancert 0.3.2
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 5 files in this release have been uploaded with provenance metadata.
Attestation for leancert-0.3.2.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 Jul 31, 2026.
Transparency logA 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.