Parse human-typed equation strings into canonical SymPy expressions
Project description
human-to-sympy
Parse human-typed equation strings into canonical SymPy expression strings.
human-to-sympy accepts the kind of math people actually type — ^ for power,
familiar function names, bare identifiers — and returns the corresponding SymPy
expression as a normalized string. It does not perform equivalence comparison;
for that, use eq-equiv.
What it does
- Replaces
^with**. - Splits on
=when present and returns the right-hand side (forgenerate_sympy_rhs*) or both sides (forgenerate_sympy_equation). - Distinguishes function-call sites from bare identifiers and binds them to
sympy.Functionandsympy.Symbolrespectively, while leaving SymPy builtins (pi,E,log,sin, ...) alone. - Returns a typed result object preserving the failure reason on parse error.
API
from human_to_sympy import (
SympyEquationGenerationResult,
SympyGenerationResult,
check_symbols,
generate_sympy_equation,
generate_sympy_rhs,
generate_sympy_rhs_with_error,
)
generate_sympy_rhs(text) -> str | None— convenience accessor for the RHS string.generate_sympy_rhs_with_error(text) -> SympyGenerationResult— same, but preserves the parse error.generate_sympy_equation(text) -> SympyEquationGenerationResult— returns both sides of anlhs = rhsequation.check_symbols(text, variables) -> list[str]— warns when expression free symbols are not declared in the supplied variable list.
Example
from human_to_sympy import generate_sympy_rhs
assert generate_sympy_rhs("Fa = 1 / (2 * pi * Ta)") == "1/(2*pi*Ta)"
assert generate_sympy_rhs("(2*pi*Ta*f)^2") == "(2*pi*Ta*f)**2"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file human_to_sympy-0.1.0.tar.gz.
File metadata
- Download URL: human_to_sympy-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
745d5ecc38137bcf836f5a3c6709518909ef98be2c93c8af78cead44a8dcd2c4
|
|
| MD5 |
11ef01e61d96cdd1551523970b344b47
|
|
| BLAKE2b-256 |
92b471b8d966aaca0545835944fcdc58076fed3773ed42165227f18980a480ad
|
File details
Details for the file human_to_sympy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: human_to_sympy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
122710d13689388f0ccfe18ecd365cc3d7c19d1a2d64154ce8e5708622385c90
|
|
| MD5 |
da825cde62b1a76214140eafae44a346
|
|
| BLAKE2b-256 |
715a08d252ff69f9389a23ef56534820c5f51ca0f587d2ec36bd3b09df8f7d74
|