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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: hsnf-0.3.14.tar.gz
  • Upload date:
  • Size: 20.7 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.14.tar.gz
Algorithm Hash digest
SHA256 0d959d2288ec9ff5331c9c72a1c5a51ae8361e3b70dabdea1ba5863a747241b8
MD5 f2bf8aef786ef95e7233e9bb1e06720c
BLAKE2b-256 11a2929003261442e6378fd6c6b1d6973265410d9ce8f205c074786a4faee961

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hsnf-0.3.14-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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 4b33bd1f464baa54265447664de67c11538b10f61bce3b9fcdddd54f8bd607b1
MD5 b21a4a40ce215d90f7673d0db2e60fc7
BLAKE2b-256 974cf9496975422f1540855839e7756baffb87e4c36370624e4b4879407eb35e

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