Skip to main content

hsnf

testing Documentation Status pre-commit.ci status codecov MIT License PyPI - Python Version PyPI version PyPI - Downloads

Computing Hermite normal form and Smith normal form with transformation matrices.

Usage

import numpy as np
from hsnf import column_style_hermite_normal_form, row_style_hermite_normal_form, smith_normal_form

# Integer matrix to be decomposed
M = np.array(
    [
        [-6, 111, -36, 6],
        [5, -672, 210, 74],
        [0, -255, 81, 24],
    ]
)

# Smith normal form
D, L, R = smith_normal_form(M)
"""
D = array([
[   1    0    0    0]
[   0    3    0    0]
[   0    0 2079    0]])
"""
assert np.allclose(L @ M @ R, D)
assert np.around(np.abs(np.linalg.det(L))) == 1  # unimodular
assert np.around(np.abs(np.linalg.det(R))) == 1  # unimodular

# Row-style hermite normal form
H, L = row_style_hermite_normal_form(M)
"""
H = array([
[     1      0    420  -2522]
[     0      3   1809 -10860]
[     0      0   2079 -12474]])
"""
assert np.allclose(L @ M, H)
assert np.around(np.abs(np.linalg.det(L))) == 1  # unimodular

# Column-style hermite normal form
H, R = column_style_hermite_normal_form(M)
"""
H = array([
[   3    0    0    0]
[   0    1    0    0]
[1185  474 2079    0]])
"""
assert np.allclose(np.dot(M, R), H)
assert np.around(np.abs(np.linalg.det(R))) == 1  # unimodular

Installation

hsnf works with Python3.8+ and can be installed via PyPI:

pip install hsnf

or in local:

git clone git@github.com:lan496/hsnf.git
cd hsnf
uv sync --all-extras

References

Metadata

Release files for hsnf 0.4.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 hsnf 0.4.0
File Size Uploaded
hsnf-0.4.0.tar.gz 129.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hsnf 0.4.0
File Interpreter ABI Platform
hsnf-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 147.2 kB

Release files / hsnf-0.4.0.tar.gz

Download URL hsnf-0.4.0.tar.gz
Size 129.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e12875c4ed431637530987ff96b1e02d748ad09a648ec12489e0176e52f8f4d9
BLAKE2b-256 checksum
How to use checksums
b8f5b7c2a7dc01101f60d994a2cbd99580428de20753902e7b778951f466b419
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / hsnf-0.4.0-py3-none-any.whl

Download URL hsnf-0.4.0-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db370524771e6d412ef9f5397a3d64f7e698d97133770fcea01516cfc8054ba4
BLAKE2b-256 checksum
How to use checksums
a20cd85b53a499bb62050a38acafb5f901468cffddb42f99049a8d7efe9437e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.16

2 release files

0.3.15

2 release files

0.3.14

2 release files

0.3.13

2 release files

0.3.12

2 release files

0.3.8

2 release files

0.3.7

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