Skip to main content

Efficient Simplification of Mathematical Expressions

Project description

SimpliPy:
Efficient Simplification of Mathematical Expressions

PyPI version PyPI license Documentation Status

pytest quality checks CodeQL Advanced

Publications

  • Saegert & Köthe 2026, Breaking the Simplification Bottleneck in Amortized Neural Symbolic Regression (preprint, under review) https://arxiv.org/abs/2602.08885

Usage

pip install simplipy

As of 0.3.0 the inline phase (simplify, conversions, validation) is a compiled Rust extension (simplipy._core). Prebuilt wheels are published for Linux (x86_64/aarch64), macOS (x86_64/arm64) and Windows (x64) on CPython ≥ 3.11, so pip install simplipy does not compile anything for most users. Installing from the source distribution (an unsupported platform, or --no-binary) requires a Rust toolchain (rustup, MSRV 1.83). If the extension is unavailable at runtime, the package transparently falls back to a slower pure-Python implementation.

import simplipy as sp

engine = sp.SimpliPyEngine.load("dev_7-3", install=True)

# Simplify prefix expressions
engine.simplify(('/', '<constant>', '*', '/', '*', 'x3', '<constant>', 'x3', 'log', 'x3'))
# > ('/', '<constant>', 'log', 'x3')

# Simplify infix expressions
engine.simplify('x3 * sin(<constant> + 1) / (x3 * x3)')
# > '<constant> / x3'

Normalization

The root-exported normalize_skeleton, normalize_expression, and normalize_variable_token helpers (also available as simplipy.normalization) canonicalize a prefix token sequence so that two expressions that are "the same" up to variable renaming / constant values compare equal. They are pure-string helpers with no engine state, so consumers such as holdout matching and symbolic-recovery scoring share identical behavior by construction.

import simplipy as sp

# Skeleton form: variables -> x{n}, numeric literals -> <constant>
sp.normalize_skeleton(['+', 'v1', '2.5'])
# > ['+', 'x1', '<constant>']

# Expression form: variables canonicalized, numeric literals kept intact
sp.normalize_expression(['+', 'V1', '2.5'])
# > ['+', 'x1', '2.5']

# Classify / canonicalize a single token -> (normalized_token, is_variable)
sp.normalize_variable_token('X3')
# > ('x3', True)
sp.normalize_variable_token('sin')
# > ('sin', False)

More examples can be found in the documentation.

Performance

Simplification time and ratio ECDFs: SymPy vs SimpliPy (Python 0.2.15) vs SimpliPy (Rust 0.3.0)

Top row: SimpliPy 0.3.0 (Rust inline engine, green). Bottom row: SimpliPy 0.2.15 (pure Python, blue). Left: Empirical Cumulative Distribution Functions (ECDFs) of simplification wall-clock time across maximum pattern lengths Lmax = 0–7, with the SymPy [Meurer et al. 2017] baseline (orange, red). The Rust inline engine is roughly 5× to 100× faster than the pure-Python engine at the same Lmax (≈ 15× at Lmax = 4), and both are orders of magnitude faster than SymPy. Right: ECDF of the simplification ratio |τ ∗|/|τ | (inset: zoom on the low-ratio region where the Lmax curves separate); the Rust and Python engines produce near-identical simplification-ratio distributions, so the Rust rewrite buys the speed-up without sacrificing simplification quality. (0.3.0 does deliberately change behaviour on a small fraction of inputs via the conversion-quirk fixes and numeric folding; see the CHANGELOG.)
Source expressions are sampled with 0 to 17 unique variables and 1 to 35 symbols [Saegert & Köthe 2026]

Development

Setup

To set up the development environment, run the following commands:

pip install -e .[dev]
pre-commit install

Tests

Test the package with pytest:

pytest tests --cov src --cov-report html

or to skip integration tests,

pytest tests --cov src --cov-report html -m "not integration"

Citation

