Skip to main content

mathio

Parse custom mathematical notation and evaluate symbolically with SymPy. Also supports generating Wolfram Language code as an opt-in backend.

Installation

pip install mathio-py

SymPy is installed automatically as a required dependency.

Quick Start

from mathio import convert, to_wolfram

# Evaluate symbolically (default)
convert("sin(π/4)")          # Unicode pretty-print
convert("sin(π/4)", fmt="plain")  # "sqrt(2)/2"
convert("sin(π/4)", fmt="latex")  # "\frac{\sqrt{2}}{2}"

# Generate Wolfram Language code
to_wolfram("sinx")           # "Sin[x]"
to_wolfram("int sinx d x")   # "Integrate[Sin[x], x]"

CLI Usage

python -m mathio "sin(π/4)"             # SymPy evaluation (pretty)
python -m mathio --plain "sin(π/4)"     # SymPy (plain text)
python -m mathio --latex "sin(π/4)"     # SymPy (LaTeX)
python -m mathio --wolfram "sinx"       # Wolfram Language code
python -m mathio --wolfram -f input.txt # Batch Wolfram generation

Grammar

expression      : add_expr
add_expr        : mul_expr (('+'|'-') mul_expr)*
mul_expr        : power_expr (('*'|'/') power_expr)*
power_expr      : implicit_mul ('^' power_expr)?        (right-associative)
implicit_mul    : factor+                                (n-ary, left-associative)
factor          : integral | derivative | func_app | unary_minus | atom
integral        : 'int' ('[' expression ',' expression ']')? expression 'd' IDENT
derivative      : DERIV implicit_mul
func_app        : FUNC '(' expression ')'
                | FUNC implicit_mul                       (stops at next FUNC)
unary_minus     : '-' factor
atom            : NUMBER | CONSTANT | IDENT | '(' expression ')'

Lexical Rules

  • Keyword splitting: Reserved keywords are split from adjacent identifiers via longest-prefix matching. e.g. sinx → sin + x, density → d + e + nsity.
  • DERIV: d/dx, d/dy, d/dtheta are recognized as a single derivative token.
  • Numbers: Integers, decimals, and scientific notation. The e in 2e1 is scientific notation; 2e is 2 * e.
  • Unicode constants: π → pi, ∞ → infty.

More Examples

from mathio import convert, to_wolfram

# SymPy evaluation
convert("sinx")                   # sin(x)
convert("int sinx d x")           # -cos(x)
convert("d/dx sinx")              # cos(x)
convert("int [0,1] x d x")        # 1/2
convert("2^10")                   # 1024
convert("1/3 + 1/6")              # 1/2

# Wolfram generation
to_wolfram("sinπx")               # Sin[Times[Pi, x]]
to_wolfram("4x/3y")               # Times[Times[4, x], Power[Times[3, y], -1]]
to_wolfram("d/dx sinx cosx")      # D[Times[Sin[x], Cos[x]], x]
to_wolfram("sin cos x y")         # Sin[Cos[Times[x, y]]]
to_wolfram("sin x ^ 2")           # Power[Sin[x], 2]

Architecture

mathio/
    tokenizer.py          # Custom lexer with keyword splitting & DERIV
    parser.py             # Recursive-descent parser → AST
    ast_nodes.py          # AST node dataclasses
    sympy_executor.py     # AST → SymPy evaluation (default backend)
    wolfram_generator.py  # AST → Wolfram Language code (opt-in)
    converter.py          # Facade: tokenize → parse → execute/generate
    config.py             # Function/constant/keyword mappings
    errors.py             # Exception classes with source-context errors
    __main__.py           # CLI entry point

Metadata

Release files for mathio-py 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mathio-py 0.1.0
File Size Uploaded Provenance Actions
mathio_py-0.1.0.tar.gz 16.1 kB With provenance Details for mathio_py-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mathio-py 0.1.0
File Interpreter ABI Platform Actions
mathio_py-0.1.0-py3-none-any.whl Python 3 none any Details for mathio_py-0.1.0-py3-none-any.whl

Total release size: 30.1 kB

Release files / mathio_py-0.1.0.tar.gz

Download URL mathio_py-0.1.0.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5835da7894ddd8492ef4b5a00ffefac5d3b24b5bc30a941d52f24e7139915321
BLAKE2b-256 checksum
How to use checksums
fc94e91a37363b61deb5595442f459926a9bc87b42f33579f32d0704200ab6b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

Release files / mathio_py-0.1.0-py3-none-any.whl

Download URL mathio_py-0.1.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99ca9e38e300902859db19fe177651567880137dbc1fb9375355ecd8ea2fcc84
BLAKE2b-256 checksum
How to use checksums
8eb24376bee2ed8e12fff7ff4776d2614c0fac068f45cd8062e8162edc6b7616
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

Security for mathio-py 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mathio_py-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page