Skip to main content

Smith Normal form of Integer matrices mod N (Storjohann)

A Rust implementation (with a thin Python binding) of 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. The algorithms live in the Rust modularsnf crate; the Python package is a thin wrapper over the native extension.

Correctness is validated in the Rust test suite: random inputs are checked against the Smith form contract ($S = UAV$, divisibility chain, unimodular transforms), and the default Storjohann path is cross-checked against the independent CRT path.

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}$.

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

Alternative: CRT fast path (experimental)

smith_normal_form_mod uses Storjohann's band reduction, which works for any modulus N >= 2. For the small-modulus, large-matrix regime there is a second, experimental algorithm that is several times faster: a CRT-based path that factors N = prod p^e, solves the SNF over each local ring Z/p^e by valuation-pivoted elimination, and recombines via the Chinese Remainder Theorem.

from modularsnf import crt_snf

S, U, V = crt_snf([[2, 4, 0],
                   [6, 8, 3],
                   [0, 3, 9]], modulus=36)
# Same (S, U, V) contract as smith_normal_form_mod; S = U @ A @ V (mod 36).

It requires the prime factorization of N; pass it explicitly as factors=[(p, e), ...] to amortize factoring across many calls with the same modulus. Prefer smith_normal_form_mod for general moduli. See docs/crt.md for the design and correctness basis.

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 .

Metadata

Release files for modularsnf 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modularsnf 0.5.0
File Size Uploaded Provenance Actions
modularsnf-0.5.0.tar.gz 29.5 kB With provenance Details for modularsnf-0.5.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for modularsnf 0.5.0
File Actions
modularsnf-0.5.0-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for modularsnf-0.5.0-cp310-abi3-win_arm64.whl
modularsnf-0.5.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for modularsnf-0.5.0-cp310-abi3-win_amd64.whl
modularsnf-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details for modularsnf-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
modularsnf-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details for modularsnf-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl
modularsnf-0.5.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for modularsnf-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
modularsnf-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for modularsnf-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 7.0 MB

Release files / modularsnf-0.5.0.tar.gz

Download URL modularsnf-0.5.0.tar.gz
Size 29.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e639a0b9cd33f033c5603e82a619d2216606bad55ae310c3d4dbec52808a3dd8
BLAKE2b-256 checksum
How to use checksums
2315575495bdef2527eaabcc3c12ab451c168ea8ff32f965efd085567579df9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Release files / modularsnf-0.5.0-cp310-abi3-win_arm64.whl

Download URL modularsnf-0.5.0-cp310-abi3-win_arm64.whl
Size 210.3 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
565bf8f55779b7c8d4c6be26ecdd8fd8395ca629116820fb22a62d3c8e6d9dd2
BLAKE2b-256 checksum
How to use checksums
dc38b5eae6c2a5fe42c8ba89a0ae45008ec9992a109828bf06dfa90fc1bd31e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Release files / modularsnf-0.5.0-cp310-abi3-win_amd64.whl

Download URL modularsnf-0.5.0-cp310-abi3-win_amd64.whl
Size 228.4 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
bd55ea2024da85ff8bfa2d954f8ea0805c3d20e51bc62c80892466d1db7a9132
BLAKE2b-256 checksum
How to use checksums
68735a52c3c85fef723621d22fbbdf4f8ccac38f5a2f174f186ad1338e844764
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Release files / modularsnf-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL modularsnf-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 3.1 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
41808b0534d64737fcd2ff85eb50321c5695efd60d30f054dc15722792257860
BLAKE2b-256 checksum
How to use checksums
9f903a6b814c763f138b6952134535fa3cc25c98fa918fb04785ad550a6a7891
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Release files / modularsnf-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL modularsnf-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 2.7 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
4431f13a59359e6d4fd4b2499eea4c1a167e321715e331d5ffc84be312d5d88b
BLAKE2b-256 checksum
How to use checksums
3da152e192461cdd1a58540887d65fae28a80e73bbed9650ec464c41bfd831da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Release files / modularsnf-0.5.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL modularsnf-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Size 334.5 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8987cb1b9ecd6cd616930254b53d519414153345e73addd78a71f9f4f9f924a5
BLAKE2b-256 checksum
How to use checksums
5adb21d2dd8021c16232f9e90090236b7eca89266467437c57ec3807a2c4d47c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Release files / modularsnf-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL modularsnf-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 346.7 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
820ccdbc2d1257ee8e4a0a6121b10fe82dba6ad30e4f59d364029bd2fcaf65e0
BLAKE2b-256 checksum
How to use checksums
f2ae12419e27ad6e4c9a1c03e6baca7163f6c1c0c2090e702300a2585c6ab6b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

Security for modularsnf 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for modularsnf-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page