Skip to main content

Computing Hermite normal form and Smith normal form.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hsnf-0.4.0.tar.gz (129.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hsnf-0.4.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file hsnf-0.4.0.tar.gz.

File metadata

  • Download URL: hsnf-0.4.0.tar.gz
  • Upload date:
  • Size: 129.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hsnf-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e12875c4ed431637530987ff96b1e02d748ad09a648ec12489e0176e52f8f4d9
MD5 e576da20a2cd0ca00ec78f26e9572a88
BLAKE2b-256 b8f5b7c2a7dc01101f60d994a2cbd99580428de20753902e7b778951f466b419

See more details on using hashes here.

File details

Details for the file hsnf-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: hsnf-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hsnf-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db370524771e6d412ef9f5397a3d64f7e698d97133770fcea01516cfc8054ba4
MD5 704c1464510ebe2b6887b6e192b32d63
BLAKE2b-256 a20cd85b53a499bb62050a38acafb5f901468cffddb42f99049a8d7efe9437e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page