Skip to content

Efficient Simplification of Mathematical Expressions

License

Notifications You must be signed in to change notification settings

psaegert/simplipy

Repository files navigation

SimpliPy:
Efficient Simplification of Mathematical Expressions

PyPI version PyPI license Documentation Status

pytest quality checks CodeQL Advanced

Usage

pip install simplipy
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'

More examples can be found in the documentation.

Performance

Original vs Simplified Length and Simplification Time

Simplification efficacy and efficiency for different maximum pattern lengths (Engine: dev_7-3). Original expressions sampled with the Lample-Charton Algorithm using the following parameters:

  • 0 to 3 variables
  • 0 to 20 operators (corresponding to lengths of 0 to 41)
  • Operators:
    • with relative weight 10: +, -, *, /
    • with relative weight 1: abs, inv, neg, pow2, pow3, pow4, pow5, pow1_2, pow1_3, pow1_4, pow1_5, sin, cos, tan, asin, acos, atan, exp, log, mult2, mult3, mult4, mult5, div2, div3, div4, div5

Points show bootstrapped mean and 95% confidence interval (N = 10,000). Orange points are within the 95% confidence interval of the shortest simplified length for the respective original length. Using patterns beyond a length of 4 tokens does not yield significant improvements and comes at a cost of increased simplification time.

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

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