HMath
HMath is a mathematics and numerical computing library with Python bindings, written in Haskell. It also provides native Haskell, C, and Wave interfaces.
HMath targets Linux x86-64. The Python distribution is named hmath-python and is imported as hmath. Version 1.0.1 includes the native library and runtime; GHC is not needed to use its Python wheel.
Python quick start
Install the Python package on Linux x86-64:
pip install hmath-python
from hmath import Tensor, add
print(add(2, 3)) # 5.0
with Tensor.matrix([1, 2, 3, 4], 2, 2) as matrix:
with matrix @ matrix as product:
print(product.values()) # [7.0, 10.0, 15.0, 22.0]
Use with to release native resources automatically. Invalid operations raise HMathError. Install hmath-python[numpy,cffi] for optional NumPy and cffi support.
See the documentation for installation requirements, tutorials, API reference, and C/Wave integration.
Features
- Core math: checked scalar operations, numeric types, constants, units, number theory, and polynomials.
- Linear algebra: dense and sparse matrices, decompositions, iterative solvers, and CPU tensors.
- Scientific computing: differentiation, integration, ODE/PDE solvers, optimization, interpolation, FFTs, and signal processing.
- Statistics and learning: reproducible sampling, probability distributions, inference, automatic differentiation, and machine learning primitives.
- Discrete and symbolic math: combinatorics, graphs, numerical data structures, symbolic calculus, and a bounded expression evaluator.
- Applied math: complex numbers, rotations, computational geometry, time series, and numerical image processing.
- Native interface: checked scalar, vector, matrix, and tensor operations; explicit ownership and errors; Python/NumPy and Wave bindings.
- Interchange: typed binary and text arrays, CSV/TSV, Matrix Market, NPY/NPZ, and CPU DLPack.
The Haskell library contains the full numerical API; Python currently exposes scalar addition and binary64 vector, matrix, and tensor construction, arithmetic, and reductions.
Build from source
Requires GHC, Cabal, a C11 compiler, Meson >= 1.3, Ninja, and Python 3. Zlib enables compressed interchange. BLAS/LAPACKE are optional runtime backends; the full spectral test suite needs LAPACKE.
git clone https://github.com/wavefnd/hmath.git
cd hmath
meson setup builddir
meson compile -C builddir
meson test -C builddir --print-errorlogs
This builds builddir/libhmath.so and runs the Haskell, C, and Python tests. Wave tests also run when wavec is available.
Haskell
Save the following as Main.hs in the checkout. Run cabal build lib:hmath, then cabal exec -- runghc -package=hmath Main.hs:
import HMath
main :: IO ()
main = do
print (dotChecked [1, 2, 3 :: Int] [4, 5, 6]) -- Right 32
print $ do
matrix <- fromListChecked 2 2 [1, 2, 3, 4 :: Int]
pure (toList (transposeMatrix matrix)) -- Right [1,3,2,4]
Checked operations return Either MathError for invalid shapes or lengths. More examples are available in examples/haskell.
C and Wave
The C header defines errors, ownership, and runtime lifetime. See the C example and Wave bindings for usage.
Contributing
Report bugs or discuss changes through GitHub issues. Submit pull requests from a fork against master; see ROADMAP.md for planned work.
License
Metadata
Release files for hmath-python 1.0.2
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 |
|---|---|---|---|---|
| hmath_python-1.0.2.tar.gz | 693.9 kB | With provenance | Details for hmath_python-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hmath_python-1.0.2-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details for hmath_python-1.0.2-py3-none-manylinux_2_28_x86_64.whl |
Total release size: 4.7 MB
Release files / hmath_python-1.0.2.tar.gz
| Download URL | hmath_python-1.0.2.tar.gz |
|---|---|
| Size | 693.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a4ec342d71e5c33baa1a5ae868106335a356750b82a5dc9d59c5b47b11cca4e
|
|
BLAKE2b-256 checksum How to use checksums |
246e12f798ed1d231d34be4ab8737d5dbc437462fd3f1b915f061dde5250003d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 28, 2026.
Transparency logRelease files / hmath_python-1.0.2-py3-none-manylinux_2_28_x86_64.whl
| Download URL | hmath_python-1.0.2-py3-none-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
dd3063fe93fccba4b204531cda5792d6be05f0005e6c3c85555b2303b565755a
|
|
BLAKE2b-256 checksum How to use checksums |
72683738006606e3b4aa64e6821e5a1b382f10a425b51d86482c9b09755af6a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 28, 2026.
Transparency logSecurity for hmath-python 1.0.2
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for hmath_python-1.0.2.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 Oct 28, 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.