Lexicographic unranking with cyclic offset bans: fixed-set algorithms and a uniform counting barrier

Kagey asked whether permutations that avoid a finite set of cyclic offsets can be efficiently unranked in ordinary lexicographic order. The answer depends on how the offsets are supplied. Every fixed finite set admits polynomial-time ranking and unranking. With an arbitrary set supplied as input, deterministic polynomial-time unranking exists if and only if \(\mathrm{FP}=\#\mathrm P\), even when the algorithm is required to answer only at valid ranks. Here polynomial time is measured in \(n\) and the bit lengths of the supplied inputs. The equality means that every \(\#\mathrm P\) counting function is computable in deterministic polynomial time. Kagey, §6.1, Definition 38 and Open Question 40 For \(n\ge 1\), write \([n]=\{1,\ldots,n\}\). A permutation \(\pi\) is legal for a finite set \(S\subset\mathbb Z\) if \(\pi(i)-i\not\equiv s\pmod n\) for every \(i\in[n]\) and \(s\in S\). Ranks start at zero and compare the one-line lists \((\pi(1),\ldots,\pi(n))\) at their first differing entry. To count the completions \(C(p)\) of a proposed prefix \(p\) of length \(\ell\le n\), return zero if an entry lies outside \([n]\), repeats a value or violates an offset ban. For a valid prefix, delete its assigned rows and used columns from the bipartite graph whose edges are the forbidden row–value pairs. If \(r_k\) counts the size-\(k\) matchings in the remaining graph, with \(r_0=1\), rook inclusion–exclusion gives \[C(p)=\sum_{k=0}^{n-\ell}(-1)^k r_k(n-\ell-k)!. \] For \(S=\varnothing\), this is simply \((n-\ell)!\). For nonempty \(S\), set \(D=\max S-\min S\). To compute the matching counts, use coordinates \(0,\ldots,n-1\) and shift all columns by \(-\min S\) modulo \(n\), including the coordinates of those deleted by the prefix. Each surviving forbidden edge now goes from row \(i\) to column \(i+d\bmod n\) for some \(d\in\{s-\min S:s\in S\}\). Coincident residues give a single edge. Sweep the rows in order. At each cut, keep the set of already used columns with neighbours on both sides of the cut, together with a polynomial for each such set. Start with polynomial \(1\) for the empty set. At the next row, either choose no edge or choose an edge to an unused surviving neighbour, multiplying the polynomial by \(z\) when an edge is chosen. Keep only used columns with neighbours on both sides of the new cut and add polynomials that reach the same state. The final polynomial is \(\sum_k r_kz^k\), where the formal variable \(z\) records the number of chosen edges. For \(D<n\), a column live after row \(i\) must lie among the first \(D\) columns, which receive all wrapped edges, or have a coordinate from \(i+1\) through \(i+D\). Thus at most \(\min(n,2D)\) columns need to be tracked, also when earlier assignments leave holes in the graph. Counting, ranking and unranking take \(2^{\min(n,2D)}\operatorname{poly}(n,\operatorname{size}(S))\) bit operations, where \(\operatorname{size}(S)\) is the bit length of the offset list. Ranking sums the completion counts of lexicographically earlier choices at each position. Unranking tries unused values in increasing order in the original coordinates, subtracting each skipped block's count until the requested rank falls within a block. Each procedure needs at most \(n^2\) prefix counts. For exact uniform sampling, if \(C(\varnothing)>0\), draw a uniform integer from \(0\) to \(C(\varnothing)-1\) and unrank it. The rook formula and the use of prefix counts in lexicographic order are established techniques. The new counting construction handles arbitrary literal prefixes for every fixed finite set. An earlier two-offset algorithm already gives polynomial time uniform in those two offsets. André, §5 The uniform result uses the fact that the number of completions of one prefix can encode the permanent of any zero–one matrix \(A\) of size \(m\times m\), with \(m\ge1\). Set \[t=2m^2+m,\qquad n=4t+4,\qquad a=n-t,\qquad R_i=n-m+i,\qquad c_j=a+jm\quad(1\le i,j\le m). \] Take \(S=\{c_j-R_i:A_{ij}=0\}\). The \(m^2\) differences are distinct modulo \(n\) and lie in \([-t,-1]\) as integers. To construct the target prefix \(P\), put the identity in positions \(1,\ldots,a\). Then match rows \(a+1,\ldots,n-m\) to columns \(a+1,\ldots,n\) other than the selected \(c_j\), using legal edges. Both sides have \(2m^2\) vertices and each vertex has at least \(m^2\) legal neighbours, so Hall's condition guarantees that a polynomial-time matching algorithm can construct \(P\). The remaining rows and columns have exactly the allowed pairs of \(A\). The number of completions is therefore \(\operatorname{perm}(A)\), the number of perfect matchings of its allowed pairs, which can be zero. An independent family of legal permutations certifies the ranks needed to recover this count. Start with cyclic translation by \(2t\) and freely rearrange the images of the first \(t+1\) rows among those rows. Their displacements stay in \([t,3t]\), below the forbidden residues in \([n-t,n-1]\). This gives \((t+1)!\) legal permutations, so every rank from \(0\) through \(t!-1\) is valid. The permutations beginning with the identity on the first \(a\) positions form the initial lexicographic block, of size at most \(t!\), and \(P\) extends that identity prefix. Binary search on the certified ranks finds the first output whose length-\((n-m)\) prefix is at least \(P\) and the first whose prefix is strictly greater than \(P\). Use \(t!\) as the boundary value if a search finds no such output in the range. The difference between the two ranks gives \(\operatorname{perm}(A)\) in \(O(\log(t!))\) valid unrank calls, including when the count is zero. The reduction gives the forward implication by the known \(\#\mathrm P\)-completeness of the zero–one permanent. Conversely, prefix completion counts belong to \(\#\mathrm P\), since a completed permutation can be checked in polynomial time. If \(\mathrm{FP}=\#\mathrm P\), those counts give a uniform polynomial-time unranker through the same lexicographic block procedure. The complexity of computing the total size of the full avoidance class directly is outside the result. Valiant, *The Complexity of Computing the Permanent*

Authors

Institutions

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-12-04
DOI
https://doi.org/10.5281/zenodo.24804082
Primary Topic
Advanced Combinatorial Mathematics
Type
preprint
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
NOV
preprint

Lexicographic unranking with cyclic offset bans: fixed-set algorithms and a uniform counting barrier

Zixuan He
Zenodo (CERN European Organization for Nuclear Research)
Advanced Combinatorial Mathematics
preprint

Lexicographic unranking with cyclic offset bans: fixed-set algorithms and a uniform counting barrier

Zixuan He
preprint en

Abstract

Kagey asked whether permutations that avoid a finite set of cyclic offsets can be efficiently unranked in ordinary lexicographic order. The answer depends on how the offsets are supplied. Every fixed finite set admits polynomial-time ranking and unranking. With an arbitrary set supplied as input, deterministic polynomial-time unranking exists if and only if \(\mathrm{FP}=\#\mathrm P\), even when the algorithm is required to answer only at valid ranks. Here polynomial time is measured in \(n\) and the bit lengths of the supplied inputs. The equality means that every \(\#\mathrm P\) counting function is computable in deterministic polynomial time. Kagey, §6.1, Definition 38 and Open Question 40 For \(n\ge 1\), write \([n]=\{1,\ldots,n\}\). A permutation \(\pi\) is legal for a finite set \(S\subset\mathbb Z\) if \(\pi(i)-i\not\equiv s\pmod n\) for every \(i\in[n]\) and \(s\in S\). Ranks start at zero and compare the one-line lists \((\pi(1),\ldots,\pi(n))\) at their first differing entry. To count the completions \(C(p)\) of a proposed prefix \(p\) of length \(\ell\le n\), return zero if an entry lies outside \([n]\), repeats a value or violates an offset ban. For a valid prefix, delete its assigned rows and used columns from the bipartite graph whose edges are the forbidden row–value pairs. If \(r_k\) counts the size-\(k\) matchings in the remaining graph, with \(r_0=1\), rook inclusion–exclusion gives \[C(p)=\sum_{k=0}^{n-\ell}(-1)^k r_k(n-\ell-k)!. \] For \(S=\varnothing\), this is simply \((n-\ell)!\). For nonempty \(S\), set \(D=\max S-\min S\). To compute the matching counts, use coordinates \(0,\ldots,n-1\) and shift all columns by \(-\min S\) modulo \(n\), including the coordinates of those deleted by the prefix. Each surviving forbidden edge now goes from row \(i\) to column \(i+d\bmod n\) for some \(d\in\{s-\min S:s\in S\}\). Coincident residues give a single edge. Sweep the rows in order. At each cut, keep the set of already used columns with neighbours on both sides of the cut, together with a polynomial for each such set. Start with polynomial \(1\) for the empty set. At the next row, either choose no edge or choose an edge to an unused surviving neighbour, multiplying the polynomial by \(z\) when an edge is chosen. Keep only used columns with neighbours on both sides of the new cut and add polynomials that reach the same state. The final polynomial is \(\sum_k r_kz^k\), where the formal variable \(z\) records the number of chosen edges. For \(D<n\), a column live after row \(i\) must lie among the first \(D\) columns, which receive all wrapped edges, or have a coordinate from \(i+1\) through \(i+D\). Thus at most \(\min(n,2D)\) columns need to be tracked, also when earlier assignments leave holes in the graph. Counting, ranking and unranking take \(2^{\min(n,2D)}\operatorname{poly}(n,\operatorname{size}(S))\) bit operations, where \(\operatorname{size}(S)\) is the bit length of the offset list. Ranking sums the completion counts of lexicographically earlier choices at each position. Unranking tries unused values in increasing order in the original coordinates, subtracting each skipped block's count until the requested rank falls within a block. Each procedure needs at most \(n^2\) prefix counts. For exact uniform sampling, if \(C(\varnothing)>0\), draw a uniform integer from \(0\) to \(C(\varnothing)-1\) and unrank it. The rook formula and the use of prefix counts in lexicographic order are established techniques. The new counting construction handles arbitrary literal prefixes for every fixed finite set. An earlier two-offset algorithm already gives polynomial time uniform in those two offsets. André, §5 The uniform result uses the fact that the number of completions of one prefix can encode the permanent of any zero–one matrix \(A\) of size \(m\times m\), with \(m\ge1\). Set \[t=2m^2+m,\qquad n=4t+4,\qquad a=n-t,\qquad R_i=n-m+i,\qquad c_j=a+jm\quad(1\le i,j\le m). \] Take \(S=\{c_j-R_i:A_{ij}=0\}\). The \(m^2\) differences are distinct modulo \(n\) and lie in \([-t,-1]\) as integers. To construct the target prefix \(P\), put the identity in positions \(1,\ldots,a\). Then match rows \(a+1,\ldots,n-m\) to columns \(a+1,\ldots,n\) other than the selected \(c_j\), using legal edges. Both sides have \(2m^2\) vertices and each vertex has at least \(m^2\) legal neighbours, so Hall's condition guarantees that a polynomial-time matching algorithm can construct \(P\). The remaining rows and columns have exactly the allowed pairs of \(A\). The number of completions is therefore \(\operatorname{perm}(A)\), the number of perfect matchings of its allowed pairs, which can be zero. An independent family of legal permutations certifies the ranks needed to recover this count. Start with cyclic translation by \(2t\) and freely rearrange the images of the first \(t+1\) rows among those rows. Their displacements stay in \([t,3t]\), below the forbidden residues in \([n-t,n-1]\). This gives \((t+1)!\) legal permutations, so every rank from \(0\) through \(t!-1\) is valid. The permutations beginning with the identity on the first \(a\) positions form the initial lexicographic block, of size at most \(t!\), and \(P\) extends that identity prefix. Binary search on the certified ranks finds the first output whose length-\((n-m)\) prefix is at least \(P\) and the first whose prefix is strictly greater than \(P\). Use \(t!\) as the boundary value if a search finds no such output in the range. The difference between the two ranks gives \(\operatorname{perm}(A)\) in \(O(\log(t!))\) valid unrank calls, including when the count is zero. The reduction gives the forward implication by the known \(\#\mathrm P\)-completeness of the zero–one permanent. Conversely, prefix completion counts belong to \(\#\mathrm P\), since a completed permutation can be checked in polynomial time. If \(\mathrm{FP}=\#\mathrm P\), those counts give a uniform polynomial-time unranker through the same lexicographic block procedure. The complexity of computing the total size of the full avoidance class directly is outside the result. Valiant, *The Complexity of Computing the Permanent*

Zenodo (CERN European Organization for Nuclear Research)
University of Glasgow (GB)
Advanced Combinatorial Mathematics
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon