Skip to main content

scikit-verify

Translate Python and NumPy programs to symbolic mathematics

CI

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

This works on real library code, not just kernels: scikit-learn metrics come back as their defining formulas (precision as its ratio of counting sums), fitted estimators as their closed forms, iterative solvers as held recurrences, and compiled routines (LAPACK, FFT, Cython) as named terms that are checked against their defining equations on every call: svd against U diag(S) Vh = A, fft against the DFT sum itself.

Randomness stays honest too. A draw like rng.normal(0, s) enters the formula as a random variable with that distribution, so sympy.stats.E and variance of the result compute in closed form, while the concrete run keeps the exact numbers drawn.

Tested against numpy, scipy, scikit-learn, statsmodels, cvxpy and random research code from GitHub; the boards in coverage regenerate every number.

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.

Download files

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

Source Distribution

scikit_verify-0.1.0.tar.gz (209.7 kB view details)

Uploaded Source

Built Distribution

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

scikit_verify-0.1.0-py3-none-any.whl (118.7 kB view details)

Uploaded Python 3

File details

Details for the file scikit_verify-0.1.0.tar.gz.

File metadata

  • Download URL: scikit_verify-0.1.0.tar.gz
  • Upload date:
  • Size: 209.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for scikit_verify-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ab2629c25c8b2ad3b62c4dc0322046005c2574c2e4503083f4e2f1ee9111c0cb
MD5 035ee8dba96c757531ac384d720d2582
BLAKE2b-256 0503d9cce67d40b47e0d7b1aba8e8194e5139dcba5dd9eaa7a5e1c0954751ba0

See more details on using hashes here.

File details

Details for the file scikit_verify-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: scikit_verify-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 118.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for scikit_verify-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b8525da9c9e208604b1e86f7f3ca9b985105d67b75fc0e465595571ba0cddbb
MD5 90abf0239735d655239dfa14bd4db37c
BLAKE2b-256 b2d62bacdb5e5744af02bee876c0f432d883724c2c020951b2236bccd4fe8b5f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page