Skip to main content

polyinv – Discover Minimal Canonical Polynomial Invariants from Noisy Data

PyPI version License: MIT

polyinv is a Python package that recovers minimal canonical polynomial invariants from noisy numerical data. Given a set of observations (points in ℝⁿ), it returns the reduced Gröbner basis of the polynomial ideal that vanishes on the data, up to a specified degree and rational coefficient tolerance.

The algorithm is based on the paper:

Canonical Minimal Polynomial Invariants from Noisy Data via Adaptive Sparse Nullspace Recovery and Gröbner Basis
Tesfay Zemuy Gebrekidan
PDF · Code


Features

  • Unique canonical form – returns the reduced Gröbner basis (grevlex order), guaranteed minimal and irredundant.
  • Handles multiple simultaneous invariants – Combinatorial Sparse Nullspace Pursuit (CSNP) separates linearly mixed conservation laws.
  • Rationality prior – prefers coefficients with low bit-cost (small integers and denominators) over spurious irrational fits.
  • Certified global search – Branch-and-Bound with dominance pruning ensures optimality (Theorem 4.4).
  • Adaptive degree discovery – automatically finds the polynomial degree via an MDL-based sweep (default maximum degree 10).
  • Noise-aware – errors-in-variables correction, adaptive snap-rounding, and scale-relative residual thresholds.
  • Multiple input formats – NumPy arrays, Pandas DataFrames, or CSV files.
  • Command-line interface – discover invariants directly from the terminal.

Installation

Install from PyPI:

pip install polyinv

Or install the latest development version:

git clone https://github.com/TesfayZ/polyinv
cd polyinv
pip install -e .

Quick Start

import numpy as np
from polyinv import discover

# Generate data on the unit circle
t = np.linspace(0, 2*np.pi, 500)
data = np.column_stack([np.cos(t), np.sin(t)])
var_names = ["x", "y"]

# Discover x² + y² − 1 = 0
result = discover(data, var_names=var_names, max_degree=2)

print(result.basis)
# [x**2 + y**2 - 1]

print(result.status)
# SUCCESS

print(result.certified)
# True

Command-Line Interface

polyinv data.csv --vars x,y --max-degree 2 --format json

For all available options:

polyinv --help

API Reference

discover(
    data,
    var_names=None,
    *,
    noise_sigma=None,
    max_degree=None,
    D_max=10,
    max_denom=64,
    k_max=6,
    full_nullspace=False,
    use_bb=True,
    auto_escalate_denom=True,
    standardize=False,
    verbose=False,
)

Recovers the reduced Gröbner basis of the vanishing ideal.

Parameters

Parameter Description
data np.ndarray, pd.DataFrame, or CSV filename
var_names Optional variable names
noise_sigma Estimated noise standard deviation. If None, estimated from the SVD tail.
max_degree Maximum polynomial degree. If omitted, adaptive search is used.
D_max Upper bound for adaptive degree discovery (default 10).
max_denom Largest denominator allowed for rational coefficients (default 64).
k_max Maximum support size (default 6).
full_nullspace Enable full-nullspace deflation when multiple invariants are expected.
use_bb Use Branch-and-Bound certification.
auto_escalate_denom Retry using larger denominators if necessary.
standardize Standardize variables before fitting.
verbose Print progress information.

Returns

A PolyInvResult object containing:

Attribute Description
basis Reduced Gröbner basis (SymPy expressions)
status "SUCCESS", "ABSTAINED", or "FAILED"
certified Whether exhaustive search certified optimality
message Human-readable status
elapsed Runtime in seconds

Additional diagnostic information (support sets, rationality cost, etc.) is also available.


Advanced Usage

Using a Pre-built Design Matrix

from polyinv._sr_gb import build_transition_difference_library

_, monomials, Phi = build_transition_difference_library(
    old_data,
    new_data,
    var_names,
    degree,
)

result = discover(
    None,
    var_names,
    degree=degree,
    monomials=monomials,
    Phi=Phi,
)

How It Works

The algorithm proceeds through the following stages:

  1. Monomial Expansion

    • Builds the polynomial feature library up to the selected degree.
  2. Numerical Nullspace Estimation

    • Uses Singular Value Decomposition (SVD) to estimate the nullspace.
  3. Combinatorial Sparse Nullspace Pursuit (CSNP)

    • Searches for sparse polynomial relations using the lexicographic objective:
    1. Rationality cost
    2. Sparsity
    3. Stability gap
  4. Snap-Rounding

    • Converts floating-point coefficients into exact rational numbers using adaptive tolerances.
  5. Algebraic Simplification

    • Removes redundant factors and unnecessary higher-degree multiples.
  6. Gröbner Basis Canonicalisation

    • Computes the reduced Gröbner basis over ℚ using graded reverse lexicographic order (grevlex).

The final output is a unique minimal generating set for the polynomial ideal that vanishes on the observed data.


Citation

If you use polyinv in your research, please cite:

@article{Gebrekidan2026polyinv,
  author  = {Tesfay Zemuy Gebrekidan},
  title   = {Canonical Minimal Polynomial Invariants from Noisy Data via Adaptive Sparse Nullspace Recovery and Gröbner Basis},
  journal = {Preprint},
  year    = {2026},
  note    = {\url{https://arxiv.org/abs/...}}
}

License

This project is licensed under the MIT License. See the LICENSE file for details.


Contributing

Bug reports, feature requests, and pull requests are welcome.

Please open an issue or submit a pull request on GitHub.


Acknowledgements

This work builds upon ideas from the Sparse Identification of Nonlinear Dynamics (SINDy) and Approximate Vanishing Ideal (AVI) communities, and uses SymPy for symbolic algebra and Gröbner basis computations.

Metadata

Release files for polyinv 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polyinv 0.1.0
File Size Uploaded Provenance Actions
polyinv-0.1.0.tar.gz 57.5 kB Without provenance Details for polyinv-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polyinv 0.1.0
File Interpreter ABI Platform Actions
polyinv-0.1.0-py3-none-any.whl Python 3 none any Details for polyinv-0.1.0-py3-none-any.whl

Total release size: 113.6 kB

Release files / polyinv-0.1.0.tar.gz

Download URL polyinv-0.1.0.tar.gz
Size 57.5 kB
Tags Source
SHA-256 checksum
How to use checksums
084345b5f06be078f7892145b65d0a208d7d8742459c6ca4c6bd7d69acb0d81c
BLAKE2b-256 checksum
How to use checksums
5ea0fdb5439476874a325d6f063629aaa69b35c5ad44f459e9de15a1137711fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / polyinv-0.1.0-py3-none-any.whl

Download URL polyinv-0.1.0-py3-none-any.whl
Size 56.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ae89f46f3ba5805626b79fd28c5b1ffde883418d37eae01aac7a890cd759c84
BLAKE2b-256 checksum
How to use checksums
ce3d8d8cd1efe43526cba57c24dbdfab74099e421771c1ccd6c7ee452973dfba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for polyinv 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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