Expr Simplifier
🍋🟩 A tool for simplifying Python expressions that don't contain side effects, mainly for generated code
Usage
Quick start in CLI
We recommend using the tool uv to try it without manually installing the package:
$ uvx expr_simplifier cse "a * 4 + (a * 4)"
(___t_0 := (a * 4)) + ___t_0
$ uvx expr_simplifier constant_folding "(___x := 1 + 1) + ___x" --max-iter=1
(___x := 2) + ___x
$ uvx expr_simplifier constant_folding "(___x := 1 + 1) + ___x" --max-iter=2
4
# uvx expr_simplifier logical_simplification "a and b and a"
a and b
As a library
$ uv add expr-simplifier
from __future__ import annotations
import ast
from expr_simplifier import auto_simplify
code = "a[1 + 1].b + a[3 - 1].b.c + (___x := 2) + (a[2].b and (___x == 2) and a[2].b)"
tree = ast.parse(code, mode="eval")
simplified_tree = auto_simplify(tree)
print(ast.unparse(simplified_tree))
# (___t_1 := a[2].b) + ___t_1.c + 2 + ___t_1
TODOs
- Add runtime checks in uts
Release files for expr-simplifier 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| expr_simplifier-0.1.1.tar.gz | 16.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| expr_simplifier-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.8 kB
Release files / expr_simplifier-0.1.1.tar.gz
| Download URL | expr_simplifier-0.1.1.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9004852cc596ce56dc850e8e2622196cb85720984df09a055ba7202f1f939980
|
|
BLAKE2b-256 checksum How to use checksums |
8c1f151502bfdcfadf90a7dd5c361df54197174acf48b9e16beaf5d2344ba418
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / expr_simplifier-0.1.1-py3-none-any.whl
| Download URL | expr_simplifier-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cec6c0e0dbeda22e228a65c260da4947c4b835e337faa9230edfe4a6022b1cd5
|
|
BLAKE2b-256 checksum How to use checksums |
b971abfad168ba9cb60714380bee030886f1852fa9856369a93f2f28c6c4c1fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|