Skip to main content

Computing Hermite normal form and Smith normal form.

Project description

hsnf

testing 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
pip install -e .[dev,docs]

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.3.15.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

hsnf-0.3.15-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hsnf-0.3.15.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hsnf-0.3.15.tar.gz
Algorithm Hash digest
SHA256 c5cef2a0de42d0bf28d8e7fd70a683830731a8fb238df34c1de0e72a704c7a8c
MD5 32747f06aa2358aa243f53f9d91de11a
BLAKE2b-256 fdf3bafa947cd8695682d194f3c15c66cefe7969fcf2afda1b237aa251ad6d5f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hsnf-0.3.15-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hsnf-0.3.15-py3-none-any.whl
Algorithm Hash digest
SHA256 add14603134ca82324283078123e618ece88e812e5412a4752ccfbfeb0c78729
MD5 6ff239ab5b649f78373a080f707b4066
BLAKE2b-256 8c216f716de08db601d64775576a7201e47a5106d3373f4b96c006ea2521d41f

See more details on using hashes here.

Supported by

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