Skip to main content

A Python module for Smith Normal Form calculations over Z/N rings

Project description

Smith Normal form of Integer matrices mod N (Storjohann)

This is a Python module that follows the deterministic algorithms presented in Arne Storjohann's PhD Dissertation Algorithms for Matrix Canonical Forms (ETH No. 13922, 2000).

It implements the Lemmas and subsequent subroutines that are necessary for calculating the SNF without exponential intermediate values.

It validates against SymPy using a known equivalence between calculating the Smith Normal form of an integer matrix, and then taking mod N, compared to solving it natively in the ring.

Quick Start

from modularsnf import smith_normal_form_mod

S, U, V = smith_normal_form_mod([[2, 4, 0],
                                  [6, 8, 3],
                                  [0, 3, 9]], modulus=36)
# S = U @ A @ V  (mod 36)
# S, U, V are plain Python list[list[int]].

S is the diagonal Smith Normal Form, U and V are unimodular transforms over $\mathbb{Z}/N\mathbb{Z}$. The return order (S, U, V) — diagonal first — follows the SymPy / SageMath convention. Rectangular matrices are supported; S, U, V shapes match the input dimensions.

A matrix is unimodular over $\mathbb{Z}/N\mathbb{Z}$ when $\gcd(\det(M),, N) = 1$, the modular analogue of $|\det(U)| = 1$ over $\mathbb{Z}$.

Lower-level API

For direct access to RingMatrix objects:

from modularsnf.ring import RingZModN
from modularsnf.matrix import RingMatrix
from modularsnf.snf import smith_normal_form

ring = RingZModN(12)
A = RingMatrix(ring, [[2, 4], [6, 8]])
U, V, S = smith_normal_form(A)   # note: (U, V, S) order

For details on the algorithm (band reduction, diagonalization, Storjohann's lemmas), see docs/algorithm.md.

Development Workflow (modern Python)

This repository supports both standard pip workflows and uv workflows.

Using uv

uv venv
uv sync --extra dev
uv run pytest
uv run ruff check .

Using pip

python -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
pytest
ruff check .

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

modularsnf-0.3.0.tar.gz (88.5 kB view details)

Uploaded Source

Built Distributions

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

modularsnf-0.3.0-cp310-abi3-win_arm64.whl (219.1 kB view details)

Uploaded CPython 3.10+Windows ARM64

modularsnf-0.3.0-cp310-abi3-win_amd64.whl (235.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

modularsnf-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

modularsnf-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

modularsnf-0.3.0-cp310-abi3-macosx_11_0_arm64.whl (343.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

modularsnf-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl (357.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file modularsnf-0.3.0.tar.gz.

File metadata

  • Download URL: modularsnf-0.3.0.tar.gz
  • Upload date:
  • Size: 88.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modularsnf-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a5ad5c28de9fd1c1da77c774f4f9a1f6398ea43bd696b2701a2a73ae51794772
MD5 5e935824279d6ebd8ac6bd88d57b4b3f
BLAKE2b-256 792393dfa6f9372f4063738df7ed84ef036c7a12f52f216c81729edb5c4fb469

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.3.0.tar.gz:

Publisher: publish.yml on events555/modularsnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modularsnf-0.3.0-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: modularsnf-0.3.0-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 219.1 kB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modularsnf-0.3.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1c5faf90be6e03455b2b65fd748d2c9e1e8af52e08e22a94363510492b6216c0
MD5 3782518fc31e4eafa53d710149f09b5f
BLAKE2b-256 48f0873bf4cde9beb6005e5e6438ffb6946f070dba089fc5e1664fdffd16ba1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.3.0-cp310-abi3-win_arm64.whl:

Publisher: publish.yml on events555/modularsnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modularsnf-0.3.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: modularsnf-0.3.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 235.9 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modularsnf-0.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 58f78d86e845ddcd3b1d829d89f1fa9cb2a2c162c18449ee8a394d65a7fd67f7
MD5 eaf7564381159360f4585954d0631e90
BLAKE2b-256 b29966583a5a7a9787235afe91f39860b39986ddfdefcbc53f350cbe7ca913d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.3.0-cp310-abi3-win_amd64.whl:

Publisher: publish.yml on events555/modularsnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modularsnf-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for modularsnf-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 acdeabc920a99b326861505c668659c1798d1d27237b57691e7f6a4b91cccbe7
MD5 d5f889adc2c2e2845231f274ff091e2b
BLAKE2b-256 0063d8a6f596f7efb63f580eb0f3579b05100c78374f7b326535fab2c86e2e45

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on events555/modularsnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modularsnf-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for modularsnf-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 69e549b8e19d2f0a502270a5d48b35fe64cc6f68fb6f7a10c46c9b64815691f3
MD5 e2d2d82302ef0ef05f81ae8649c0e2b7
BLAKE2b-256 118497821928cb348cffd599bcdd6a6dd3d9aa53c89cf8b873d462f3a57b2bce

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on events555/modularsnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modularsnf-0.3.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for modularsnf-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 764985e20eb459a82b400cc7ac897f357f5c6f7097eb1af1848f50f9db1d7a7c
MD5 b5060cf41b54b52fcbbe1825359e6c5e
BLAKE2b-256 a7fe7b9c3c780909af61da86fa3117fe7f84cb5383ba87fa16a9dd20effd7e3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.3.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on events555/modularsnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modularsnf-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for modularsnf-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 09c95f9acfd41b05c2973e987392b2da05a09cdf58bc790862d1a986c08a798e
MD5 d2e3f9f12caff6fc00719f2543827c19
BLAKE2b-256 aaf6d4adb5524cfa50a5ca221092149072f58cf5cdb12e1a12fab1a284e88851

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: publish.yml on events555/modularsnf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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