1 Introduction
For nonnegative integer vectors r=(r_1,\ldots,r_m) and c=(c_1,\ldots,c_n) with common total N, write
The uniform distribution on this finite set gives every table equal mass. We study sampling when both dimensions vary and the margins are encoded in binary. In particular, a polynomial bound in the numeric total N would not, in general, give a polynomial bound in the input length. There are no cell bounds or forbidden positions: every nonnegative integer matrix with the prescribed margins is allowed. For probability laws on a finite set, we use the convention \TV(\mu,\nu)=\tfrac12\sum_x|\mu(x)-\nu(x)|.
Theorem 1.1. For arbitrary nonnegative integer margins of equal total, the following algorithms exist in the model of unbiased random bits and bit operations.
- (i)
Given an integer k\ge1, a bounded-time algorithm outputs a table in \Omega(r,c) whose law is within 2^{-k} in total variation of the uniform law. Its running time is polynomial in m,n,\log(N+1),k.
- (ii)
An algorithm outputs an exactly uniform table in \Omega(r,c), terminates almost surely, and has expected running time polynomial in m,n,\log(N+1).
The polynomials are uniform over all margin vectors. No positivity, sparsity, balance, or fixed-dimension hypothesis is imposed.
For a rational tolerance 0<\eps<1 encoded by a binary numerator and denominator, integer comparisons compute k=\lceil\log_2(1/\eps)\rceil in time polynomial in that encoding length. Thereafter part (i) has accuracy dependence polynomial in \log(1/\eps). The algorithms below are explicit, although their exponents are deliberately large. Part (ii) concerns expected time: an exceptionally rare branch performs exhaustive computation.
Counting and sampling fixed-margin arrays. Contingency tables are a basic family of integer arrays with linear constraints. Their enumeration and exact and approximate generation are treated, for example, by Diaconis and Gangolli [7]. The algorithmic question involves more than producing one feasible table: the law must give all feasible tables nearly or exactly the same mass, even when their number and the coordinate ranges are exponentially large in the margin bit length.
For two rows, Dyer and Greenhill [9] give polynomial-time approximate counting and sampling. Their heat-bath chain has mixing time at most n(n-1)\log(N/\eps)/2 in the author version’s Theorem 4.1. Dependence on \log N rather than N makes this a polynomial bound in the binary input length. Kijima and Matsui [12, Theorems 3.1 and 5.1] give exact uniform sampling for two rows by monotone coupling from the past, after sorting the columns. Their expected O(n^3\ln N) bound is stated for pseudocode using uniform real draws. These results allow arbitrary two-row margin sizes after deleting zero margins.
The fixed-row case extends beyond two rows. Cryan and Dyer [4] combine dynamic programming with volume estimation for approximate counting and sampling. Dyer [8, Section 3] gives a dynamic-programming rejection sampler that is exactly uniform, analyzed in arithmetic operations. Cryan, Dyer, Goldberg, Jerrum, and Martin [5] prove rapid mixing of the 2\times2 heat-bath chain for every fixed number of rows. The polynomial bounds in these results depend on that fixed row count; they do not give a bound polynomial jointly in both dimensions.
DeSalvo and Zhao [6, Theorem 2.3 and Remarks 2.4–2.5] give a general exact divide-and-conquer construction using O(mn\log M) expected random bits, where M is the largest margin. In the cited arXiv version, their polynomial total-runtime conclusion is conditional on efficient evaluation of the parity-restricted counting quantities in Conjecture 2.6; the bit-time bounds in Theorem 1.1 are unconditional.
Another line of work uses the geometry of the transportation polytope when margins are large. Dyer, Kannan, and Mount [10] develop scaled coordinates, softened constraints, lattice walks, and rounding comparisons for dense tables. Morris [14] improves the dense sampling bounds through expanded polytopes and rounding. These methods are close antecedents of the dense completion routine below. Our use of that routine is conditional: a padding construction makes every completion problem dense, while a separate chain handles all cells incident to small margins.
For sparse margins, Arman, Gao, and Wormald [2, Theorem 1 and Remark 2] give exact uniform generation under 5\Delta^4<N, where \Delta is the largest margin, in expected O(N) time with unit-cost arithmetic on integers of magnitude O(N). The condition is a genuine restriction, although within this family it also bounds N polynomially in the dimensions. Their 2021 introduction surveys fixed-row, dense, and sparse algorithms and reports that no polynomial-time approximately uniform sampler for arbitrary margins was then known. Theorem 1.1 removes those margin and dimension restrictions and includes all random bits and integer arithmetic in its cost.
Approximation and exact correction. Exactness and bounded running time are separate issues. Our approximate algorithm has a deterministic polynomial work bound for each accuracy request. The final exact correction uses the residual-mixture construction of Göbel, Liu, Manurangsi, and Pappik [11, Section 3.1, Algorithm 1 and Theorem 6]. That construction combines a sufficiently accurate sampler with a rare exhaustive draw from the remaining probability mass. Its application here requires an additional property: the actual implemented output law can be tabulated in time with an exponential input-size factor but only polynomial dependence on the accuracy bits. We prove that property and give the dyadic implementation explicitly. Thus the exact algorithm has polynomial expected bit cost, not a polynomial bound on every execution.
Proof strategy. Only cells incident to a margin below a polynomial threshold are explicit coordinates of the auxiliary chain. The remaining cells form a complete rectangle. We pad this rectangle so every conditional completion problem has large margins. Each explicit cell has two bounded integer values, one for its row and one for its column. Besides states where these values agree, called transversals, we allow a positive unit discrepancy at one cell and a negative unit discrepancy at another.
The target law on these small states assigns weight equal to the number of padded completions. Sampling a state from that law and then a uniform completion makes all state/completion pairs equally likely. Accept only a transversal whose large completion entries are all at least the padding. Subtracting it then gives a uniform original table conditional on acceptance. Section 2 constructs a repair map for the defect states and uses it to bound their weight and the probability of successful unpadding. The bounded sampler never evaluates completion counts: an ideal transition uses a uniform completion draw to test a proposed move.
To prove that this chain mixes in polynomial time, we expose the small-cell values of a transversal in a fixed order. After fixing a prefix, we compare the averages of any real function on the state graph over the two fibers that assign adjacent values to the next cell. The comparison comes from quadratic forms indexed by pairs of unit removals. Section 3 proves that these forms have at most one positive eigenvalue and that the property survives summing out a balanced pair. A weighted telescoping calculation then bounds the energy of a signed flow between neighboring conditional fibers. Section 4 combines this bound with conditional-variance decomposition and repair to obtain a Poincaré inequality for the completion-count law. This supplies the small chain’s mixing bound.
Section 5 implements the completion draws approximately on a finite scaled grid, using rational arithmetic and dyadic random choices. A continuous log-concave density serves only as an analytic tool for the rejection and conductance bounds. Large coordinate ranges appear in finite sums in the proof but are never enumerated in an ordinary run. Section 6 couples each implemented completion draw to its ideal counterpart and bounds the number of sampling and unpadding attempts, giving the bounded almost-uniform algorithm. For exactness, it also shows how to tabulate that algorithm’s actual finite law, including its stopping rules and fallbacks. This exhaustive computation is performed only on the rare correction branch.
2 The binary model and the padded graph
This section separates bounded small coordinates from a complete rectangle of large coordinates. Its repair map controls the mass of defect states; padding then gives a uniform lower bound on the chance of recovering an original table from a stationary state and its completion.
We count bit operations and use independent unbiased random bits. All margins are nonnegative integers given in binary, with common total N. Accuracy is specified by an integer k\ge1, meaning error at most 2^{-k}. An empty dimension forces N=0 and gives a unique empty table. If N=0, or if one dimension is one, the unique table can likewise be returned directly. In all remaining constructions the dimensions are positive, and we use
Here d is a dimension allowance, L the padding, U the small-margin threshold, C a coordinate cap, and b a bit-size allowance. Thus d\ge14, mn<d, U<C, and b=O(d+\log(N+1)). Polynomial bounds in d,b,k have the required binary-input dependence. A fixed feasible table is obtained greedily: choose a row and column of positive remaining margins, place the minimum of those two margins in their cell, and subtract it from both margins. Each placement exhausts a row or column. This uses at most m+n-1 positive placements and polynomial bit work, including initialization of the output. We fix index order for this construction and all later ties.
2.1 Small states and large completions
Put I=\{i:r_i\ge U\} and J=\{j:c_j\ge U\}. The large slots are the cells in the complete rectangle \mathcal B=I\times J; the remaining cells form the set \mathcal S of small slots. Set B_s=C on \mathcal B and B_s=U on \mathcal S. Associate to each slot two coordinates x_s,y_s\in\{0,\ldots,B_s\}, and put q_s=B_s-y_s. Here x is the row viewpoint and q is the column viewpoint. A slot is balanced when x_s=q_s, equivalently x_s+y_s=B_s. The balanced representation of a value a\in\{0,\ldots,B_s\} is (x_s,y_s)=(a,B_s-a); both x_s and q_s then equal a.
A graph state retains only the coordinates on \mathcal S. Its allowed pattern is either a transversal, with all slots balanced, or a defect, with distinct slots t,s satisfying
We call t positive and s negative. Both patterns have total doubled occupancy \sum_{s\in\mathcal S}(x_s+y_s)=U|\mathcal S|. Define the original residual margins by
Their totals agree because \sum_{s\in\mathcal S}(x_s-q_s)=0. Let k_i and \ell_j be the numbers of large slots in row i and column j. A state is feasible when all residuals are nonnegative and R_i^0=0 if k_i=0, P_j^0=0 if \ell_j=0. Its padded residuals and enlarged full margins are
Write \mathcal F_X for the set of nonnegative integer tables on \mathcal B with margins R_i(X),P_j(X), and set f(X)=|\mathcal F_X|. On infeasible states set f(X)=0. The complete rectangle admits a greedy completion whenever these residual tests hold. If \mathcal B is empty the only completion is the empty table, so feasible states have weight one.
Every completion has total at most N+|\mathcal B|L<C, and every nonempty block margin is at least L. In particular the formal large capacity C excludes no completion: its doubled coordinates can be taken as x_s=A_s,y_s=C-A_s for A\in\mathcal F_X. The bounded sampler will draw completions of this block without enumerating its large coordinate ranges. One-row or one-column blocks have a unique completion and need no random draw.
Let \mathcal X be the feasible states, \mathcal T\subseteq\mathcal X the transversals, and
An original feasible table gives a transversal and a completion by retaining its small entries and adding L to each large entry. The small entries respect their capacity because every small cell has an incident original margin below U. This construction also gives a specified starting transversal, using the greedy original table.
2.2 Repairs and graph edges
For a defect with negative slot s=(i,j) and positive slot t=(i',j'), put v=(i',j). With e_w denoting a small-slot unit vector, define its repair \mathcal R(X) by
The term involving e_v is omitted if v is large. The undirected graph on \mathcal X contains all pairs that differ by lowering one doubled small coordinate by one and raising another by one, and also every pair \{X,\mathcal R(X)\} with X a defect. Repeated edges are counted only once. Its unnormalized energy is
Lemma 2.1 (Repair and preservation of prefixes). The repair is a feasible transversal. For each fixed ordered pair (s,t) it is injective on small states and extends to an injection
Thus f(X)\le f(\mathcal R(X)). Order small slots by row and then by column. If t follows s, the repair leaves every slot preceding s unchanged. When additionally x_s=l-1,q_s=l, its repaired value at s is l if i'=i and l-1 otherwise.
Proof. The defect relation is q=x-e_t+e_s, and x_t\ge1. If v is small, the changes to x lie in row i', with zero total; the changes to q are q'-q=e_v-e_s, in column j, also with zero total. Hence all residual margins are unchanged. The new common entries are nonnegative. Their row totals are the old x row totals and their column totals are the old q column totals. At each small slot, one of these totals is bounded by an original margin strictly below U, proving the capacity constraint. If j'=j, then v=t and the two changes to x cancel; the reset of q is confined to that column. If i'=i, then v=s: the transfer increments the negative slot, decrements the positive slot, and leaves q unchanged. These include both possible coincidences.
If v is large, it differs from s,t, and x'=x-e_t, q'=q-e_s. These vectors remain nonnegative and within capacity, since x_t\ge1 and q_s=x_s+1\ge1. Only the residuals of row i' and column j increase, each by one. Both lines meet the large block. Adding one to completion entry v therefore gives a valid target completion. Its entries remain below C by the total bound already proved.
For fixed s,t, the repaired vector recovers x=x'+e_t-\one_{\{v\in\mathcal S\}}e_v, followed by q=x-e_t+e_s and y=U\one-q. In the large-receiver case subtract e_v from the target completion; otherwise retain it. These inverses on the image prove both injections.
Finally, t>s implies either i'=i,j'>j, in which case v=s, or i'>i, in which case every small receiver v follows s. Only s,t,v can change, proving prefix preservation and the claimed special value.
For later use, fix a balanced prefix \sigma before s, and let z_-,z_+ be the total transversal weights extending it with special values x_s=l-1,l, respectively. Let c_{st,l}^{\sigma} be the total weight of defects extending that prefix with negative s satisfying x_s=l-1,q_s=l and positive t>s. Lemma 2.1 maps this entire class injectively, with completions, into one fixed child. Hence
Figure 1 illustrates the large-receiver case.
Figure 1: The repair when the receiving cell (i',j) is large. Small cells display (x,q), and the shaded cell displays a completion entry. Decreasing x_t and matching the viewpoints increases the residual row margin at i' and column margin at j by one; adding one to z gives an injective map of completions. The other cells remain unchanged.
There are fewer than 4d^2 ordered unit exchanges. A defect has one designated repair; a transversal has at most d^2 inverse repairs, one for each ordered defect type. Thus the degree is at most 5d^2+1. Neighbors can be listed with polynomial bit work using (2.3) and its inverse, testing the boxes, patterns and residuals, and removing duplicates. No completion count is needed. On a repair edge the weight in (2.4) equals the source defect’s weight.
2.3 Stationary mass and unpadding
The repair bounds defect mass by transversal mass. To recover an original table from a padded completion, we also need to control the probability that a large entry is smaller than the padding. The following estimate applies to unrestricted tables with any prescribed margins.
Lemma 2.2 (Small entries). Consider the uniform law on all nonnegative integer tables with prescribed margins, with at most m rows and n columns and no entry restrictions. If both margins incident to a cell are at least a\ge4d, then, for every integer t with 0<t\le a/2,
Proof. Let the marked cell be (i,j) and its entry be h<t. The other entries in its row have sum at least a/2, as do the other entries in its column. Unless this event is empty, choose deterministically j'\ne j and i'\ne i whose donor entries are both at least a/(2d). Such choices exist because each line has fewer than d entries. If there is only one row or column, the event is empty instead. For every v=1,\ldots,\lfloor a/(2d)\rfloor, subtract v from the entries (i,j') and (i',j) and add v at (i,j) and (i',j'). The resulting table is nonnegative with the same margins. Given this table and the labels (i',j',h), its marked entry determines v, and reversing the four changes recovers the source. There are at most td^2 possible labels for each output. Since \lfloor a/(2d)\rfloor\ge a/(4d), double counting these moves gives the asserted bound. No upper entry bound is imposed in this argument.
Proposition 2.3 (Stationary mass and unpadding). The masses satisfy
Draw X with law \pi and then a uniform A\in\mathcal F_X. Declare success if X is a transversal and every large entry of A is at least L. Subtracting L from these entries gives a uniform original table conditional on success, and
Proof. For each of at most |\mathcal S|(|\mathcal S|-1)\le d^2 defect types, the joint injection in Lemma 2.1 bounds its total weight by Z_0. This proves the upper bound on \Lambda; the other mass inequalities follow from inclusion and the greedy starting table. There are \Lambda joint objects (X,A), each specified by 2|\mathcal S|+|\mathcal B|\le2mn<2d integer coordinates in [0,C]. Thus \Lambda\le(C+1)^{2d}, and the positive integer weights f(X) give the minimum-mass bound.
Consider all unrestricted tables with the enlarged margins \bar r,\bar c, and call their number F. Every transversal and completion gives one such table, so Z_0\le F. Each large cell has both enlarged margins at least U. Lemma 2.2 and a union bound show that the proportion of these enlarged tables with some large entry below L is at most
Here L\le U/2 and U\ge4d; an empty block has no bad cells. Every enlarged table passing this test can be unpadded to an original table. Conversely, padding every original table gives exactly one passing table and a feasible transversal with its completion. Consequently the successful pairs are in bijection with \Omega(r,c) and number at least F/2\ge Z_0/2. Under the stated joint law every pair has probability (f(X)/\Lambda)(1/f(X))=1/\Lambda, proving conditional uniformity and (2.7).
If there are no small slots, \mathcal X has one state and all graph energies vanish; the completion and unpadding step still applies. If there is no large block, the completion step is deterministic. These conventions will also be used for the Markov chains below.
3 Quadratic signatures and balanced summation
The transport construction uses quadratic forms with at most one positive eigenvalue. We prove the required property for integer coordinates and then show that it survives summation over balanced slots. Integer coordinates allow two units to be removed at the same location, so the diagonal entries and the endpoints of the summation require explicit treatment. Large capacities occur only in finite mathematical sums in this section; the algorithm will not enumerate those sums. The one-positive-eigenvalue viewpoint is central to the theory of Lorentzian polynomials developed by Brändén and Huh [3]. Here the needed closure is a discrete balanced-pair summation, established by the laminar decomposition and telescoping calculation below.
Definition 3.1 (Softened weights). Let \mathcal B and \mathcal S be the large and small slots from Section 2, and put
For a full coordinate vector \xi=(x_s,y_s)_s, write |\xi|=\sum_s(x_s+y_s) and q_s=B_s-y_s. For a\in\R, let a_+=\max(a,0). Define
For 0<\eta<1, set
For a small-coordinate configuration X of total \sum_{s\in\mathcal S}B_s, define
An empty product of choices contributes one term.
Every box-valid full vector of total T has strictly positive weight, regardless of its margin deviations or slot occupancies. Thus f_\eta(X)>0 for every box-valid X of the indicated total. On the transversal and defect patterns,
Indeed, a term has D=0 exactly when the full row and column margins are \bar r,\bar c and the small row and column totals do not exceed r,c. When the large slots are balanced, these conditions specify precisely the nonnegative residuals and padded completions defining f. On a line without a large slot, the full-margin equality also makes the residual zero. The capacity C excludes no such completion, by its choice in (2.1). Each zero-penalty term tends to one, all other terms tend to zero, and the sum is finite.
We use the following convention throughout. Some coordinates have fixed box-valid values \sigma, of total c=|\sigma|; a disjoint collection \mathcal R of whole slots is summed over its balanced profiles; and all remaining coordinates are active. For an assignment v to the active coordinates, let
Thus the summation domain is fixed, even when v changes. A box-valid active display p for two removals satisfies
Its two-removal matrix has entries M_{ih}=\Phi_{\sigma,\mathcal R}(p-e_i-e_h). In particular, two removals at the same coordinate give a diagonal entry; an invalid removal gives zero. The display has total T+2, whereas every nonzero entry is evaluated at total T.
Lemma 3.2 (Laminar factors). With no balanced slots summed, every two-removal matrix just defined has at most one positive eigenvalue.
Proof. Before imposing the box and total, the formula \eta^{D(\xi)} is a product of positive log-concave sequences in sums over a laminar family of coordinate sets. Here laminar means that any two sets are disjoint or one contains the other. The sets are the x coordinates of each row and their small-slot subsets, and the y coordinates of each column and their small-slot subsets. The row and column families are disjoint because they use different coordinates. For example, the column factors have the form
where z is the relevant sum of y coordinates and K,K' are the corresponding sums of capacities. All exponents are convex in z; since \log\eta<0, the factors are log-concave on all integers.
An active coordinate with p_i=0 gives a zero row and column of M; discard these indices temporarily. Restrict the laminar sets to the remaining indices and absorb fixed coordinates into shifts of their scalar factors. Combine factors whose restricted sets coincide, and absorb empty sets into a positive constant. We obtain distinct nonempty laminar sets G, positive log-concave sequences \psi_G, and arguments t_G at the display. Evaluate their formula even for invalid removals for the moment. Let W>0 be its value at the display and put
The extended two-removal matrix is W\diag(\alpha)K\diag(\alpha), where
For each set define
The sets containing any given pair of indices form a chain. Telescoping the product along this chain gives the exact identity
Consequently K is nonpositive on \{v:\one^{\mathsf T}v=0\} and has at most one positive eigenvalue. The only still-invalid removals are diagonal ones at coordinates with p_i=1. Replacing each such entry by zero subtracts a nonnegative diagonal matrix from K, so preserves that conclusion. Positive diagonal congruence and restoration of the zero rows and columns complete the proof.
We next sum over a fresh slot of capacity B. Two occupancies are needed. At occupancy B, summing the profiles (j,B-j) eliminates a balanced slot and preserves the signature. At occupancy B+1, the same calculation gives a weighted quadratic estimate; this is the estimate used to bound the transport construction in the next section. Both conclusions follow from a discrete second-difference inequality.
Lemma 3.3 (Pair summation). Fix a box-valid display p on the old active coordinates, a fresh slot of capacity B\ge2, and fixed context and balanced sums as above. Choose its displayed occupancy D'\in\{B,B+1\} so that
Write \Phi(r,a,b) for the weight after the balanced sums, with old values r and fresh pair (a,b). The box-valid displays (p,j,D'-j) are indexed by
Their two-removal matrices have the blocks
Thus V_j records two old removals, S(l) one old and one fresh removal, and u_j one removal from each fresh coordinate of display j. Put S(l)=0 outside 0\le l\le D'-1 and u_j=0 outside 1\le j\le D'-1. Suppose each matrix
has at most one positive eigenvalue. The entries u_{j-1} and u_{j+1} are the double removals at the first and second fresh coordinates, respectively. For every real old vector h satisfying \sum_{l=0}^{D'-1}h^{\mathsf T}S(l)=0, define
All these divisions are valid, and
If D'=B, the matrix \sum_{j=0}^B V_j has at most one positive eigenvalue. If D'=B+1, then
Proof. First, u_j>0 for every 1\le j\le D'-1. Its pair values (j-1,D'-1-j) are within [0,B]^2 in both cases. They have total D'-2, so (3.5) puts the full configuration on the total-T slice. Choose any balanced box-valid profile, for example (0,B_s), at each summed slot. The unchanged old profile and fixed context then give a positive term of F_\eta. This proves positivity even when the context violates the original margins or some old displayed coordinates are zero.
The cumulative definition and the balance condition imply, including l=0,D'-1,
We use an elementary consequence of the signature assumption. If a symmetric matrix M has at most one positive eigenvalue and e^{\mathsf T}Me>0, then
Indeed, subtract from v its M-orthogonal projection onto e. The remaining vector must have nonpositive square, since otherwise it and e span a positive definite two-dimensional subspace.
For j\in\mathcal J, put v=(h,g_j,-g_j), and let e_a,e_b denote the two fresh coordinate directions. Equations (3.6) and (3.10) give
If u_{j-1}>0, apply (3.11) to e_a; if u_{j+1}>0, apply it to e_b. Either bound is at most
If both diagonals vanish, then u_j>0 and e_a+e_b has square 2u_j and is M_j-orthogonal to v. The same upper bound, now zero, follows. These cases cover all admissible j: at j=0 or D' the inward diagonal is positive, and at every other index u_j>0. An exact expansion now yields
proving (3.8).
For clarity, the smallest capacity is covered without a positive diagonal at every display. When B=D'=2, the displays j=0,2 use the diagonal u_1>0, and j=1 uses the positive sum direction with square 2u_1. When B=2,D'=3, the only displays are j=1,2; they have, respectively, positive diagonal u_2 and u_1. The out-of-box displays j=0,3 are never evaluated.
Write a_j=u_jg_j^2, zero outside 1\le j\le D'-1. For D'=B, summing (3.8) over 0\le j\le D' gives
Thus the sum is nonpositive on the kernel of h\mapsto h^{\mathsf T}\sum_l S(l), a subspace of codimension at most one. A positive eigenspace of dimension two would intersect that kernel nontrivially, so the sum has at most one positive eigenvalue. For D'=B+1, let w_j=j(D'-j), with w_0=w_{D'}=0. Multiplying (3.8) by w_j and summing only over the admissible indices gives
This proves (3.9), using only scalar zero endpoint weights, never endpoint matrices outside the box.
Proposition 3.4 (Signature after balanced summation). Fix 0<\eta<1. For arbitrary box-valid fixed context \sigma, arbitrary balanced-slot summation set \mathcal R, and arbitrary box-valid active display p satisfying (3.3), the matrix
has at most one positive eigenvalue.
Proof. Induct on |\mathcal R|. Lemma 3.2 proves the empty case. For a nonempty set choose t\in\mathcal R, regard its two coordinates as active at (j,B_t-j), and sum only over \mathcal R\setminus\{t\}. Every resulting matrix M_j has at most one positive eigenvalue by induction; its total is T+2 by (3.3). Apply Lemma 3.3 with D'=B_t. The matrix \sum_{j=0}^{B_t}V_j is exactly the required matrix after also summing slot t, and has the asserted signature. All capacities here are at least two. Zero active coordinates give zero rows and columns throughout and need no additional assumption.
This is a specific closure under balanced-pair summation, proved by (3.8); arbitrary sums of matrices with this signature need not preserve it. In the transport argument, a weighted matrix V_t=\sum_j j(D'-j)V_j will be tested against real vectors h whose entries may have either sign. Equation (3.9) controls these quadratic evaluations under the stated balance condition. We make no signature assertion for V_t itself. In particular, Proposition 3.4 is applied before this weighted sum, on the entire softened total-T box, even when the resulting two-removal configurations lie outside the graph patterns.
4 Transport and the graph variance bound
We now turn the quadratic property into a variance bound for the graph of Section 2. A signed flow compares adjacent conditional means; decomposing variance over successive conditions gives a bound on the transversals, and the repair map extends it to the full graph. All large slots are summed with their balances throughout. The remaining slots are exposed in row-major order. Fix a real-valued function H on the feasible small-state graph. The flow-energy comparison is the standard quadratic electrical-network method; see Aldous and Fill [1, Section 3.7.1]. The recursive signed demands and their bound for integer slots are constructed here. A context \sigma fixes balanced profiles on a prefix of small slots. Write \mathcal T_\sigma for the transversals with this context and z_\sigma=\sum_{X\in\mathcal T_\sigma}f(X). If s is the next slot, its child j fixes (x_s,y_s)=(j,U-j), and has mass z_j and weighted mean H_j. Means are used only for positive masses.
Let E_\sigma(H) be the sum of \min(f(X),f(Y))(H(X)-H(Y))^2 over unordered unit-exchange edges whose endpoints respect \sigma. In particular E_\sigma(H)\le E(H); repair edges need not be included in E_\sigma. A superscript \eta on masses or means, and E_{\eta,\sigma} on this energy, will indicate the softened weights from Definition 3.1. For the softened energy we include all box-admissible transversal and defect patterns with the context, including states whose limiting weight is zero.
4.1 Child weights and adjacent means
Lemma 4.1 (Child log-concavity). At every context with positive transversal mass, the child masses (z_j)_{j=0}^U are log-concave and their positive support is an integer interval. If z_a,z_b>0 and a\le j\le b, then z_j\ge\min(z_a,z_b).
Proof. For 0<\eta<1 every child mass is positive. For 1\le j<U, display the next pair as (j+1,U-j+1) and sum every other unexposed slot with its balance. The display is in its box and has two excess units. Its two-removal matrix is
Proposition 3.4 gives at most one positive eigenvalue. The trace is positive, so the determinant is nonpositive: (z_j^\eta)^2\ge z_{j-1}^\eta z_{j+1}^\eta. Consequently the successive differences of \log z_j^\eta are nonincreasing, and for a<j<b,
Finite sums converge as \eta\downarrow0. The local inequalities give log-concavity in the limit; the displayed interpolation gives positivity between positive endpoints and the asserted lower bound.
Lemma 4.2 (Conditional transport). Let \sigma be a row-major context, and let children l-1,l of its next slot have positive masses z_-,z_+ and means H_-,H_+. Then
Proof. We first work at a fixed \eta>0. Extend H by arbitrary fixed finite values to the box-admissible graph patterns whose limiting weights are zero, and suppress \eta on masses. We seek a signed flow with divergence f_\eta(X)/z_- at each transversal in the minus child, -f_\eta(X)/z_+ at each transversal in the plus child, and zero elsewhere. For such a flow J, summation by parts and Cauchy–Schwarz give
where each unit-exchange edge is oriented once. Thus it is enough to bound the flow’s resistance energy. We build its signed demands by successively exposing the remaining small slots, and charge its energy to a quadratic potential along that recursion.
Display the special slot s as (l,U+1-l), where 1\le l\le U. Removing its first or second coordinate gives the minus or plus child, respectively. The flow uses these endpoint transversals and defects with s positive and one other unexposed small slot negative.
Balanced recursion. A recursion node \nu displays the special pair and some subsequent small pairs, the latter all with occupancy U. Let p be this display, and call its coordinates the old indices. With the context included, and all undisplayed slots assigned their balanced occupancies, the total is T+1, where T=\sum_s B_s. For an old index i, let s_i be the total softened weight obtained by removing one unit there and summing all undisplayed slots with their balances. Invalid removals have weight zero. Assign coefficients h_i satisfying
The quantity s_i h_i is the signed demand on that one-removal fiber; the first equality requires total demand zero at the node. At the root the two coefficients are 1/z_- and -1/z_+, giving the prescribed endpoint demands and root potential 1/z_-+1/z_+.
To process the next ordinary slot v, branch over its balanced profiles (j,U-j), 0\le j\le U. In the notation of Lemma 3.3, use the auxiliary occupancy D'=U+1. Then S(j) is the vector of old-hole weights in branch j, and u_j is the no-old-hole weight with pair (j-1,U-j). Thus u_1,\ldots,u_U are positive and u_0=u_{U+1}=0. Since \sum_j S_i(j)=s_i, define
Balance gives h^TS(j)=u_{j+1}g_{j+1}-u_jg_j, including both endpoints. In child j, retain all old coefficients and give the two new coordinates coefficients g_j,-g_{j+1}. Their one-hole masses are u_j,u_{j+1}, so the child is balanced. Summing child potentials conserves the old terms and adds exactly
Here V_{\nu,v} is the matrix of two-old-hole weights with v displayed at (a,U+1-a), summed over 1\le a\le U with multiplier a(U+1-a) and over all other undisplayed slots with their balances. The inequality is precisely Equation (3.9). Each individual display before the two removals has total T+2.
A future quadratic form. For any slot t still to be processed, define Q_t(\nu)=h^TV_{\nu,t}h by the same rule. If a different slot v is split now, we claim
For an explicit common summation kernel, put
Here r assigns the old coordinates, w assigns the current pair v, and b ranges over the Cartesian product of balanced profiles of every remaining slot other than t, including all large slots. As usual, an invalid coordinate assignment contributes zero. This is a single fixed summation domain; all penalties are evaluated on the full configurations. Every kernel entry used below has total T.
The old–old terms in the children partition the parent’s balanced sum over v. For a mixed term, removing old index i and the first new coordinate in branch j gives K_t(p-e_i,(j-1,U-j)) with coefficient 2h_i g_j. Removing i and the second new coordinate in branch j-1 gives the identical kernel entry with coefficient -2h_i g_j. These terms cancel. All legal resulting pairs have occupancy U-1; the unmatched formal endpoint removals are invalid and have weight zero. For the new–new terms, each resulting pair (k,U-2-k), 0\le k\le U-2, has exactly the following contributions:
| Removed coordinates | Branch | Coefficient |
| First twice | k+2 | g_{k+2}^2 |
| First and second | k+1 | -2g_{k+1}g_{k+2} |
| Second twice | k | g_{k+1}^2 |
They all multiply K_t(p,(k,U-2-k)). Hence the exact identity is
All omitted boundary removals are invalid. Auxiliary entries with two holes in an ordinary pair need not be graph states: they belong to the full softened total-T slice where the signature proposition applies. No signature property of the weighted sum V_{\nu,t} is being asserted; Equation (4.4) and the explicit square identity are the properties of that sum that are used.
The root bound. Iterating Equation (4.5) shows that the sum of Q_t at the level just before processing t is at least its root value. Thus Equation (4.4), summed over levels, bounds the total leaf potential by the root potential minus the sum of the root Q_t’s. Let c_t=c_{st,l}^{\eta,\sigma} be the total weight of defects respecting \sigma with special pair (l-1,U-l) negative, slot t positive, and every other small slot balanced. These auxiliary defects differ from the special-positive defects used by the leaf flow: the off-diagonal entry removes both special coordinates from (l,U+1-l), leaving (l-1,U-l). At the root, the off-diagonal entry of V_{\nu,t} is this sum with multiplier a(U+1-a) on the positive pair t, so it is at most (U+1)^2c_t. Its diagonal entries are nonnegative. Substituting the root coefficients and dropping their nonpositive contributions to -Q_t gives
The sum ranges only over the other unexposed small slots. With no such slots the recursion consists of its root and this bound still holds.
Leaf flows and their divergences. At a leaf let D denote the entire small-coordinate display, including the fixed context. For its unfixed coordinate indices i, the valid one-removal states X_i=D-e_i have weights s_i=f_\eta(X_i)>0, and form a clique of unit exchanges. Choose a maximum-weight vertex as hub. On the edge from each nonhub X_i to the hub send signed flow s_i h_i; its conductance is exactly s_i. The flow’s divergence at X_i is s_i h_i, and balance gives the same prescribed divergence at the hub. Its resistance energy is at most \sum_i s_i h_i^2=\Phi_\nu. Different leaf cliques have disjoint edge sets: the coordinatewise maximum of the endpoints recovers D, which uniquely determines the leaf. Their flows can therefore be added without an energy multiplier.
An endpoint transversal has a unique leaf representation. Its ordinary balanced profiles determine all branches, and its special hole is in the first coordinate for the minus child and the second for the plus child. Its coefficient remains 1/z_- or -1/z_+ throughout. Every other used state has special slot positive and a unique ordinary negative pair, say (a,U-1-a) in slot v. It has exactly two leaf representations: fill the first coordinate, giving branch a+1 and coefficient g_{a+1}, or fill the second, giving branch a and coefficient -g_{a+1}. All earlier profiles are determined by the state, so both coefficients come from the same recursion parent. Later splits retain them. Both representations carry the identical weight f_\eta(X), and their divergences cancel. This also holds for a=0,U-1.
Consequently the summed flow J has divergence f_\eta/z_- on the minus child, -f_\eta/z_+ on the plus child, and zero elsewhere. The resistance-energy comparison from the start of the proof and Equation (4.7) now eliminate the flow and all recursive coefficients:
The limit and conditional repair. The extension of H was fixed independently of \eta. For this fixed input all sums are finite. Since the two limiting child masses are positive, every quantity in Equation (4.8) converges as \eta\downarrow0. We take this limit only after obtaining that inequality; convergence of the demands, the g_j’s, or the flows is unnecessary. For the limiting c_{st,l}^\sigma, Lemma 2.1 injects state/completion pairs into one of the two child fibers. Specifically, since t follows s in row-major order, the receiver is either s itself or lies in a later row, and all earlier assignments are preserved. The repaired special value is l in the first case and l-1 in the second, with the choice fixed by s,t. Thus
There are fewer than d possible slots t. Multiplication of the limiting inequality by \min(z_-,z_+) now yields Equation (4.1).
4.2 From conditional transport to variance
Theorem 4.3 (Graph Poincaré inequality). For every real function H on the feasible small graph,
In particular, the feasible graph is connected.
Proof. First restrict to transversals. At a positive-mass context \sigma, put p_j=z_j/z_\sigma. The between-child contribution to its unnormalized variance is
Zero-mass children may be omitted. For positive endpoints a<b, Lemma 4.1 makes every intervening mass at least \min(z_a,z_b). Telescoping and Cauchy–Schwarz therefore give
There are at most (U+1)^2 pairs. Thus the contribution in Equation (4.10) is at most (U+1)^4A_0 E_\sigma(H).
Iterating the identity \Var H=\E(\Var(H\mid j))+\Var(\E(H\mid j)) down the exposure tree expresses the full unnormalized transversal variance as the sum of these contributions. At any fixed depth, the energies E_\sigma use disjoint edge sets, because distinct contexts assign different prefix coordinates. There are at most d internal levels, and A_0\le4d(U+1)^2. Hence, writing \Var_{\mathcal T} for variance under the normalized transversal weights,
If there are no small slots, the transversal space is a singleton and this inequality holds directly.
Let \overline H be the transversal mean, and compare each defect X to its repair \mathcal R(X). By Lemma 2.1, f(X)\le f(\mathcal R(X)), the repair map is injective within each of fewer than d^2 defect types, and its edge has conductance f(X). Distinct defects give distinct repair edges. It follows that
Insert Equation (4.11) to obtain the first bound in Equation (4.9). Since U\ge1, 1+2d^2\le3d^2 and (U+1)^6\le64U^6 give the second bound. Finally, the indicator of a nonempty proper connected component would have positive variance and zero energy, which is impossible. The one-state case is already connected.
5 Sampling a dense completion block
The completion distributions required by the small-state chain have large minimum margins, but their margins need not have comparable sizes. We now give the sampling subroutine, using the global parameters in Equation (2.1). All random choices in its implementation use finitely many independent unbiased bits.
Theorem 5.1 (Dense completion draw). Let a rectangular block have at most m rows and n columns, nonnegative integer margins of equal total less than C, and every margin at least L=d^{12}. For each integer h\ge1, there is an algorithm that always outputs a feasible integer table and whose law is within 2^{-h} in total variation of the uniform law on the block’s feasible tables. Its worst-case bit running time is polynomial in d,b,h. Empty blocks, and blocks having a single row or a single column, have deterministic completion algorithms with the same guarantee.
The proof first groups integer tables into scaled bins and gives a constant lower bound on rejection-sampling acceptance. A log-concave continuous density controls the bin normalizer and the conductance of the finite bin chain. We then implement its transitions and the within-bin offsets with bounded numbers of random bits. The scaled-coordinate and softened-density construction follows the geometric approach of Dyer, Kannan, and Mount [10, Sections 4–5]; expanded-polytope rounding is also central to Morris [14, Sections 1.3–2]. The estimates and finite-bit sampler needed here are proved below.
5.1 Scaled coordinates and rejection from bins
The deterministic cases require no argument beyond the prescribed margins, so suppose the block has a,c\ge2 rows and columns. Write its margins as R_i,P_j. Reorder the rows and columns so that R_a and P_c are maximum, breaking ties by their original indices, and restore the original order when returning a table. The entries with i<a,j<c determine the entire table. We group their possible integer values into intervals of lengths
There are e=(a-1)(c-1)\le d free entries. Since s_{ij}\ge L\ge2B,
Each nonnegative integer free entry has a unique representation X_{ij}=w_{ij}v_{ij}+\beta_{ij} with integer v_{ij}\ge0 and 0\le\beta_{ij}<w_{ij}. For a feasible table, X_{ij}\le s_{ij}, so v_{ij}\le2B<K_0. Thus all feasible tables are represented by bins indexed by
and an offset in each free coordinate. The number of bins depends only on the dimensions, although an offset range can depend on the margins. We will give weight one to every bin containing a feasible table and choose the other weights by penalizing violations of nonnegativity. An ideal proposal then samples a weighted bin and uniform offsets, rejecting an infeasible table.
To define these weights, pass temporarily to scaled real coordinates. For u\in\R^e, define the affine table X(u) by
These formulas impose all the margins. Let T_{ij}=X_{ij}/s_{ij}, including the dependent entries, and set
Every free scale contributing to a dependent entry is at most that entry’s scale. For example, s_{ij}\le s_{ic} follows from P_j\le P_c, s_{ij}\le s_{aj} from R_i\le R_a, and s_{ij}\le s_{ac} follows from both inequalities. Thus every coefficient in each normalized affine entry has absolute value at most 1/B, and there are at most d of them. Consequently
Feasibility and Equation (5.2) imply \mathcal P\subset[0,2B]^e. The integer representation above belongs to the closed unit bin Q_v=v+[0,1]^e, at the point with coordinates u_{ij}=v_{ij}+\beta_{ij}/w_{ij}.
The feasible polytope has a point u_* with uniform positive slack:
To construct it, first assign s_{ij}/(2d) to every cell. This uses at most cR_i/(2d)\le R_i/2 in row i and at most aP_j/(2d)\le P_j/2 in column j. The remaining nonnegative real margins have equal totals and can be completed by the greedy supply–demand construction. The resulting table determines u_*. The strict slack and Equation (5.3) also show that \mathcal P has positive e-dimensional volume.
On the cube [0,K_0]^e define
The allowance d/B makes p vanish at the lower corner of every bin meeting \mathcal P, by Equation (5.3). The function p is convex and (d/B)-Lipschitz in the sup norm; therefore \rho is positive, continuous, and log-concave. Comparison with u_*\in[0,2B]^e gives 0\le p(u)\le4d on the cube. Assign the dyadic bin weights
In particular W(v)=1 whenever Q_v contains a feasible point, even on its boundary. For u\in Q_v,
so
This comparison lets integrals of \rho control sums of bin weights; overlapping bin faces have zero volume in these integrals.
An ideal trial draws v with probability W(v)/Z_B, then draws independent uniform offsets \beta_{ij}\in\{0,\ldots,w_{ij}-1\} and sets
It fills the remaining entries to give the prescribed margins and accepts exactly when all entries are nonnegative.
Proposition 5.2 (Bin rejection). An ideal trial succeeds with probability at least 1/64. Conditional on success, its output is exactly uniform on the feasible integer tables.
Proof. The unique bin-and-offset representation of a feasible integer table has a bin of weight one. The table’s probability before rejection is therefore
independent of the table. The dependent entries are integers because they are integer sums and differences. This proves conditional uniformity, including tables on faces and widths of different sizes.
For the success bound, let n_{\rm full} be the number of bins whose entire closure is contained in \mathcal P. Each has weight one and accepts every offset, so its contribution to the success probability is 1/Z_B. We compare n_{\rm full} and Z_B with \vol(\mathcal P). Set \mathcal P^- =\{u:T_{ij}(u)\ge2d/B\text{ for every }i,j\}. The affine map u\mapsto(1-\alpha)u+\alpha u_* with \alpha=4d^2/B sends \mathcal P into \mathcal P^- by Equation (5.4). Hence Bernoulli’s inequality gives
Except on grid boundaries, every point of \mathcal P^- lies in a bin whose entire closure is in \mathcal P: the change of any normalized entry across that bin is at most d/B. These bins cover \mathcal P^- up to a null set and each has volume one, so n_{\rm full}\ge\vol(\mathcal P^-)\ge\vol(\mathcal P)/2.
To bound Z_B, for any \gamma\ge0 consider the entire relaxed polytope \mathcal P_\gamma=\{u:T_{ij}(u)\ge-\gamma\text{ for all }i,j\} in \R^e, without a cube restriction. For u\in\mathcal P_\gamma the point
belongs to \mathcal P, since the affine coefficients sum to one and each T_{ij}(z)\ge0. Thus \mathcal P_\gamma\subset u_*+(1+2d\gamma)(\mathcal P-u_*), and
This argument also covers points with negative free coordinates. The sublevel set \{p\le(j+1)/A\} inside the sampling cube is contained in \mathcal P_{d/B+(j+1)/A}. Summing the upper bounds for the penalty layers and using Equation (5.7) gives
For the last numerical bound put a_0=2/d^2 and b_0=2/d^5. Since a_0+b_0\le1/4, both \exp(a_0) and \exp(a_0+b_0) are at most 4/3. The geometric sum is at most 4(4/3)/(1-(4/3)/2)=16, which is stronger than asserted. Consequently
5.2 An integral interpolation inequality
We supply the continuous inequality used to mix the bins. It is an analytic proof device; the algorithm never integrates or samples a real density. This finite-box statement is a special case of the Prékopa–Leindler inequality [13, 15]. We include the one-dimensional transport argument and induction on slices to specify the regularity needed here.
Lemma 5.3 (Finite-box integral interpolation). Let S_1,S_2,S_0 be bounded finite unions of open axis-aligned boxes in \R^q, and let 0<t<1, with (1-t)S_1+tS_2\subset S_0. Let f_1,f_2,f_0 be positive continuous functions on a compact box containing the closures of these sets. If
then
In particular, for finite unions S,D_0 of open boxes in the sampling cube,
Proof. We first prove the one-dimensional integral assertion in the slightly larger class needed for slices. Suppose F,G,H are nonnegative, supported on bounded finite unions of intervals, and, after removal of finitely many endpoints, are continuous and either zero or bounded above and below by positive constants on each interval piece. Assume H((1-t)x+ty)\ge F(x)^{1-t}G(y)^t whenever F(x)G(y)>0, apart from possible source endpoints. Source integrals zero give a trivial inequality; otherwise write M_F=\int F>0, M_G=\int G>0.
Let u(a),v(a), 0<a<1, be the quantiles of F/M_F and G/M_G. Split (0,1) at the cumulative probabilities of the finitely many support endpoints and continuity breakpoints of both densities. On each remaining open interval I, the quantiles are continuously differentiable, strictly increasing, and satisfy
These statements follow directly by inverting the continuously differentiable cumulative function on a positive interval piece, whose derivative is positive. The function z(a)=(1-t)u(a)+tv(a) is also strictly increasing and continuously differentiable on I. Its images z(I) for distinct pieces are disjoint. Change of variables on each piece, followed by the weighted arithmetic–geometric mean inequality, yields
The pieces have total parameter length one. A gap in a source support causes a quantile jump at one of the excluded parameter values; the corresponding gaps between image intervals merely omit nonnegative contributions to \int H. Thus neither disconnected supports nor density jumps require continuity across a gap.
The assertion for dimension q=1 follows by restricting the ambient continuous weights to their sets. Induct on q. For each first coordinate x, let S_i(x) be the slice in the remaining q-1 coordinates and put
Whenever S_1(x) and S_2(y) are nonempty, their interpolation is contained in S_0((1-t)x+ty). The induction hypothesis for these slices therefore gives
To justify the one-dimensional step for the marginals, partition the first-coordinate axis by all endpoints of all the boxes. On each open piece, a slice domain is a fixed union of boxes or is empty. In the nonempty case it has fixed positive volume. Each ambient weight has a positive minimum and finite maximum on the compact box, so its marginal is bounded above and below by positive constants there. Uniform continuity of the weight on the compact box proves continuity of the marginal on that piece by integration over this fixed domain. These are exactly the hypotheses of the one-dimensional argument just proved. Applying that argument and then iterated integration proves Equation (5.12).
Finally, the interpolation of two finite unions of open axis-aligned boxes is the finite union of all pairwise interpolations of their boxes, each again such a box. Convexity of p gives the required pointwise inequality for f_0=f_1=f_2=\rho, proving Equation (5.13).
5.3 Conductance of the bin chain
The following finite-chain estimate converts a cut bound into a mixing bound. We will use it for the bin chain here and for the small-state chain in Section 6.
Lemma 5.4 (Conductance and mixing). Let P be a reversible kernel on a nonempty finite set V, with stationary probabilities \pi(x)>0 and P(x,x)\ge1/2. Set Q(x,y)=\pi(x)P(x,y) and
where unordered pairs have distinct endpoints. If \Var_\pi H\le K\mathcal E_P(H) for all H, with K\ge1, then, writing \pi_{\min}=\min_{x\in V}\pi(x), for every integer t\ge0,
If, for some \kappa>0, every cut satisfies
then the variance inequality holds with K=2/\kappa^2.
Proof. For nonnegative g with \pi(g>0)\le1/2, integrate the cut inequality over A_u=\{x:g(x)^2>u\} to obtain
The last step is Cauchy–Schwarz and
Consequently \norm{g}_{L^2(\pi)}^2\le2\kappa^{-2}\mathcal E_P(g), also when g=0. Choose a \pi-median a of H and apply this to (H-a)_+ and (a-H)_+. Their squared norms sum to \norm{H-a}_{L^2(\pi)}^2, and their energies sum to at most \mathcal E_P(H), by the corresponding inequality on each edge. Since the variance is the minimum squared deviation from a constant, this proves the cut assertion.
For mixing, reversibility makes P self-adjoint on L^2(\pi) and gives \mathcal E_P(H)=\langle H,(I-P)H\rangle_\pi. The stochastic kernel 2P-I is an L^2(\pi) contraction by Jensen’s inequality and stationarity. Hence the eigenvalues of P are in [0,1]. The variance inequality bounds those on the mean-zero subspace by 1-1/K\le e^{-1/K}. For g_x(y)=\one_{\{y=x\}}/\pi(x)-1, reversibility gives
The L^2 contraction followed by Cauchy–Schwarz bounds the total variation distance by
which implies (5.14). On a singleton all asserted variances and distances vanish; it may simply be regarded as already mixed.
Use the axis-neighbor Metropolis chain on \mathcal V. Each of the 2e signed coordinate directions is proposed with probability
the unused probability, or a proposal leaving the cube, holds. A proposal v' within the cube is accepted with probability \min(1,W(v')/W(v)). This chain is reversible for \pi_B(v)=W(v)/Z_B and holds with probability at least 3/4.
Proposition 5.5 (Bin conductance and mixing). For every nontrivial cut of the bin states, its stationary edge conductance divided by the smaller stationary side mass is at least
Starting at any bin, after H=d^{50}(h+1)^2 steps the total-variation distance from \pi_B is at most 2^{-4(h+d)}.
Proof. Write \mu(E)=\int_E\rho and D=(0,K_0)^e. For a cut \mathcal V=V_1\sqcup V_2, choose S to be the union of the open bins on the side of smaller continuous mass. Then 0<\mu(S)\le\mu(D)/2. Set
We have S\subset M, by writing x=(1-t)x+tx for x\in S. Lemma 5.3 gives
This is actual gained mass even though S need not be convex.
We next cover this gain by neighborhoods of cut faces. Ignore the finite union of grid hyperplanes, a null set. If z\in M\setminus S, write z=(1-t)x+ty with x\in S, y\in D. The segment from x to z stays inside the open convex cube and has sup-norm length less than r. Its initial bin lies on the selected side and its terminal bin lies on the other side. Follow the segment through its finitely many grid crossings. At a crossing in several coordinates simultaneously, the incident bins are indexed by the two choices in each crossing coordinate, and are connected by axis-neighbor faces through that same point. If the incoming and outgoing bins have different labels, a face path between them contains an opposite-label pair. Its common closed face contains the crossing point. Since some crossing changes the label, z is at sup distance less than r from a cut face. No exterior face is needed: the entire segment lies in D.
For such a closed unit face F, take its sup-distance-r neighborhood intersected with D, denoted F^{(r)}. Its volume is at most
If v is the lower corner of either bin adjacent to F, every point z\in F^{(r)} satisfies \norm{z-v}_\infty\le1+r. Hence
and the same inequality holds for the other adjacent corner v'. Thus \mu(F^{(r)})\le4\min(W(v),W(v')). Combining the face cover with Equation (5.15), and writing D_i=\sum_{v\in V_i}W(v), gives
The second inequality follows from Equation (5.7): the selected continuous side has mass at least one quarter of its own discrete weight, which is at least \min(D_1,D_2). It does not require the two notions of smaller side to agree. Stationary edge conductance is q_B\min(W(v),W(v'))/Z_B. Since q_B\ge1/(16d), the cut ratio is at least \log(2)/(1024d^2K_0)\ge\kappa_B.
The weights satisfy 2^{-4Ad}\le W(v)\le1, so
Lemma 5.4 supplies inverse gap at most
It bounds the error at time H by \exp(4d^5-H/K_B). Since d^{18}\ge4d^5 and d^5h(h+2)\ge(d+1)h\ge h+d, we have
This proves the asserted error.
5.4 A bounded random-bit implementation
We finish the proof of Theorem 5.1, keeping explicit bounds that will also describe the finite output law in Section 6. Use the integer schedule
Run at most J independent trials, each running H bin-chain steps from 0. At the end of each bin walk use Equation (5.8), but obtain each offset from the bounded draw
Return the first feasible table. If all J trials fail, return a fixed greedy feasible table with the required margins.
Each offset probability differs from 1/w_{ij} by at most 2^{-k_{ij}}: its number of preimages is either the floor or the ceiling of 2^{k_{ij}}/w_{ij}. Thus its total-variation error is at most w_{ij}/2^{k_{ij}}\le2^{-4(h+d)}. Coupling the independent offsets coordinate by coordinate bounds their joint error by d2^{-4(h+d)}. Proposition 5.5 bounds the bin error by 2^{-4(h+d)}, so a complete implemented trial, including its success flag, differs from an ideal trial by at most (1+d)2^{-4(h+d)}.
Couple the J independent trial records until the first discrepancy. This bounds the difference between the implemented first-success procedure and its ideal counterpart by J(1+d)2^{-4(h+d)}, without conditioning on an approximate success event. By Proposition 5.2, the ideal procedure has uniform law on success and failure probability at most (63/64)^J. Its greedy fallback therefore changes the uniform law by at most this probability. The total error is at most
For explicit numerical bounds, d^4\ge128 gives (63/64)^J\le\exp(-J/64)\le2^{-2(h+1)}\le2^{-h-2}. Also d\le2^{d/2}, d+1\le2^d, and h+1\le2^h give J(1+d)2^{-4(h+d)}\le2^{-3h-d}\le2^{-h-2}. All actual outputs are feasible by the acceptance test or the fallback.
It remains to account for every computation in the bit model. At an integer bin corner v, the entries X_{ij}(v) are integer sums of products w_{ij}v_{ij} and margins. Since w_{ij}<C/B and v_{ij}<4B, their absolute values are at most a fixed multiple of dC; they have O(b+\log d) bits. The candidates for the maximum defining p(v) are the rational numbers
Cross multiplication, comparison, multiplication by A, and integer division compute E_v=\lfloor Ap(v)\rfloor exactly with polynomial bit cost. Denominators have O(b+\log d) bits and there are at most d candidates. In particular no evaluation of an exponential or integral is required. We have 0\le E_v\le4Ad, so a Metropolis acceptance is either certain or has probability 2^{-(E_{v'}-E_v)}, implemented by requiring that many fresh unbiased bits to be zero. The difference has absolute value at most 8Ad, a convenient uniform allowance. A draw of q_{\rm bin} bits proposes each signed coordinate direction by one code, with the remaining codes holding; this implements the stated proposal exactly.
The offset draw in Equation (5.17) uses O(b+h+d) bits and an integer multiplication and division on numbers of polynomial bit length. Table construction, feasibility tests, the greedy fallback, and the bounded loop counters also use polynomially many operations on polynomial-length integers. There are JH transitions and at most dJ offsets. Schoolbook integer arithmetic already yields a worst-case polynomial bound in d,b,h.
For later use, a uniform upper bound on the number of bits per transition and per offset is respectively
Unused transition bits, missing free coordinates, and unused trials after the first success can be padded with unread independent bits. Thus a trial has probabilities with common denominator 2^{R_1}, and the whole subroutine has probabilities with common denominator 2^{R_D}. This padding changes no output law. For an offset of width w and actual bit length k, its exact probability of value \beta is
It can therefore be tabulated by integer arithmetic without enumerating the random bit strings. The deterministic completion cases can use the same denominator allowances. This completes the proof of Theorem 5.1.
6 Sampling algorithms and exact correction
We now turn the weighted graph bound into an algorithm using unbiased random bits. All deterministic choices, including greedy completions, neighbor orders, and tie breaking, are fixed once and for all. Abbreviate \Omega(r,c) by \Omega. Write \nu_X for the uniform law on \mathcal F_X and z_0 for a greedy original table. Its restriction to the small slots gives a starting transversal X_0.
6.1 The ideal chain
Set
List the distinct feasible neighbors of a state X in a fixed order. Assign one of the 2^{q_{\rm s}} equally likely binary strings to each neighbor and let all remaining strings propose a hold. This gives every edge the same proposal probability p in both directions. As explained in Lemma 2.1, the list is obtained by testing all unit exchanges, the repair of X when it is a defect, and the uniquely reconstructed inverse repair of each possible ordered defect type. There are at most 5d^2+1 neighbors. Each test checks only coordinate bounds, the allowed occupancy pattern, and residual margins; it does not evaluate f.
Here is the completion adjustment used for a nonholding proposal X\to Y. For a nonempty block \mathcal B=I\times J, fix a reference row i_0 and column j_0, independently of X. Let \Delta R_i=R_i(Y)-R_i(X) and \Delta P_j=P_j(Y)-P_j(X) be the changes in its padded margins. Define the integer matrix D_{XY} by
The equality of total row and column changes verifies all its row and column sums, including the reference column. Also D_{YX}=-D_{XY}. Along a unit exchange or repair edge each individual residual changes by at most two; hence every displayed entry has magnitude at most 10d. These formulas also apply to a block with a single row or column.
The ideal transition draws a\sim\nu_X and accepts Y precisely when a+D_{XY} is nonnegative. It then belongs to \mathcal F_Y because its margins are already correct. A rejected proposal holds at X. If the block is empty, every edge proposal is accepted. Denote this ideal kernel by P.
Proposition 6.1 (Small-chain bound). The kernel P is lazy and reversible for \pi(X)=f(X)/\Lambda. On every edge it satisfies
If there is more than one state, its inverse spectral gap is at most d^{160}. Moreover \pi_{\min}\ge(C+1)^{-2d}, and, for every t\ge0,
A one-state chain is already stationary.
Proof. The proposal holds with probability at least 1-(5d^2+1)/(32d^2)>1/2, and rejection can only increase this probability. Translation by D_{XY} bijects the set of acceptable completions in \mathcal F_X with the corresponding set in \mathcal F_Y. Calling its cardinality c_{XY}=c_{YX} gives f(X)P(X,Y)=p c_{XY}=f(Y)P(Y,X).
Every nonempty completion-block margin is at least L. Rejection implies that one of at most d entries of a uniform completion is less than 10d. Lemma 2.2, with a=L and threshold 10d\le L/2, gives
Consequently c_{XY}\ge f(X)/2, and in particular c_{XY}\ge\min(f(X),f(Y))/2. Since p\ge1/(64d^2), both the stated transition bound and the Dirichlet-form comparison
follow. Theorem 4.3 and U=d^{20} now give an inverse-gap bound of
Indeed the coefficient inside parentheses is at most 770d^4U^6. The graph is connected by Theorem 4.3, and Proposition 2.3 gives \pi_{\min}\ge(C+1)^{-2d}. Lemma 5.4 now gives (6.1).
6.2 A bounded almost-uniform sampler
For an integer k\ge1, put
The implemented chain replaces every ideal completion draw by the subroutine of Theorem 5.1 with accuracy h; write \mu_X for its output law on \mathcal F_X and Q for the resulting kernel. Starting anew at X_0 on each trial, perform the following bounded procedure.
- 1.
Run Q for T transitions and then make one further, independent completion draw with law \mu_X at the final state.
- 2.
If X is a transversal and every large completion entry is at least L, subtract L on the large block and return the resulting original table. Otherwise this trial fails.
- 3.
Repeat for at most J_{\rm o} independent trials, and return z_0 if all of them fail.
All randomness in different draws and trials is fresh. In particular, a completion used to test a transition is discarded after that test; the current small state is the chain’s entire persistent state.
Theorem 6.2 (Almost-uniform sampling). The preceding procedure returns a feasible table with law p_k satisfying
Its worst-case number of bit operations is bounded by a fixed polynomial in d,b,k.
Proof. We first control adaptive approximation. The dense guarantee is uniform over feasible states: \TV(\mu_X,\nu_X)\le\eta:=2^{-h}. From a common state, couple the proposal and holding decision identically, and maximally couple the two completion draws if there is a nonholding proposal. Agreement of these draws gives the same acceptance decision and the same next state. Thus
Couple successively until the first disagreement. Conditional on agreement so far, the common state may be adaptive, but the same uniform conditional bound still applies. After T transitions and the terminal completion, the probability of a disagreement is at most (T+1)\eta. This argument uses neither reversibility nor a stationary-law assertion for Q. By Proposition 6.1, the additional error from replacing the ideal terminal state by a stationary one is at most \tau=(C+1)^{2d}e^{-T/d^{160}}.
In a stationary ideal trial every pair (X,a) has probability \pi(X)/f(X)=1/\Lambda. By Proposition 2.3, successful pairs are in bijection with \Omega, and the success probability s_*=|\Omega|/\Lambda is at least 1/[2(1+d^2)]. The first success among J_{\rm o} independent stationary trials therefore has, including the fallback, the exact law
For clarity, each particular table receives first-success mass \sum_{j=0}^{J_{\rm o}-1}(1-s_*)^j/\Lambda =[1-(1-s_*)^{J_{\rm o}}]/|\Omega|. Pregenerate all potential trials in both procedures, then apply the same deterministic first-success-or-fallback map. The union bound and contraction of total variation under a deterministic map give total error at most
In particular, no error is divided by a success probability.
Each term in (6.3) is at most 2^{-k-2}. Here are explicit checks. Put t=k+b\ge15, so d\le t, k+2\le t, and \log_2(C+1)<b. First,
For the second term,
Finally, since T+1\le2T,
Their sum is less than 2^{-k}.
For the running time, neighbor lists have polynomial size, and all state coordinates, residuals, and completion entries have O(b+\log d) bits. The proposal uses exactly q_{\rm s} unbiased bits. Each completion call has bounded polynomial bit cost by Theorem 5.1; the numbers of steps, trials, and calls in (6.2) are fixed polynomials. Comparisons, additions, integer multiplications and divisions, and loop counters all have polynomial bit cost, for example with schoolbook arithmetic. Only feasible completions and the feasible fallback can be returned. Empty and singleton-dimensional blocks use their deterministic completion rule. This proves the claimed worst-case bound.
6.3 Exact tabulation of the implemented law
The exact correction will need the law of the actual bounded algorithm, including approximate offsets, adaptive transitions, and both stopping rules. Only the small state persists between transitions. We can therefore cache the dense completion law for each small state, propagate the resulting finite kernel, and then apply the terminal and first-success rules. The spaces enumerated in this calculation do not grow with the accuracy request; accuracy changes only the iteration counts and the lengths of integers.
Proposition 6.3 (Law tabulation). For fixed margins and k, the entire law p_k can be computed exactly in
bit operations. It has a common dyadic denominator: p_k(z)=a_z/2^R, where a_z are nonnegative integers and R is bounded by a fixed polynomial in d,b,k. The sizes of all enumerated state spaces are independent of k.
Proof. The finite spaces. Use the dense sampler’s notation A=d^4 and K_0=4d^8. There are at most \mathsf S:=2^{2db} feasible small states, since their number is at most (C+1)^{2d}. A completion fiber, the original table space, an offset space, and the bin space each have at most \mathsf V:=2^{db} elements: use (C+1)^d\le2^{db} and K_0<C. They can be enumerated by listing coordinate arrays and retaining those that pass their defining tests. None of these coordinate ranges depends on k. This exhaustive calculation is used only for the exact correction, not during an ordinary run of the bounded sampler.
Caching a dense completion law. The following denominator allowances are uniform over all feasible small states, with h as in (6.2):
Every bin transition has denominator dividing 2^{Q_0}: its proposal needs \lceil\log_2(8d)\rceil bits and every dyadic acceptance test needs at most 8Ad bits. For each input X, enumerate its bins, compute their transition matrix as B_X/2^{Q_0} with integer entries, and propagate the point mass at zero for H steps. At step t the vector uses denominator 2^{tQ_0}; its next numerator is the previous integer vector multiplied by B_X. Adding contributions from many paths changes the numerator, not the denominator exponent.
Offsets are tabulated without enumerating their random bits. For width w and the actual bit count r=\lceil\log_2(w+1)\rceil+4(h+d)\le r_{\max}, the probability of offset u\in\{0,\ldots,w-1\} is
Indeed these two endpoints count the integers z with u\le wz/2^r<u+1. Integer ceiling division evaluates the count exactly. Enlarge its denominator to 2^{r_{\max}}, pad unused free coordinates to d, and combine with the propagated bin law. Enumerating bin and offset tuples, constructing the candidate table, and applying its feasibility test gives the implemented dense trial’s success numerators \alpha_X(a) and failure numerator \phi_X, all with denominator 2^{R_1}. Sorting of margins and its inverse are deterministic functions of X; we always record completions in the original block coordinates.
Let a_X^0 be the dense call’s fixed greedy fallback. The complete dense output law is exactly
This is a finite first-success sum and the all-fail mass. It introduces no division by a success probability. A deterministic empty or singleton-dimensional completion call uses the same denominator by ignoring the reserved bits. Cache (6.6) for each X.
Propagating the implemented chain. For a distinct neighbor Y the implemented transition is
For an empty block interpret the indicator as one. These entries share denominator 2^{R_{\rm D}+q_{\rm s}}. Since only X persists between steps and completion randomness is fresh, ordinary vector propagation v_{t+1}=v_tQ, starting at X_0, computes the exact adaptive state law. Append the terminal completion draw and the unpadding test. This yields the one-outer-trial success masses g(z) and failure mass f_0=1-\sum_z g(z) with common denominator 2^{R_{\rm T}}, where
Explicitly, g(z) is the sum of v_T(X)\mu_X(a) over pairs passing that test and producing z. The final law is
whose denominator divides 2^R for R=J_{\rm o}R_{\rm T}. Both geometric sums are evaluated by bounded integer multiplication and addition. Algebraically, the common denominators reserve ignored bits for holds, shorter draws, and stopped trials; neither tabulation nor sampling enumerates those bit strings.
Bit complexity. The denominator exponents are bounded by fixed polynomials. With q=d+b+k+2\ge31, one has h\le q^6, h+1\le q^7, Q_0\le q^6, r_{\max}\le q^7, H\le q^{64}, and hence
Here we used T\le q^{202}, J_{\rm o}\le q^5, and q_{\rm s}\le q^2. Probability numerators never exceed their common denominator. Intermediate products and sums may be stored with the prescribed stage’s denominator, so their bit lengths, including the offset counts in (6.5), are polynomial as well. Candidate tables that fail feasibility can have negative dependent entries, but their entries are integer sums of O(d) quantities of size O(C) and still have O(b+\log d) bits.
For each state, dense matrix propagation costs at most H\mathsf V^2 arithmetic operations. Bin–offset summation, even with a scan of all completions to identify the output, costs at most \mathsf V^3; the geometric composition costs at most J_{\rm D}\mathsf V. Constructing (6.7) uses at most \mathsf S^2\mathsf V terms. Small-state propagation uses T\mathsf S^2, terminal completion and output lookup at most \mathsf S\mathsf V^2, and the last geometric composition at most J_{\rm o}\mathsf V. Including the cache calculation for all \mathsf S states, the total number of arithmetic operations is at most 2^{10db}\operatorname{poly}(d,b,k); multiplying by the established polynomial bit cost per operation gives the stated, looser 2^{500db} bound. The iteration counts H,J_{\rm D},T,J_{\rm o} depend polynomially on k; none of the enumerated spaces does.
6.4 Exact uniform sampling
The final step uses the rare residual-mixture construction of Göbel, Liu, Manurangsi, and Pappik [11, Section 3.1, Algorithm 1 and Theorem 6]. A sufficiently accurate approximate law is dominated pointwise by a slight enlargement of the target law. Its remaining mass can therefore be sampled exactly on a rare branch. Here we verify this domination, implement the mixture with unbiased bits, and use Proposition 6.3 to account for the exhaustive work.
Theorem 6.4 (Exact sampling). There is an algorithm using unbiased random bits that terminates almost surely, outputs an exactly uniform element of \Omega, and has expected bit running time polynomial in d,b.
Proof. Set
Theorem 6.2 gives, for every z\in\Omega, p_k(z)\le1/M+\delta^2. Also M\le(C+1)^d\le2^{db} and D\ge db, so M\delta\le1. Therefore
It follows that r(z)=[1/M-(1-\delta)p_k(z)]/\delta is a probability law.
Use D independent bits to enter a correction branch precisely when all are zero. On the complementary event run the bounded sampler with accuracy k. On the correction branch, enumerate \Omega to obtain M and use Proposition 6.3 to compute p_k(z)=a_z/2^R. Form the integer weights
They are nonnegative by the pointwise domination just proved, and the sum follows from \sum_z a_z=2^R. Thus r(z)=n_z/(M2^R). All integers in (6.9) have O(R+D+\log M) bits; the fact that M can be large as a number does not make its binary representation long.
To sample this law exactly, put V=M2^R and draw a uniform integer in \{0,\ldots,V-1\} by using \lceil\log_2V\rceil bits and repeating whenever their value is at least V. If V=1, use zero bits. The acceptance probability is greater than 1/2, so the expected number of attempts is less than two, and termination is almost sure. A scan of cumulative weights n_z then selects the output exactly according to r. Use fresh bits on each attempt and after the branch decision.
The output law is (1-\delta)p_k+\delta r=\operatorname{Uniform}(\Omega). The correction branch has conditional expected cost at most 2^{500db}\operatorname{poly}(d,b,k), including enumeration, integer arithmetic, and the exact integer draw. Its contribution to the unconditional expectation is polynomial, since
Substituting k=2d^6b^2 into a fixed polynomial preserves polynomial dependence on d,b. The other branch and the branch decision also have polynomial cost. This proves the expectation and termination claims.
Proof of Theorem 1.1. If either dimension is empty, if N=0, or if one dimension is one, return the unique feasible table as in Section 2. Otherwise the parameters in (2.1) satisfy d=O(mn+m+n+1) and b=O(d+\log(N+1)+\log d). For the supplied integer k\ge1, Theorem 6.2 gives the first assertion. Theorem 6.4 gives the second. Their bounds therefore have the stated dependence on dimensions and binary margin size. All outputs are feasible, and the exact algorithm’s only unbounded loop is the almost-surely terminating integer rejection on its correction branch.
References
- [1]David Aldous and James Allen Fill. Reversible Markov Chains and Random Walks on Graphs. Unfinished monograph, 2002. Recompiled 2014. https://www.stat.berkeley.edu/~aldous/RWG/book.html. https://www.stat.berkeley.edu/~aldous/RWG/book.html.
- [2]Andrii Arman, Pu Gao, and Nicholas Wormald. Linear-time uniform generation of random sparse contingency tables with specified marginals. arXiv:2104.09413v2, 2021. Version 2, 15 June 2021. arXiv:2104.09413, https://arxiv.org/abs/2104.09413v2.
- [3]Petter Brändén and June Huh. Lorentzian polynomials. Annals of Mathematics (2), 192(3):821–891, 2020. doi:10.4007/annals.2020.192.3.4. doi:10.4007/annals.2020.192.3.4.
- [4]Mary Cryan and Martin Dyer. A polynomial-time algorithm to approximately count contingency tables when the number of rows is constant. Journal of Computer and System Sciences, 67(2):291–310, 2003. doi:10.1016/S0022-0000(03)00014-X. doi:10.1016/S0022-0000(03)00014-X.
- [5]Mary Cryan, Martin Dyer, Leslie Ann Goldberg, Mark Jerrum, and Russell Martin. Rapidly Mixing Markov Chains for Sampling Contingency Tables with a Constant Number of Rows. SIAM Journal on Computing, 36(1):247–278, 2006. doi:10.1137/S0097539703434243. doi:10.1137/S0097539703434243.
- [6]Stephen DeSalvo and James Y. Zhao. Random Sampling of Contingency Tables via Probabilistic Divide-and-Conquer. arXiv:1507.00070v4, 2016. Version 4, 29 February 2016. arXiv:1507.00070, https://arxiv.org/abs/1507.00070v4.
- [7]Persi Diaconis and Anil Gangolli. Rectangular Arrays with Fixed Margins. In David Aldous, Persi Diaconis, Joel Spencer, and J. Michael Steele, editors, Discrete Probability and Algorithms, pages 15–41, Springer, 1995. doi:10.1007/978-1-4612-0801-3_3. doi:10.1007/978-1-4612-0801-3_3.
- [8]Martin Dyer. Approximate counting by dynamic programming. In Proceedings of the Thirty-Fifth Annual ACM Symposium on Theory of Computing, pages 693–699, ACM, 2003. Published article. https://www.math.cmu.edu/~af1p/Teaching/MCC17/Papers/knapsack.pdf.
- [9]Martin Dyer and Catherine Greenhill. Polynomial-time counting and sampling of two-rowed contingency tables. Theoretical Computer Science, 246:265–278, 2000. Author version. https://web.maths.unsw.edu.au/~csg/papers/contingency.pdf.
- [10]Martin Dyer, Ravi Kannan, and John Mount. Sampling contingency tables. Random Structures & Algorithms, 10(4):487–506, 1997. Published article. https://www.math.cmu.edu/~af1p/Teaching/MCC17/Papers/contingency.pdf.
- [11]Andreas Göbel, Jingcheng Liu, Pasin Manurangsi, and Marcus Pappik. Perfect sampling from rapidly mixing Markov chains. arXiv:2410.00882v2, 2024. Version 2, December 6, 2024. arXiv:2410.00882, https://arxiv.org/abs/2410.00882v2.
- [12]Shuji Kijima and Tomomi Matsui. Polynomial Time Perfect Sampling Algorithm for Two-rowed Contingency Tables. Technical Report METR 2003-15, Department of Mathematical Informatics, Graduate School of Information Science and Technology, The University of Tokyo, 2003. https://www.keisu.t.u-tokyo.ac.jp/data/2003/METR03-15.pdf. https://www.keisu.t.u-tokyo.ac.jp/data/2003/METR03-15.pdf.
- [13]László Leindler. On a certain converse of Hölder’s inequality. II. Acta Scientiarum Mathematicarum, 33(3–4):217–223, 1972. Publisher archive. https://acta.bibl.u-szeged.hu/14358/.
- [14]Ben Morris. Improved bounds for sampling contingency tables. Random Structures & Algorithms, 21(2):135–146, 2002. doi:10.1002/rsa.10049. doi:10.1002/rsa.10049.
- [15]András Prékopa. On logarithmic concave measures and functions. Acta Scientiarum Mathematicarum (Szeged), 34:335–343, 1973. Author-hosted version. https://rutcor.rutgers.edu/Prekopa/pdf/SCIENT2.pdf.