sympy2hwy
sympy2hwy translates SymPy expressions into Google Highway SIMD function
calls. It emits the explicit function API instead of overloaded C++ operators,
so generated expressions remain usable with sizeless SIMD types such as SVE
and RVV.
from sympy import symbols
from sympy2hwy import hwycode
a, b = symbols("a b")
hwycode(a + b)
# 'hn::Add(a, b)'
Security warning
Never pass untrusted strings to hwycode or the command-line interface.
String inputs are parsed with sympy.sympify. SymPy's string parsing uses
Python evaluation mechanisms and is not a sandbox. A malicious expression can
execute arbitrary Python code with the permissions of the running process.
For input originating outside your trust boundary, do not use this package's string interface or CLI.
Installation
python -m pip install -e .
The project requires Python 3.10 or newer and SymPy 1.14 or newer.
Python API
from sympy2hwy import HighwayPrinter, hwycode
hwycode("x - y / 3")
# 'hn::Sub(x, hn::Mul(hn::Set(d, 0.3333333333333333), y))'
hwycode("exp(x)", use_contrib=True)
# 'hn::Exp(d, x)'
hwycode("exp(x)", use_contrib=True, fast=True)
# 'hn::FastExp(d, x)'
hwycode("x + 2", namespace="project::", tag="df")
# 'project::Add(x, project::Set(df, 2))'
The public function is:
hwycode(
expr,
namespace="hn::",
tag="d",
fast=False,
use_contrib=False,
)
exprmay be a trusted string or a pre-built SymPyExpr.namespaceis emitted exactly as provided, including the trailing::.tagselects Highway overloads and broadcasts numeric constants.use_contrib=Trueenables functions fromhwy/contrib/math.fast=Trueselects availableFast*, approximate reciprocal, and approximate reciprocal-square-root operations. Functions without a fast equivalent remain accurate when contrib support is enabled.
HighwayPrinter exposes the same configuration for direct printer use.
Command line
The CLI is intended only for trusted expressions:
sympy2hwy 'a + b'
sympy2hwy --contrib --fast 'exp(x) + cos(y)'
sympy2hwy --namespace 'project::' --tag df 'x / y'
Supported expressions
Core mode supports symbols, numeric broadcasts, arithmetic, integer powers, square roots, absolute value, min/max, modulo, floor, and ceiling. Contrib mode adds supported trigonometric, inverse, hyperbolic, exponential, logarithmic, error, gamma, cube-root, and general-power functions.
SymPy rationals are converted to binary64 decimal literals before being broadcast. This intentionally loses exact rational precision.
Expressions without a direct Highway translation raise
UnsupportedExpressionError. This includes comparisons, boolean expressions,
Piecewise, matrices, calculus objects, complex values, infinities, NaN, and
unknown functions. The output is a single C++ expression; callers must provide
the required Highway includes, namespace alias, tag, and vector declarations.
Development
python -m pytest
The test suite covers the printer API, core and contrib mappings, fast mode, strict rejection, configuration options, and CLI behavior.
Publishing
Pushing any Git tag, or manually running the Build and publish workflow in GitHub Actions, tests the package, builds both wheel and source distributions, checks their metadata, and publishes them to PyPI.
Publishing uses PyPI Trusted Publishing rather than a stored API token. Before
the first release, configure a trusted publisher for the sympy2hwy PyPI
project with these values:
- Owner and repository: this GitHub repository's owner and name.
- Workflow filename:
publish.yml. - Environment:
pypi.
Create a GitHub environment named pypi; adding required reviewers is strongly
recommended, especially because the workflow supports manual publication. The
version in pyproject.toml must be new on PyPI before triggering a release.
git tag v0.1.0
git push origin v0.1.0
Metadata
Release files for sympy2hwy 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 | Provenance | Actions |
|---|---|---|---|---|
| sympy2hwy-0.1.0.tar.gz | 10.4 kB | With provenance | Details for sympy2hwy-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sympy2hwy-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sympy2hwy-0.1.0-py3-none-any.whl |
Total release size: 18.8 kB
Release files / sympy2hwy-0.1.0.tar.gz
| Download URL | sympy2hwy-0.1.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c14ed2fc435911c8d830dfade5854db901cb9d18af0c93c87f39feeca4a37e5
|
|
BLAKE2b-256 checksum How to use checksums |
5ab7751a530105c4dfe6ce913cbb16b8aa1fa5c1b5167c034b52887fdbe7a364
|
| 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 Jul 18, 2026.
Transparency logRelease files / sympy2hwy-0.1.0-py3-none-any.whl
| Download URL | sympy2hwy-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e1f215b6d59b416761d58ed3030c5b57eac394cb0bc6e56bd6d13305f2923d1
|
|
BLAKE2b-256 checksum How to use checksums |
2873736ca1e9b3ad3db95ab13027c07cd0d4b52991ec8f399643564a061830c1
|
| 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 Jul 18, 2026.
Transparency logSecurity for sympy2hwy 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.
Attestation for sympy2hwy-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 Jul 18, 2026.
Transparency logA 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.