Skip to main content

A Python library for symbolic math expressions and evaluation.

Project description

Expressionizer

Expressionizer is a Python library for symbolic math expression building, simplification, and step-by-step evaluation output.

It is designed for apps and tools that need explainable algebraic transformation, not just final answers. Typical use cases include math tutoring workflows, educational software, expression debugging, and generating human-readable solution traces.

Pre-Stable Status

Expressionizer is currently in a pre-stable (0.x) phase.

  • The core API is usable and actively developed.
  • Some interfaces and behavior may change between minor versions.
  • If you are using this in production, pin an exact version.

Why Expressionizer

  • Build symbolic expressions in Python.
  • Evaluate with variable substitutions.
  • Generate step-by-step simplification traces.
  • Render expressions as plain text and LaTeX.
  • Support structured expression types like equations and inequalities.
  • Include procedural expression generation utilities.

Features

  • Symbolic expression tree primitives
    • Symbol, Power, Product, Sum, FunctionCall
    • Equation and InEquality data structures
  • Convenience constructors
    • symbol(...), sum(...), product(...), power(...), fraction(...)
  • Expression normalization and simplification
    • Combines numeric terms/factors
    • Merges powers and repeated structures where possible
  • Step-by-step evaluation engine
    • evaluate(...) returns both the result and evaluation context
    • Context tracks snapshots and can render explanation output
    • Includes decomposition-based arithmetic steps for larger operations
  • Configurable evaluator behavior
    • Limits and precision controls via EvaluatorOptions
    • Approximation and bounds behavior for very small/large numbers
  • Rendering
    • Plain text rendering with render(...)
    • LaTeX rendering with render_latex(...)
    • Expression tree inspection with render_type(...)
  • Function evaluation support
    • Works with substitutions for variables and callables
    • Includes common math function support through procedural helpers
  • Procedural generation utilities
    • Random variable name generation
    • Random number generation with constraints
    • Weighted random expression generation for testing/content generation

Installation

pip install expressionizer

Quick Start

from expressionizer import symbol, sum, power, evaluate, render_latex

x = symbol("x")
expr = power(sum([x, 2]), 2)

result, context = evaluate(expr, substitutions={"x": 3})

print("Result:", result)
print("Expression (LaTeX):", render_latex(expr))
print(context.render())

Output from a real run:

Result: 25
Expression (LaTeX): (2 + x)^2
## Step 1
Substitute $x = 3$:
$$(2 + x)^2 \\
= (2 + 3)^2 \\
= 5^2$$

## Step 2
$$5^2 \\
= 5(5) \\
= 25$$

Real Examples (Generated by Expressionizer)

1) Symbolic multiplication with substitution

from expressionizer import symbol, sum, product, evaluate

x = symbol("x")
expr = product([sum([x, 4]), sum([x, 1])])

result, context = evaluate(expr, substitutions={"x": 5})

print(result)
print(context.render())
54
## Step 1
Substitute $x = 5$:
$$(4 + x)(1 + x) \\
= (4 + 5)(1 + 5) \\
= 9(1 + 5)$$

## Step 2
$$9(1 + 5) \\
= 9(6)$$

## Step 3
$$9(6) \\
= 54$$

2) Decimal decomposition and place-value addition

from expressionizer import Sum, evaluate

expr = Sum([4, 7.90623])
result, context = evaluate(expr)

print(result)
print(context.render())
11.90623
Let's break $4$ and $7.90623$ down into their components.
$$4 + 7.90623 \\
= 4 + 7 + 0.9 + 0.006 + 0.0002 + 0.00003$$

[aligned place-value rows]
4.00000
7.00000
0.90000
0.00600
0.00020
0.00003

$10^{-5}$: $3 + 0 + 0 + 0 + 0 + 0 = 3$
$10^{-4}$: $0 + 2 + 0 + 0 + 0 + 0 = 2$
$10^{-3}$: $0 + 0 + 6 + 0 + 0 + 0 = 6$
$10^{-1}$: $0 + 0 + 0 + 9 + 0 + 0 = 9$
$10^{0}$: $0 + 0 + 0 + 0 + 7 + 4 = 11$, carry the 1.
$10^{1}$: 1 (carried)
Putting it together, we get $11.90623$.
$$ 4 + 7 + 0.9 + 0.006 + 0.0002 + 0.00003 = 11.90623 $$

context.render() returns a formatted explanation sequence you can display in apps, notebooks, or web UIs.

Core API Overview

  • evaluate(expression, substitutions={}, error_on_invalid_snap=True)
    • Returns (result, context)
  • render(expression, group=False)
    • Plain text expression rendering
  • render_latex(expression, renderOptions=...)
    • LaTeX rendering for display and documentation
  • Constructors:
    • symbol(name)
    • sum(terms)
    • product(factors)
    • power(base, exponent)
    • fraction(numerator, denominator)

Compatibility

  • Python >=3.8
  • OS independent

Roadmap

As a pre-stable library, near-term improvements are focused on:

  • API stabilization toward 1.0
  • Expanded test coverage
  • Improved docs and examples
  • Continued refinement of step-by-step output quality

SEO Keywords

Python symbolic math library, step-by-step math solver, algebra expression evaluator, LaTeX math renderer, expression simplification engine, educational math software backend.

Contributing

Issues and pull requests are welcome. If you report a bug, include:

  • the expression
  • substitutions used
  • expected behavior
  • actual behavior and rendered steps

License

MIT

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

expressionizer-0.7.7.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

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

expressionizer-0.7.7-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file expressionizer-0.7.7.tar.gz.

File metadata

  • Download URL: expressionizer-0.7.7.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for expressionizer-0.7.7.tar.gz
Algorithm Hash digest
SHA256 7686f18554f294070458226f348b4878d676ec41083514d61709b6a7d11f4afa
MD5 12abc38167e411de68315a36ea26b35c
BLAKE2b-256 1e6c143f6d76d4f47460ef738d8217a05b6af295492bed15ec6c88f4007b7b39

See more details on using hashes here.

File details

Details for the file expressionizer-0.7.7-py3-none-any.whl.

File metadata

  • Download URL: expressionizer-0.7.7-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for expressionizer-0.7.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e9e1f8895ddbc340b22430a3ca3f9fb5c7d0ffad5742e3ab1004eae29c191bfe
MD5 2baa6f9618552047f3ec9c82b7b1dbe5
BLAKE2b-256 59668d6b709e27cf342a04c0dff95fb34d27c4ae6950b272ca72a82853d98173

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