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.

The 1.0.0 release targets Linux x86-64. The Python distribution is named hmath-python and is imported as hmath.

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.

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.0.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.0.0
File Size Uploaded Provenance Actions
hmath_python-1.0.0.tar.gz 12.4 kB With provenance Details for hmath_python-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hmath-python 1.0.0
File Interpreter ABI Platform Actions
hmath_python-1.0.0-py3-none-any.whl Python 3 none any Details for hmath_python-1.0.0-py3-none-any.whl

Total release size: 25.3 kB

Release files / hmath_python-1.0.0.tar.gz

Download URL hmath_python-1.0.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c945451b03aabe5338c918bfcba69a9479d4e1cb4d3333d88415ccabb301b82d
BLAKE2b-256 checksum
How to use checksums
50b2bd3c358521450431480911430c156618efcf89718bb31752307319d4ae0f
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 log

Release files / hmath_python-1.0.0-py3-none-any.whl

Download URL hmath_python-1.0.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47c3a92006167b4ad46be83a375fc83dc170f3e62cdc7f206d65384922916186
BLAKE2b-256 checksum
How to use checksums
55af7e0554cf10adf0f81df0d60da9c0e051b1a028a0921cdfdfb222f91b88f6
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 log

Security for hmath-python 1.0.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.0.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 Oct 28, 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