@misc{saegert2026breakingsimplificationbottleneckamortized,
  title   = {Breaking the Simplification Bottleneck in Amortized Neural Symbolic Regression},
  author  = {Paul Saegert and Ullrich Köthe},
  year    = {2026},
  eprint  = {2602.08885},
  archivePrefix =  {arXiv},
  primaryClass  = {cs.LG},
  url     = {https://arxiv.org/abs/2602.08885},
}

% Optionally
@software{simplipy-2025,
    author = {Paul Saegert},
    title = {Efficient Simplification of Mathematical Expressions},
    year = 2025,
    publisher = {GitHub},
    version = {0.3.1},
    url = {https://github.com/psaegert/simplipy}
}

Project details


Download files

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

Source Distribution

simplipy-0.4.1.tar.gz (780.5 kB view details)

Uploaded Source

Built Distributions

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

simplipy-0.4.1-cp311-abi3-win_amd64.whl (568.4 kB view details)

Uploaded CPython 3.11+Windows x86-64

simplipy-0.4.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (703.4 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

simplipy-0.4.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (684.0 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

simplipy-0.4.1-cp311-abi3-macosx_11_0_arm64.whl (634.6 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

simplipy-0.4.1-cp311-abi3-macosx_10_12_x86_64.whl (653.6 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file simplipy-0.4.1.tar.gz.

File metadata

  • Download URL: simplipy-0.4.1.tar.gz
  • Upload date:
  • Size: 780.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for simplipy-0.4.1.tar.gz
Algorithm Hash digest
SHA256 6c64ffa911a52633e42505ebad970268bda01b9e82ed17bb6061710d6795c5ac
MD5 4702b2fcd73f4393deeba8d261cd8509
BLAKE2b-256 ca3ae9926a822b0751eee2ca70669c7d21c3679ff75d16f136ce68ffbefce8db

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplipy-0.4.1.tar.gz:

Publisher: publish.yml on psaegert/simplipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplipy-0.4.1-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: simplipy-0.4.1-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 568.4 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for simplipy-0.4.1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 accb5b30f3430a850fa815341658bfe66cce014644979160702f18f732cafd07
MD5 fd7cf2598283b8511625a7eb3848ab13
BLAKE2b-256 a00f1de2140f7cbba1cd89a928808c0ad107c92fda74ca8b4ed6d30cac0d4a47

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplipy-0.4.1-cp311-abi3-win_amd64.whl:

Publisher: publish.yml on psaegert/simplipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplipy-0.4.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for simplipy-0.4.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f42cad8c4ed2311a750a89468d85d73f3aff7e3ecd672977f1955e63a6c52ed
MD5 7f1c252ec03dbf97ac2a43d9d204b063
BLAKE2b-256 cecc02ef3558cf07f8e2cb8f10a6f0667b53e2c3e0554cac1f51f4b50223e469

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplipy-0.4.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on psaegert/simplipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplipy-0.4.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for simplipy-0.4.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1e785705c9585422d56b3f67a0292240aaff60043122e8fc678b57a1a274894c
MD5 52129331b85ed782a158f7be68214f59
BLAKE2b-256 e81f6f77ee046072488b08b2f1fbd802af65af8ef33d25c7299802a168b81078

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplipy-0.4.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on psaegert/simplipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplipy-0.4.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for simplipy-0.4.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0e42945c20a4162252d8f578aa126f9ac5e696eda5edcf69b5cb4044a8067e8
MD5 17b2b1a3fef02bdbbe6eae951f43b3df
BLAKE2b-256 2ccc92ad2e71a95798b4bc7b1d65cc9d94999757ce12c1876dd9c92889a9ea33

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplipy-0.4.1-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on psaegert/simplipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simplipy-0.4.1-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for simplipy-0.4.1-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 991187207d57283de3e4d2f4786087c83c674e9a41f31a30cb532ab51853883d
MD5 d40ce377f72209e2de68c47d1905c9c7
BLAKE2b-256 c0bdc95275f5e6cb71f7c66d222b7a45ed029e533267066767d65bf9abd12cd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for simplipy-0.4.1-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: publish.yml on psaegert/simplipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page