Skip to main content

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"

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)

Source distribution for human-to-sympy 0.1.0
File Size Uploaded
human_to_sympy-0.1.0.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for human-to-sympy 0.1.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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