Skip to main content

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leancert-0.3.0.tar.gz (79.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

leancert-0.3.0-py3-none-win_amd64.whl (75.4 MB view details)

Uploaded Python 3Windows x86-64

leancert-0.3.0-py3-none-manylinux2014_x86_64.whl (79.1 MB view details)

Uploaded Python 3

leancert-0.3.0-py3-none-macosx_11_0_arm64.whl (70.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

leancert-0.3.0-py3-none-macosx_10_15_x86_64.whl (70.0 MB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

Details for the file leancert-0.3.0.tar.gz.

File metadata

  • Download URL: leancert-0.3.0.tar.gz
  • Upload date:
  • Size: 79.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for leancert-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a7da9d87df3feff2477c0bda159527f6ec75a0267abbe4e7a83342b35573cb64
MD5 1a73ad64fe1e1325636be04b04a78baf
BLAKE2b-256 d19b152c1e04106598681c8a0e7637397752c90b41a252bd3f602441c18f2398

See more details on using hashes here.

Provenance

The following attestation bundles were made for leancert-0.3.0.tar.gz:

Publisher: build-wheels.yml on alerad/leancert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leancert-0.3.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: leancert-0.3.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 75.4 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for leancert-0.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4c9b14262a42c3c9c3a40b3e4853ac2cc5012f96df2cd562967430672fec0981
MD5 3469eb85f3c8d97d07d130c5c35f8ca4
BLAKE2b-256 96e379d22ae1b094952e2734136d2dcae8aa1e377786bf7c626280586b73e109

See more details on using hashes here.

Provenance

The following attestation bundles were made for leancert-0.3.0-py3-none-win_amd64.whl:

Publisher: build-wheels.yml on alerad/leancert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leancert-0.3.0-py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for leancert-0.3.0-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7de7a23577090024801b8fc4c20ed5eec46853573723ef39930d61780ce77512
MD5 9bc4b8eb16af2de8a8921a812b7bc16f
BLAKE2b-256 f73b44b16c6205f738a5b0e5973d2fa64523f537936ac0db7247def1c9e73dbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for leancert-0.3.0-py3-none-manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on alerad/leancert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leancert-0.3.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for leancert-0.3.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e41ef3e0a70dbb9102d86214ae4c312bd03e3074e9d6825f42c1acff5aec3d42
MD5 6ce73b7a962ae86aee6ecc8acab02caf
BLAKE2b-256 05f96036470b05c4bd644fbe7fde277df5f8ba093806d900268aa1ad097178c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for leancert-0.3.0-py3-none-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on alerad/leancert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leancert-0.3.0-py3-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for leancert-0.3.0-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 6421e00579b42e8601f1238bafabc314fee6da79a3136805a0ef612c069c68c4
MD5 73491d56b24f13fa38e1825734ea8e88
BLAKE2b-256 5c76557ecf9a160c4aa194010ded8556927e5a72979fef6b09d6fe2caec745cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for leancert-0.3.0-py3-none-macosx_10_15_x86_64.whl:

Publisher: build-wheels.yml on alerad/leancert

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page