A Python module for Smith Normal Form calculations over Z/N rings
Project description
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 .
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modularsnf-0.5.0.tar.gz.
File metadata
- Download URL: modularsnf-0.5.0.tar.gz
- Upload date:
- Size: 29.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e639a0b9cd33f033c5603e82a619d2216606bad55ae310c3d4dbec52808a3dd8
|
|
| MD5 |
9631ee800c64ceac15057394c25f98cb
|
|
| BLAKE2b-256 |
2315575495bdef2527eaabcc3c12ab451c168ea8ff32f965efd085567579df9e
|
Provenance
The following attestation bundles were made for modularsnf-0.5.0.tar.gz:
Publisher:
publish.yml on events555/modularsnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularsnf-0.5.0.tar.gz -
Subject digest:
e639a0b9cd33f033c5603e82a619d2216606bad55ae310c3d4dbec52808a3dd8 - Sigstore transparency entry: 1738361568
- Sigstore integration time:
-
Permalink:
events555/modularsnf@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/events555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Trigger Event:
push
-
Statement type:
File details
Details for the file modularsnf-0.5.0-cp310-abi3-win_arm64.whl.
File metadata
- Download URL: modularsnf-0.5.0-cp310-abi3-win_arm64.whl
- Upload date:
- Size: 210.3 kB
- Tags: CPython 3.10+, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
565bf8f55779b7c8d4c6be26ecdd8fd8395ca629116820fb22a62d3c8e6d9dd2
|
|
| MD5 |
d791d1c379abe6166e969a9b4f29c176
|
|
| BLAKE2b-256 |
dc38b5eae6c2a5fe42c8ba89a0ae45008ec9992a109828bf06dfa90fc1bd31e7
|
Provenance
The following attestation bundles were made for modularsnf-0.5.0-cp310-abi3-win_arm64.whl:
Publisher:
publish.yml on events555/modularsnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularsnf-0.5.0-cp310-abi3-win_arm64.whl -
Subject digest:
565bf8f55779b7c8d4c6be26ecdd8fd8395ca629116820fb22a62d3c8e6d9dd2 - Sigstore transparency entry: 1738361696
- Sigstore integration time:
-
Permalink:
events555/modularsnf@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/events555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Trigger Event:
push
-
Statement type:
File details
Details for the file modularsnf-0.5.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: modularsnf-0.5.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 228.4 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd55ea2024da85ff8bfa2d954f8ea0805c3d20e51bc62c80892466d1db7a9132
|
|
| MD5 |
db64ec2bd39489a77360bb59ad44840e
|
|
| BLAKE2b-256 |
68735a52c3c85fef723621d22fbbdf4f8ccac38f5a2f174f186ad1338e844764
|
Provenance
The following attestation bundles were made for modularsnf-0.5.0-cp310-abi3-win_amd64.whl:
Publisher:
publish.yml on events555/modularsnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularsnf-0.5.0-cp310-abi3-win_amd64.whl -
Subject digest:
bd55ea2024da85ff8bfa2d954f8ea0805c3d20e51bc62c80892466d1db7a9132 - Sigstore transparency entry: 1738361806
- Sigstore integration time:
-
Permalink:
events555/modularsnf@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/events555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Trigger Event:
push
-
Statement type:
File details
Details for the file modularsnf-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: modularsnf-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41808b0534d64737fcd2ff85eb50321c5695efd60d30f054dc15722792257860
|
|
| MD5 |
390a8f465556ce568fadf57ede4e3d39
|
|
| BLAKE2b-256 |
9f903a6b814c763f138b6952134535fa3cc25c98fa918fb04785ad550a6a7891
|
Provenance
The following attestation bundles were made for modularsnf-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on events555/modularsnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularsnf-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
41808b0534d64737fcd2ff85eb50321c5695efd60d30f054dc15722792257860 - Sigstore transparency entry: 1738361776
- Sigstore integration time:
-
Permalink:
events555/modularsnf@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/events555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Trigger Event:
push
-
Statement type:
File details
Details for the file modularsnf-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: modularsnf-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4431f13a59359e6d4fd4b2499eea4c1a167e321715e331d5ffc84be312d5d88b
|
|
| MD5 |
09b7f5c9c51c28d297092e7590d7284f
|
|
| BLAKE2b-256 |
3da152e192461cdd1a58540887d65fae28a80e73bbed9650ec464c41bfd831da
|
Provenance
The following attestation bundles were made for modularsnf-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl:
Publisher:
publish.yml on events555/modularsnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularsnf-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
4431f13a59359e6d4fd4b2499eea4c1a167e321715e331d5ffc84be312d5d88b - Sigstore transparency entry: 1738361739
- Sigstore integration time:
-
Permalink:
events555/modularsnf@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/events555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Trigger Event:
push
-
Statement type:
File details
Details for the file modularsnf-0.5.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: modularsnf-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 334.5 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8987cb1b9ecd6cd616930254b53d519414153345e73addd78a71f9f4f9f924a5
|
|
| MD5 |
4f277aaaff3d58f6cfdff63ca8f87dee
|
|
| BLAKE2b-256 |
5adb21d2dd8021c16232f9e90090236b7eca89266467437c57ec3807a2c4d47c
|
Provenance
The following attestation bundles were made for modularsnf-0.5.0-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
publish.yml on events555/modularsnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularsnf-0.5.0-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
8987cb1b9ecd6cd616930254b53d519414153345e73addd78a71f9f4f9f924a5 - Sigstore transparency entry: 1738361672
- Sigstore integration time:
-
Permalink:
events555/modularsnf@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/events555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Trigger Event:
push
-
Statement type:
File details
Details for the file modularsnf-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: modularsnf-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 346.7 kB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
820ccdbc2d1257ee8e4a0a6121b10fe82dba6ad30e4f59d364029bd2fcaf65e0
|
|
| MD5 |
3e4c4ce2e4d4b2dd8ad2186ab2b75bc7
|
|
| BLAKE2b-256 |
f2ae12419e27ad6e4c9a1c03e6baca7163f6c1c0c2090e702300a2585c6ab6b8
|
Provenance
The following attestation bundles were made for modularsnf-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl:
Publisher:
publish.yml on events555/modularsnf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularsnf-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
820ccdbc2d1257ee8e4a0a6121b10fe82dba6ad30e4f59d364029bd2fcaf65e0 - Sigstore transparency entry: 1738361625
- Sigstore integration time:
-
Permalink:
events555/modularsnf@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/events555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7eda45d334c96f1b168b748dd27e1cddcaa26711 -
Trigger Event:
push
-
Statement type: