hsnf
Computing Hermite normal form and Smith normal form with transformation matrices.
- Document: https://hsnf.readthedocs.io/en/latest/
- Document(develop): https://lan496.github.io/hsnf/develop
- Github: https://github.com/lan496/hsnf
- PyPI: https://pypi.org/project/hsnf
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
- http://www.dlfer.xyz/post/2016-10-27-smith-normal-form/
- I appreciate Dr. D. L. Ferrario's instructive blog post and his approval for referring his scripts.
- CSE206A: Lattices Algorithms and Applications (Spring 2014)
- Henri Cohen, A Course in Computational Algebraic Number Theory (Springer-Verlag, Berlin, 1993).
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hsnf-0.4.0.tar.gz | 129.1 kB | Without provenance | Details for hsnf-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hsnf-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for hsnf-0.4.0-py3-none-any.whl |
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
|
Security for hsnf 0.4.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.