Translate Python and NumPy programs to symbolic mathematics
- Source code
- Coverage
- License
- skverify-mcp - MCP for mathematical feedback for coding agents
- skverify-hypothesis - find every branch, boundary and edge case of your function with Hypothesis
- Blog post - the story and the mathematics, with examples
- Demo - a 20-page SciPy derivation, checked
scikit-verify is a tracer for numerical Python. It runs your NumPy function once and returns the formula it computed, as an ordinary SymPy expression you can read, simplify, compare against a paper, or evaluate at any other input. Your code is not modified or annotated. For example:
import numpy as np
from skverify import to_sympy
def weighted_rms(x, w):
return np.sqrt(np.sum(w * x**2) / np.sum(w))
out = to_sympy(weighted_rms, np.array([1.0, 2.0, 3.0]), np.array([0.5, 0.3, 0.2]))
out.formula
# sqrt(Sum(w[j]*x[j]**2, (j, 0, 2))/Sum(w[j], (j, 0, 2)))
Every formula comes as a certificate: the expression, plus the assumptions it was derived under. When code branches on your data, the branch taken becomes a stated hypothesis instead of a hidden one:
out = to_sympy(np.median, np.array([3.0, 1.0, 4.0, 1.5]))
print(out.pretty())
# formula = a[0]/2 + a[3]/2
# assumes[0] = a[0] <= a[2]
# assumes[1] = a[1] <= a[3]
# assumes[2] = a[3] <= a[0]
The contract is exact-or-refuse. If an operation has no faithful symbolic form, scikit-verify raises instead of guessing:
to_sympy(lambda a: a.astype(int).mean(), np.array([1.4, 2.6]))
# NotImplementedError: astype to non-float would change the math
Tested against numpy, scipy, scikit-learn, statsmodels, cvxpy and random research code from GitHub; the boards in coverage regenerate every number.
A certificate is also the statement a proof assistant consumes: the formula with its hypotheses. A Lean 4 / Mathlib bridge for the rational-arithmetic fragment is on the roadmap, upgrading certificates from solver-checked to kernel-checked.
Installation
pip install scikit-verify
Requires Python >= 3.11, numpy, and sympy. The import name is
skverify. The companion layers install as extras:
pip install "scikit-verify[mcp]" # MCP server for coding agents
pip install "scikit-verify[hypothesis]" # testing helpers
Pre-alpha; the API may change. Iterative solvers at real sizes can be slow to trace (minutes, not wrong); the boards in coverage/ carry timings.
Lineage
The ideas here are old and good. Pairing a concrete execution with a symbolic one is King's symbolic execution (CACM 1976), run in the concolic style of Cadar and Sen. Checking a compiled routine's answer against its defining equation, instead of trusting its name, is Blum and Kannan's result checking (1989). Folding a long trace back into its loop structure follows Larus's whole-program paths (PLDI 1999), with templates recovered by Plotkin's anti-unification (1970). The stance that code verification means checking code against the mathematics it claims to implement is Oberkampf and Roy's (2010). Verified lifting of stencils to summaries was developed by Kamil et al. (PLDI 2016) for performance; scikit-verify lifts for correctness. Converting NumPy to SymPy was wished for in sympy#2810 (2014).
License
BSD-3-Clause. scikit-verify is an independent project and is not affiliated with the SciPy developers.
If this is useful to you, a star helps others find it ⭐
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 scikit_verify-0.2.0.tar.gz.
File metadata
- Download URL: scikit_verify-0.2.0.tar.gz
- Upload date:
- Size: 223.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
defec808517ef86605094b03be2a94a53a5355d45f7506f5db647a532164cc62
|
|
| MD5 |
5d345b0f1deca01f81b737a97af6f715
|
|
| BLAKE2b-256 |
3ea4de9d3df116c78ab0b96d53ccad01b930842262c7855dd4a73b0d1735dfec
|
File details
Details for the file scikit_verify-0.2.0-py3-none-any.whl.
File metadata
- Download URL: scikit_verify-0.2.0-py3-none-any.whl
- Upload date:
- Size: 122.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed7c8892f2a5a1c2d5a53d03fcbb482f1e2153d2f9fddc9796db3918b1e11101
|
|
| MD5 |
cbaafe5f0195082c0a7cabdb62c3bf98
|
|
| BLAKE2b-256 |
7045b62e61fad700e4cc70337a8e5c1d66c169bfaa887ad577a79765137fff9d
|