Translate Python and NumPy programs to symbolic mathematics
- Source code
- Coverage
- License
- skverify-mcp - MCP for mathematical feedback for coding agents
- 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.
You can also state the formula you believe and let the trace check it, as an ordinary pytest test:
import sympy
from scipy.integrate import simpson
from skverify.testing import specifies
y = sympy.IndexedBase("y")
@specifies((y[0] + 4*y[1] + 2*y[2] + 4*y[3] + y[4]) / 3)
def test_simpson_is_the_textbook_rule():
return (lambda v: simpson(v)), (np.array([0.7, 1.2, 2.5, 0.3, 0.4]),)
The comparison is symbolic, not sampled: a passing test means the code computes that formula for every input of that shape, and a failing one prints both formulas with a concrete counterexample. Specs come from the paper or the docstring, never from the trace itself.
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
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.3.0.tar.gz.
File metadata
- Download URL: scikit_verify-0.3.0.tar.gz
- Upload date:
- Size: 253.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c7bd28d8ce26e8cdfedf58ec11ce8fa0326acdd50e5c4c686a30e3bea67a2e8
|
|
| MD5 |
9ecea36bc11dced9be7733a15f3e206a
|
|
| BLAKE2b-256 |
2935c968ca170b19dd6f73150cc7c6778dbfc57e9969a7755d404b2980581c52
|
File details
Details for the file scikit_verify-0.3.0-py3-none-any.whl.
File metadata
- Download URL: scikit_verify-0.3.0-py3-none-any.whl
- Upload date:
- Size: 128.2 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 |
e9adcedc6ed243ed61e0e909df8f6629d2d3eade38693f40cd1ea63c106b9273
|
|
| MD5 |
50186c256dd1431ec8bba74edad2b31d
|
|
| BLAKE2b-256 |
6ba82e2d3409844fb5d6fd5afa1e65c3ed2ffadada52d18371a86db0e858c960
|