Skip to main content

F-family fusion pattern rewriter for symbolic expressions and Python source.

Project description

eml-rewrite

Pre-release. Patent pending. Not for redistribution.

F-family fusion pattern rewriter for symbolic expressions. Detects equivalent rewrites that strictly reduce predicted EML cost (per eml-cost). Provable non-regression: every proposed rewrite either improves the cost or is filtered out.

Status

Pre-release. Covered by Monogate Research patent applications #11 and #12 (filed 2026-04-25). Public release follows post-prosecution licensing.

Library API

from eml_rewrite import suggest, best, score, Suggestion
import sympy as sp

x = sp.Symbol("x", real=True)

# Find improving rewrites (provably non-regressing)
sugg = suggest(sp.exp(x) / (1 + sp.exp(x)))
# [Suggestion(pattern_name="sigmoid",
#             rewritten=1/(1 + exp(-x)),
#             score_before=3, score_after=2, reduction=1)]

# Pick the lowest-score rewrite, or original if no improvement
best(sp.sinh(x) / sp.cosh(x))
# tanh(x)

best(sp.exp(sp.exp(x)))
# exp(exp(x))   ← original; nothing in library matches

Pattern library (9)

  1. exp(x)/(1+exp(x))1/(1+exp(-x)) — sigmoid canonicalization
  2. sinh(x)/cosh(x)tanh(x) — F-family fusion
  3. (exp(x)+exp(-x))/2cosh(x) — hyperbolic fusion
  4. (exp(x)-exp(-x))/2sinh(x) — hyperbolic fusion
  5. sin(x)² + cos(x)²1 — Pythagorean identity
  6. cosh(x)² - sinh(x)²1 — hyperbolic identity
  7. exp(log(x)), log(exp(x))x — inverse pair
  8. log(a/b)log(a) - log(b) — when score improves
  9. log(x^n)n·log(x) — when score improves

Command line

eml-rewrite scan FILE [FILE ...]    # report rewrites without applying
eml-rewrite fix  FILE [FILE ...]    # show rewrites that would be applied
eml-rewrite analyze "exp(sin(x))"   # full Pfaffian profile + suggestions

Example:

$ eml-rewrite analyze "exp(x)/(1 + exp(x))"
Expression:           exp(x)/(1 + exp(x))
  pfaffian_r:           1
  max_path_r:           1
  eml_depth:            2
  structural_overhead:  3
  corrections:          Corrections(c_osc=0, c_composite=0, delta_fused=0)
  predicted_depth:      4
  is_pfaffian_not_eml:  False

Suggested rewrites (1):
  [sigmoid] 1/(1 + exp(-x))  (-1 cost units)

Provable non-regression

The library's headline guarantee:

for expr in any_collection:
    for s in suggest(expr, only_improvements=True):
        assert s.score_after < s.score_before  # always

Every rewrite returned with only_improvements=True strictly reduces the EML predicted depth. The test suite validates this on a hand-checked panel; the engine filters non-improvements before returning them.

Installation (pre-release, local only)

pip install -e /path/to/eml-rewrite-pkg

Requires eml-cost (also pre-release).

License

PROPRIETARY-PRE-RELEASE. See LICENSE.

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

eml_rewrite-0.1.0a0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

eml_rewrite-0.1.0a0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file eml_rewrite-0.1.0a0.tar.gz.

File metadata

  • Download URL: eml_rewrite-0.1.0a0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for eml_rewrite-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 0f5472b06086bc96f83bfd542d2a2066d775fde7f746aef08aa423aa4d0b2b19
MD5 3b43dbbb34ea7b08175426603d1dab66
BLAKE2b-256 d78c3fc7e374fe6dfa6f657399c078e484062e11e336298a9e1f7fcf8f2052aa

See more details on using hashes here.

File details

Details for the file eml_rewrite-0.1.0a0-py3-none-any.whl.

File metadata

  • Download URL: eml_rewrite-0.1.0a0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for eml_rewrite-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ad368f3931a6420137f0ca8678cbdd7b25e86c7f95a21fb5446cec6a918f706
MD5 42255fe6f8704a950d72fa3fda3d8c32
BLAKE2b-256 66019cded72edc0632206266ae33bf36327fe82f2384694137d2f179e82d1dd1

See more details on using hashes here.

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