Skip to main content

scikit-verify

Translate Python and NumPy programs to symbolic mathematics

weighted_rms in numpy maps to the square root of the ratio of weighted sums

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

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

scikit_verify-0.2.0.tar.gz (223.8 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.2.0-py3-none-any.whl (122.0 kB view details)

Uploaded Python 3

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

Hashes for scikit_verify-0.2.0.tar.gz
Algorithm Hash digest
SHA256 defec808517ef86605094b03be2a94a53a5355d45f7506f5db647a532164cc62
MD5 5d345b0f1deca01f81b737a97af6f715
BLAKE2b-256 3ea4de9d3df116c78ab0b96d53ccad01b930842262c7855dd4a73b0d1735dfec

See more details on using hashes here.

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

Hashes for scikit_verify-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed7c8892f2a5a1c2d5a53d03fcbb482f1e2153d2f9fddc9796db3918b1e11101
MD5 cbaafe5f0195082c0a7cabdb62c3bf98
BLAKE2b-256 7045b62e61fad700e4cc70337a8e5c1d66c169bfaa887ad577a79765137fff9d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

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