Skip to main content

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

Mozilla Public License 2.0.

Metadata

Release files for hmath-python 1.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 hmath-python 1.1.0
File Size Uploaded Provenance Actions
hmath_python-1.1.0.tar.gz 2.1 MB With provenance Details for hmath_python-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hmath-python 1.1.0
File Interpreter ABI Platform Actions
hmath_python-1.1.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for hmath_python-1.1.0-py3-none-manylinux_2_28_x86_64.whl

Total release size: 16.0 MB

Release files / hmath_python-1.1.0.tar.gz

Download URL hmath_python-1.1.0.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
0d482ceafb1f38dd88e65719651663c25a086d8023ad90926ee0448c87bf4459
BLAKE2b-256 checksum
How to use checksums
467d82094c954c023a0bb34348c408a805818040494f619131f883643219a3d5
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 Nov 2, 2026.

Transparency log

Release files / hmath_python-1.1.0-py3-none-manylinux_2_28_x86_64.whl

Download URL hmath_python-1.1.0-py3-none-manylinux_2_28_x86_64.whl
Size 13.9 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
c0a0e0a3cdf87ff972000e6bc92a2471f4b2a8c5a5f305ad125a1340236c6302
BLAKE2b-256 checksum
How to use checksums
fea6ab98f7ebf5a2a66d6ffa1e752eee37f05d477cf76d2fd5ea39d640602b00
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 Nov 2, 2026.

Transparency log

Security for hmath-python 1.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hmath_python-1.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 Nov 2, 2026.

Transparency log

A 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.

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