Latin Rectangles
Exact counts for extending a Latin rectangle: append rows that use every symbol once and never repeat a symbol in a column. The library combines specialized two-row methods based on permutation cycles and Touchard's identity with general k-row counting on forbidden bipartite graphs.
Read the full mathematical explanation, animation and diagrams.
Try it
Requires Python 3.12+. Install with uv add latin-rectangles or
pip install latin-rectangles. Try the illustrated example with
uvx latin-rectangles --c "2,2,4".
from latin_rectangles import count_extensions, count_extensions_from_cycle_type
# Two fixed rows; the relative permutation has cycle lengths 2, 2 and 4.
count_extensions_from_cycle_type([2, 2, 4]) # 4744 legal third rows
# Three explicit rows; a leading zero marks the 1-indexed representation.
rows = [[0, 1, 2, 3, 4], [0, 2, 1, 4, 3], [0, 3, 4, 1, 2]]
count_extensions(rows) # 1 legal fourth row
Methods and scope
The cycle-type API offers auto, touchard, rook and rook_ntt methods for
one added row. Counts use integers throughout. The optional transform path
uses exact NTT/CRT reconstruction with schoolbook fallback, not floating-point
FFT. The favorable method depends on structure, coefficient size and cache
state.
The two-row reduction implements Touchard's 1934 counting identity. For general starting rectangles, component matching polynomials and inclusion-exclusion count the next rows. Multiple added rows are ordered and use direct recursion, intended for small-n exact work; the general matching computation is exponential in the largest forbidden component.
- Methods, derivation and attribution
- Benchmark workloads and reproduction
- Independent correctness checks
- Changelog
License
MIT.
Metadata
Release files for latin-rectangles 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| latin_rectangles-0.3.3.tar.gz | 1.3 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| latin_rectangles-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.3 MB
Release files / latin_rectangles-0.3.3.tar.gz
| Download URL | latin_rectangles-0.3.3.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bdaa02f4c065cff52ca90432a88811bf53bd5e5a1cd440290fb4fb09864fad8a
|
|
BLAKE2b-256 checksum How to use checksums |
b4ed01cc3a7fa90efc857f13d2af595260027cf8d4c6f8730b4a3af0f8005404
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / latin_rectangles-0.3.3-py3-none-any.whl
| Download URL | latin_rectangles-0.3.3-py3-none-any.whl |
|---|---|
| Size | 19.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c43c13bbd2afa19ea59cb56774a77563c6399289ef3c879bcb6d3c15e6e3ec6
|
|
BLAKE2b-256 checksum How to use checksums |
011d9cc6e7249b2c030c265009b2a255fd475012cf306f0c1ebeb7353abea058
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|