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"
Metadata
Release files for human-to-sympy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| human_to_sympy-0.1.0.tar.gz | 9.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| human_to_sympy-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.2 kB
Release files / human_to_sympy-0.1.0.tar.gz
| Download URL | human_to_sympy-0.1.0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
745d5ecc38137bcf836f5a3c6709518909ef98be2c93c8af78cead44a8dcd2c4
|
|
BLAKE2b-256 checksum How to use checksums |
92b471b8d966aaca0545835944fcdc58076fed3773ed42165227f18980a480ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.8
|
Release files / human_to_sympy-0.1.0-py3-none-any.whl
| Download URL | human_to_sympy-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
122710d13689388f0ccfe18ecd365cc3d7c19d1a2d64154ce8e5708622385c90
|
|
BLAKE2b-256 checksum How to use checksums |
715a08d252ff69f9389a23ef56534820c5f51ca0f587d2ec36bd3b09df8f7d74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.8
|