Formal verification for numerical Python code - powered by Lean4
Project description
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)
# Verify a bound holds for ALL x in [-2, 2]
verified = lc.verify_bound(expr, {'x': (-2, 2)}, lower=-0.25)
print(verified) # True - mathematically proven!
# 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.
Links
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leancert-0.3.1.tar.gz.
File metadata
- Download URL: leancert-0.3.1.tar.gz
- Upload date:
- Size: 83.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea26f1c4c969fefb243349d7a0931fdd91adebeff19b5555ad252d7f61a8217e
|
|
| MD5 |
c75b10549d8b388f0b5b7c0ff0da3397
|
|
| BLAKE2b-256 |
436a1a690b69b7b8ebe66620ae39eecf25e81da7d393969b346736548e6921cc
|
Provenance
The following attestation bundles were made for leancert-0.3.1.tar.gz:
Publisher:
build-wheels.yml on alerad/leancert-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leancert-0.3.1.tar.gz -
Subject digest:
ea26f1c4c969fefb243349d7a0931fdd91adebeff19b5555ad252d7f61a8217e - Sigstore transparency entry: 2128358946
- Sigstore integration time:
-
Permalink:
alerad/leancert-python@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/alerad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Trigger Event:
push
-
Statement type:
File details
Details for the file leancert-0.3.1-py3-none-win_amd64.whl.
File metadata
- Download URL: leancert-0.3.1-py3-none-win_amd64.whl
- Upload date:
- Size: 39.3 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64bc088cd4b51a4b19f66a1c733e353fe9f9816eceb9ee995e3631a00a54f18c
|
|
| MD5 |
82fc7af11caa1626875c4a51b2b9ff67
|
|
| BLAKE2b-256 |
78b7c484c7c89562360873c611bae993ee41ad9cf1b69eebe5ab3ffc7a7751e5
|
Provenance
The following attestation bundles were made for leancert-0.3.1-py3-none-win_amd64.whl:
Publisher:
build-wheels.yml on alerad/leancert-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leancert-0.3.1-py3-none-win_amd64.whl -
Subject digest:
64bc088cd4b51a4b19f66a1c733e353fe9f9816eceb9ee995e3631a00a54f18c - Sigstore transparency entry: 2128358962
- Sigstore integration time:
-
Permalink:
alerad/leancert-python@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/alerad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Trigger Event:
push
-
Statement type:
File details
Details for the file leancert-0.3.1-py3-none-manylinux2014_x86_64.whl.
File metadata
- Download URL: leancert-0.3.1-py3-none-manylinux2014_x86_64.whl
- Upload date:
- Size: 38.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a94c08389b69ff01a9fb525121b60673a60df49431e05c74168a8e7970bdcb2
|
|
| MD5 |
498d3de2fb77db1f995346972e5515af
|
|
| BLAKE2b-256 |
5bc6d2f5a4460f1e611afdbe8dc8ecfd5b33abefe8cd2fa3fc55e68ba33628a0
|
Provenance
The following attestation bundles were made for leancert-0.3.1-py3-none-manylinux2014_x86_64.whl:
Publisher:
build-wheels.yml on alerad/leancert-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leancert-0.3.1-py3-none-manylinux2014_x86_64.whl -
Subject digest:
1a94c08389b69ff01a9fb525121b60673a60df49431e05c74168a8e7970bdcb2 - Sigstore transparency entry: 2128358996
- Sigstore integration time:
-
Permalink:
alerad/leancert-python@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/alerad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Trigger Event:
push
-
Statement type:
File details
Details for the file leancert-0.3.1-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: leancert-0.3.1-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 34.3 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da3e6ac338ecae9572391879ace864d928810d6fe235c715436104db93bc6894
|
|
| MD5 |
ea01032733bf0c2cb521b7a49f87a6e5
|
|
| BLAKE2b-256 |
6ea666a8da0c50df1c1d54fee7e99a68a73f7253c36b441ca5f2874313c1f358
|
Provenance
The following attestation bundles were made for leancert-0.3.1-py3-none-macosx_11_0_arm64.whl:
Publisher:
build-wheels.yml on alerad/leancert-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leancert-0.3.1-py3-none-macosx_11_0_arm64.whl -
Subject digest:
da3e6ac338ecae9572391879ace864d928810d6fe235c715436104db93bc6894 - Sigstore transparency entry: 2128359013
- Sigstore integration time:
-
Permalink:
alerad/leancert-python@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/alerad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Trigger Event:
push
-
Statement type:
File details
Details for the file leancert-0.3.1-py3-none-macosx_10_15_x86_64.whl.
File metadata
- Download URL: leancert-0.3.1-py3-none-macosx_10_15_x86_64.whl
- Upload date:
- Size: 34.3 MB
- Tags: Python 3, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dde6335223d0bfe430bd9087eb568b72cc71fd569f647377209074dced08969e
|
|
| MD5 |
d26139a4737aa29e2988bce4a50b78d7
|
|
| BLAKE2b-256 |
1fe8c094f0ca737767e039fba866239e00f23d0d4492c594e319c2d651152eaa
|
Provenance
The following attestation bundles were made for leancert-0.3.1-py3-none-macosx_10_15_x86_64.whl:
Publisher:
build-wheels.yml on alerad/leancert-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
leancert-0.3.1-py3-none-macosx_10_15_x86_64.whl -
Subject digest:
dde6335223d0bfe430bd9087eb568b72cc71fd569f647377209074dced08969e - Sigstore transparency entry: 2128358980
- Sigstore integration time:
-
Permalink:
alerad/leancert-python@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/alerad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@7a3b75bcc6cec99da5d2e2097ee2f84ce6ef3010 -
Trigger Event:
push
-
Statement type: