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

Uploaded Source

Built Distribution

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

modularsnf-0.1.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for modularsnf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 53e4b7abedb05cf1a0974001f3364b30f6ff51489f6d88499d10831c74516999
MD5 ab244155d65ab7bf3a6d835c99a4466c
BLAKE2b-256 f712f73ac8d6521ce623362c1c7dd2d2cf531ef3bbc5ea80336f52b48b9a659f

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: modularsnf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modularsnf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80b217424e21d4d824b9b8eba33964787f2b7f93631ed11d61a224ba6cf534b5
MD5 a720f28e825ac85e0b310a947c6a865b
BLAKE2b-256 f621408ebc7dc12fcfd01454388c5a93c4146b2c5553f48043bb01103e571712

See more details on using hashes here.

Provenance

The following attestation bundles were made for modularsnf-0.1.0-py3-none-any.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