Skip to main content

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 (for generate_sympy_rhs*) or both sides (for generate_sympy_equation).
  • Distinguishes function-call sites from bare identifiers and binds them to sympy.Function and sympy.Symbol respectively, 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 an lhs = rhs equation.
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

human_to_sympy-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

human_to_sympy-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

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

Hashes for human_to_sympy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 745d5ecc38137bcf836f5a3c6709518909ef98be2c93c8af78cead44a8dcd2c4
MD5 11ef01e61d96cdd1551523970b344b47
BLAKE2b-256 92b471b8d966aaca0545835944fcdc58076fed3773ed42165227f18980a480ad

See more details on using hashes here.

File details

Details for the file human_to_sympy-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for human_to_sympy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 122710d13689388f0ccfe18ecd365cc3d7c19d1a2d64154ce8e5708622385c90
MD5 da825cde62b1a76214140eafae44a346
BLAKE2b-256 715a08d252ff69f9389a23ef56534820c5f51ca0f587d2ec36bd3b09df8f7d74

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