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.4.0.tar.gz (34.4 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.4.0-cp310-abi3-win_arm64.whl (217.5 kB view details)

Uploaded CPython 3.10+Windows ARM64

modularsnf-0.4.0-cp310-abi3-win_amd64.whl (233.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

modularsnf-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl (3.1 MB view details)

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

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

modularsnf-0.4.0-cp310-abi3-macosx_11_0_arm64.whl (345.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

modularsnf-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl (360.4 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for modularsnf-0.4.0.tar.gz
Algorithm Hash digest
SHA256 26712e99104ef3c8399a9591ccea45b5d83ec6f6c22ef02a57c00e57dcd78ced
MD5 e7f41b470e9a2faabb6722471f5c5895
BLAKE2b-256 49f8b9e0078e55cac93d857d465f5f60859b4fd1da7aad1381d3944249afba30

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.4.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.4.0-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: modularsnf-0.4.0-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 217.5 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.4.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 f7861fe9f2cfaebb3fc848ee398397195af0db52d7e949125a135518130162a1
MD5 e317f56a681b53db00333bbeed6df52f
BLAKE2b-256 51e387f87efbe4ac4e7af7f159f0b24b8eaa9bb69004a7087654c0c7c33943cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.4.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.4.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: modularsnf-0.4.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 233.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.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 537c47144e84d148d55acae3fbf70a52158ab597f10c3fea715936c02bb1bf0f
MD5 42e313686ef1259948df673f7eb9fa66
BLAKE2b-256 5a0625a0a4bbf305afdc454e295a0653e5ec1070dac3b62c17e9580e882c4368

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.4.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.4.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for modularsnf-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 df5af987f73561528f26da461e6f00d1fa491e808c288fbd1ab0a6e544f6b778
MD5 464eda61a0c21ef2daf7cf18b273671e
BLAKE2b-256 5eb4e6a7e40fd18b4752c2fc6f56b53d0d2289f3e85666a87342e6a1602ec05b

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.4.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.4.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for modularsnf-0.4.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dd3ee0deed2a0daaa6797cdd94fbae94af9fa691466bc3f36eb856bc8fb795a3
MD5 b4e204af1cd949d9386c78c12eefc196
BLAKE2b-256 a653a03406da3ac6fe9026e235a5e46387db93068d220d2b8b99089e894efc1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.4.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.4.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for modularsnf-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef7cb7b938b863535e6e7587e84459855c6fe8649ed4c54789446ec69999b630
MD5 6815bf7408ad0e271309124cbc92b5ac
BLAKE2b-256 a1b75fb23e4d430c06f418f0bc3caf024c0ee3ea6d5ab342d6a00d1cf3b5b8bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.4.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.4.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for modularsnf-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ac2879fae0dd7e1c4d54589da7780a4db9fb06e606bebbd1d89c96ee30494927
MD5 57139c05e65e4ef77bbee8a08bb5c634
BLAKE2b-256 094ccce98c72d80a857be44efec91362239d11125ea791d5e3168f8e3e74e9ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.4.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