Skip to main content

Computing Hermite normal form and Smith normal form.

Project description

hsnf

testing 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 .

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

Uploaded Source

Built Distribution

hsnf-0.3.8-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hsnf-0.3.8.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for hsnf-0.3.8.tar.gz
Algorithm Hash digest
SHA256 1f7c4de298aba3141d8dc5cd338b6319a59301a791832183e83e512a76547f3c
MD5 472a825300013ccc35e53ab72336a8d7
BLAKE2b-256 f98c3067a53bbf455be8ccf49350e3fdddc3305ee0a52a5f1b2b5ad753e92f76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hsnf-0.3.8-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for hsnf-0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0f14750f309f50167aff73a5019f0221db3e2699dca85cd668e9f6ffe5ef7ae9
MD5 4c989b598c2e9222c78b30322dce9d77
BLAKE2b-256 c649ed94f2964673db26fb02609ad22d3af59804de70341d9a661ab08cad8dac

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