Computing Hermite normal form and Smith normal form.
Project description
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
pip install -e .[dev,docs]
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).
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.16.tar.gz
(21.2 kB
view details)
Built Distribution
hsnf-0.3.16-py3-none-any.whl
(11.1 kB
view details)
File details
Details for the file hsnf-0.3.16.tar.gz
.
File metadata
- Download URL: hsnf-0.3.16.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae4f99c89076f734969d6aedaa0d3390f667929a2aa4862c7e03c067cd063207 |
|
MD5 | 01ab86dd8c2e7b3a4cc6c80454787322 |
|
BLAKE2b-256 | 54887461240d61cfaa7301163e6fc6b78e8ac5ced3dbda2b708476cec2b6978b |
File details
Details for the file hsnf-0.3.16-py3-none-any.whl
.
File metadata
- Download URL: hsnf-0.3.16-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 906d0ad4af691e1c45e51fd6c99d8b3ed0be1179cbcc21cbd4dda11cc97dc1e8 |
|
MD5 | ed345f6966cac753c11b0f29d100982e |
|
BLAKE2b-256 | b590f6f56e32a71a091ff0afa377f92a97a2a3804dc8ab8210134a94144e9bf8 |