A
D
V
E
R
T
I
S
E
M
E
N
T
ADVERTISEMENT
A Fully Polynomial Randomized Approximation Scheme for Perfect Matchings in General Graphs
expertly designed by an internal OpenAI model  ·  released 2026-09-23  ·  original PDF
Theorems: 4 Lemmas: 18 Proofs: 25
Formulas: 1,407 Words: 19,369 Play time: ~2 hours

>>> How to Play <<<
We give a fully polynomial randomized approximation scheme (FPRAS) for counting perfect matchings in arbitrary finite simple undirected graphs, resolving the general-graph perfect-matching approximation problem. The algorithm returns zero with certainty when no perfect matching exists. Otherwise, it achieves relative error ε with failure probability at most δ in worst-case bit time polynomial in the input length, $\varepsilon ^{-1}$, and $\log\delta^{-1}$.

>>> Level Map <<<
  1. Introduction
  2. History and significance
  3. Proof architecture
  4. Preliminaries
  5. Weighted matchings and holes
  6. Bottleneck similarities
  7. Tree bags
  8. Dirichlet energy and approximation
  9. Controlling the cost of unmatched vertices
  10. A subdivision with controlled holes
  11. The path profile
  12. The enlarged matching law
  13. Exact accounting for deleted vertices
  14. Charging the pairing capacity
  15. A quadrangulation adapted to the labels
  16. A two-coordinate energy inequality
  17. The pair kernel
  18. An exact identity on a cycle
  19. Encoding the demands
  20. Controlling context errors by cycle swaps
  21. Completion of the energy proof
  22. A sampler from replicated adjacent tiers
  23. An exact refresh at unit activities
  24. The product chain
  25. A quantitative sampling guarantee
  26. From samples to the number of perfect matchings
  27. The schedule and vertex scales
  28. Observables from one marked sample
  29. Estimating and restoring balance
  30. Success probability and output
  31. A bounded-bit implementation
  32. Sizes of the parameters and state spaces
  33. Rational bit lengths
  34. Random choices with a fixed number of bits
  35. Total bit cost
  36. Prescribed-degree subgraphs and fixed-cardinality matchings
  37. Constant-fibre reductions
  38. A deletion sampler for perfect matchings

Introduction

Let \(G=(V,E)\) be a finite simple undirected graph. A perfect matching is a set of edges incident to each vertex exactly once. Write \[Z(G)=\#\{M\subseteq E:M\text{ is a perfect matching of }G\}.\] A fully polynomial randomized approximation scheme approximates \(Z(G)\) within a prescribed relative error, with a prescribed success probability, in time polynomial in the input length and the reciprocal error. The confidence parameter enters through its logarithm. We prove the following theorem, including a bound on the time of every execution.

Theorem 1. There is a uniform classical randomized algorithm which, given \(G\) and rational parameters \(0<\varepsilon<1\) and \(0<\delta<1/2\), returns a nonnegative rational number \(\widehat Z\) such that \[\mathbb P\bigl[(1-\varepsilon)Z(G)\le \widehat Z\le(1+\varepsilon)Z(G)\bigr] \ge 1-\delta.\] If \(Z(G)=0\), the output is zero with certainty. The worst-case bit running time is polynomial in the input encoding length, \(\varepsilon^{-1}\), and \(\log\delta^{-1}\).

As consequences, 10 gives counting schemes for edge subsets with prescribed vertex degrees and for matchings of a specified size. On feasible inputs, its samplers always return a feasible object and approximate the corresponding uniform law in total variation.

History and significance

Perfect matchings illustrate the distinction between finding a combinatorial structure and counting its realizations. Edmonds gave a polynomial-time algorithm for finding a maximum matching in a general graph [5]. Valiant proved that exact counting is #P-complete even for bipartite graphs, where it is the permanent of a zero–one matrix [19]. Pfaffian methods give polynomial-time exact counting for planar graphs [13].

For approximation, three problems must be distinguished: counting all matchings, counting bipartite perfect matchings, and counting perfect matchings in general graphs. Jerrum and Sinclair gave an FPRAS for the total number of matchings in an arbitrary graph, summed over all cardinalities [10]. Their perfect-matching algorithm applied when the ratio of near-perfect matchings, which leave exactly two vertices unmatched, to perfect matchings was bounded by a fixed polynomial [10]. Without such a bound, perfect matchings can carry too little stationary mass for this sampling approach. Approximating the total number of matchings therefore does not isolate its perfect-matching contribution with relative accuracy.

Jerrum, Sinclair, and Vigoda removed the ratio restriction in the bipartite setting and obtained an FPRAS for the permanent of every nonnegative matrix [11]. Their method assigns weights to near-perfect states according to their two unmatched vertices and learns suitable weights while gradually changing edge activities. The general-graph question was explicitly raised by Jerrum and Sinclair [10] and remained a benchmark for approximate counting. Cai and Liu relate it to approximation for the eight-vertex model [2]; Fei, Goldberg, and Lu distinguish the spin-system parameter line equivalent to general perfect-matching approximation from the region covered by their FPRAS [7]. 1 answers the general-graph perfect-matching approximation problem affirmatively.

A direct extension of the bipartite chain faces a precise obstruction. Štefankovič, Vigoda, and Wilmes constructed graphs on which every JSV-type chain has either exponentially small stationary probability of perfect matchings or exponentially slow mixing, even with arbitrary weights depending on the hole pattern [16]. Here JSV type means the perfect-and-near-perfect state space with the specified Broder proposals and a Metropolis acceptance rule. The sampler below uses a different state space: a product of perfect-matching spaces on an enlarged colored graph, with exchanges of alternating cycles between coordinates. Its energy comparison is proved for these states and moves.

Subsequent permanent algorithms sharpen the bipartite result. Bezáková, Štefankovič, Vazirani, and Vigoda accelerated the cooling schedule and improved the analysis of the matching chain [1]. Chen, Vigoda, and Yang obtain a further improvement through restricted Poincaré inequalities and coupled flows [4]; Chen, Guo, Vigoda, and Yang develop an energy-weighted multicommodity-flow comparison and improve the running time again [3]. These results concern bipartite perfect matchings.

For nonbipartite graphs, Yi gives deterministic relative approximation for hafnians, the weighted sums over perfect matchings, when the \(n\)-vertex support has minimum degree at least \((1/2+\gamma)n\) and nonzero weights lie in \([\theta,1]\) [21]. Here \(0<\gamma<1/2\) and \(0<\theta\le1\) are fixed constants, and the polynomial running-time exponent may depend on them. 1 has no density promise on its simple unweighted input.

The proof below also builds on the methodological framework of weighted matching chains. Alternating overlays and weight-preserving switches underlie the encodings of Jerrum and Sinclair and of Jerrum, Sinclair, and Vigoda [10, 11]. Their sampling-to-counting strategy learns local partition ratios while gradually changing activities. Here these ratios are exposed by marked edges in an enlarged graph, and vertex scaling maintains a row-wise balance condition. The capacity bound, subdivision and marked-edge identities needed for this construction are proved explicitly.

Energy comparison through weighted demands has classical antecedents in multicommodity-flow bounds for mixing [15]. Our comparison differs from routing every demand along a path of chain transitions: long-arc conversions enter a signed identity and need not be legal single updates. The resulting estimate initially controls only additive functions of two matching coordinates. The separate product-space argument is essential to obtain a spectral gap for arbitrary functions. It uses the classical orthogonal decomposition into coordinate interactions [6]; the ordered assignment of residual terms and the replication estimate are proved below.

Proof architecture

The counting algorithm starts with the complete graph, whose perfect matchings are easy to count, and gradually suppresses the nonedges of \(G\) by decreasing their positive activities. It estimates the ratios of successive partition functions and multiplies them. To keep the observations statistically useful, it updates vertex scales from estimates of the two-hole partition ratios: partition functions after deleting two vertices, divided by the current partition function. Accurate estimates keep each row maximum between two absolute constants. A vertex scale multiplies every complete matching weight by the same factor, preserving the probability law used to estimate the current counting ratio.

The purpose of balance is to control the extra mass introduced by an auxiliary graph. We replace each logical edge by a weighted path, with a bijection between logical perfect matchings and matchings using only these real path edges. We then add weak clique edges in overlapping bags indexed by a tree. Under balance, the added edges increase the partition function by at most a factor of two, so a sample uses only real edges with probability at least one half. A specially marked auxiliary edge exposes the corresponding two-hole partition ratio. These are exact event identities; they provide both the counting estimate and the data for the next scale update.

To prove the inflation bound, 3 assigns a pairing capacity to each even hole set using the strongest bottleneck paths between its vertices. The capacity pays for the weights of possible added edges on those holes. Subdivision transfers this bound to the real graph while making incident effective strengths comparable. The resulting geometry supplies the tree of clique bags. Thus the hole estimates control the probability of the observable events, while the tree-bag structure supplies a sampler for their law.

That sampler uses local switches in one matching and exchanges alternating cycles between two matching coordinates. Its energy comparison initially controls only additive functions of the two coordinates. A quadrangulation adapted to the bag labels gives an exact signed identity for a whole-cycle difference ([lem:quadrangulation,thm:pair-energy]). The identity is not a route through chain transitions: long arc conversions may change many edges. Two-matching encodings instead compare its terms with local switches and cycle exchanges, with polynomially bounded multiplicity.

A ladder of nearby weight distributions then places many independent coordinates at each tier. An ordered orthogonal decomposition ensures that each coordinate-interaction term is charged to at most one pair. Replication reduces the coefficient of their combined contribution enough to absorb it. This yields a spectral gap for arbitrary functions of the product state (20). The bottom tier has unit activities and admits exact counting and ideal sampling by a tree dynamic program. The sampler requires no balance assumption. It therefore remains defined, with the same time bound, after an inaccurate empirical estimate; balance is used only to prove that accurate estimates propagate through the counting stages.

1 summarizes the changes of law. Finally, [sec:counting,sec:complexity] account for all arithmetic and finite-bit random choices. Every polynomial has an absolute degree; the constants are chosen for transparent estimates rather than practical efficiency.

The successive graphs and probability laws. Here \(n\) is the original vertex count and \(N\) the enlarged count. Scaling, subdivision, conditioning, and clamping have distinct roles.
Object Vertices Relation of matching laws
Input \(G\) \(n\) The target is its unweighted count \(Z(G)\).
Complete graph \(n\) Raw activities \(w^{(j)}\) gradually suppress the nonedges of \(G\).
Vertex scaling \(n\) Activities \(\lambda\) preserve the normalized raw matching law.
Real paths \(N\) Subdivision gives a matching bijection with a common weight multiplier.
Colored bags \(N\) Their activities \(W\) recover the real law when every sampled edge is revealed as real.
Weight tiers \(N\) Common-interval clamps of \(W\) connect the unit-activity law to the bag law on one colored state space.

The specialized combinatorial and sampling arguments are proved here. We use Edmonds’s algorithm for the initial matching-existence test and Hoeffding’s bounded-variable inequality for concentration and confidence amplification [5, 9].

Preliminaries

Logarithms are natural unless a base is indicated.

Weighted matchings and holes

We allow parallel edges distinguished by colors. A matching specifies the actual colored edges it uses. For positive rational activities \(a=(a_e)\), put \[\operatorname{wt}_a(M)=\prod_{e\in M}a_e,\qquad Z_a(-U)=\sum_{M\in\mathcal M(H-U)}\operatorname{wt}_a(M), \qquad Z_a=Z_a(-\varnothing),\] where \(H\) is the underlying graph and \(\mathcal M(H-U)\) is its set of perfect matchings after deleting \(U\). The empty graph has one perfect matching, of weight one. Whenever \(Z_a>0\), define \[g_a(U)=\frac{Z_a(-U)}{Z_a},\qquad \pi_a(M)=\frac{\operatorname{wt}_a(M)}{Z_a}.\] These weighted colored graphs are intermediate spaces constructed from the simple input graph. Their representation is explicit: vertices, colored edges, and rational activities are stored individually. The main theorem retains the finite simple undirected input model; it does not assert a counting algorithm for compressed edge multiplicities or for singleton-covering loops.

We call the vertices in \(U\) holes. For distinct vertices we abbreviate \(g_a(\{i_1,\ldots,i_k\})\) to \(g_a(i_1\cdots i_k)\). Collapsing parallel activities into their sum preserves every partition function. Conditional on a collapsed edge, its original type can be recovered with probabilities proportional to the summands.

The union of two matchings, with common edges retained twice, has maximum degree two. Its nontrivial components are alternating paths and even alternating cycles. Swapping the layers along a component preserves the product of their weights. In the union of two perfect matchings, deleting common identical edges leaves disjoint alternating cycles; different colors on the same pair of vertices form a cycle of length two. We fix a vertex order and a color order once and for all. They resolve every combinatorial tie in the proof.

Bottleneck similarities

For a positive weighted connected graph define \[ B_{ij}=\max\left\{1,\ \max_{P:i\leadsto j}\ \min_{e\in P}a_e\right\} \quad (i\ne j). \tag{1}\] Simple paths suffice. This symmetric similarity satisfies \(B_{ij}\ge\min\{B_{ik},B_{kj}\}\): concatenating two paths and erasing loops cannot lower their minimum activity. For \(t>1\), its equivalence classes are the connected components of the graph retaining edges of activity at least \(t\). Singletons are included. At \(t=1\) we take one class containing every vertex, consistently with the floor at one. For an even set \(U\) define its pairing capacity \[ \Phi_B(U)=\max_{\mathcal P}\prod_{ij\in\mathcal P}B_{ij}, \qquad \Phi_B(\varnothing)=1, \tag{2}\] where \(\mathcal P\) runs over pairings of \(U\). We use this quantity only in proofs; the counting algorithm never needs to enumerate pairings or compute \(\Phi_B(U)\) for a general hole set.

Tree bags

Definition 2. A tree-bag graph consists of a finite rooted tree of labels and a finite even vertex set. A label \(l\) at level \(k\) has height \(h_l=2^k\); the root has level zero and a child has level one greater than its parent. Each vertex belongs to either one label or two adjacent labels. The bag at \(l\) is the set of vertices belonging to \(l\). For each unordered pair of distinct vertices and each common label \(l\), there is one edge of color \(l\). There are no other edges. For an integer parameter \(D\ge1\), its reference activities obey \[ \frac{h_l}{D}\le W_{xy,l}\le3h_l. \tag{3}\] We also consider activities obtained by clamping all \(W_e\) to one common interval \([a,b]\subset(0,\infty)\).

Every vertex pair has at most two edge colors. At any bag, the interfaces with its parent and its different children are disjoint: a vertex in two such interfaces would have at least three memberships. Empty bags and repeated underlying vertex sets are permitted. Clamping is monotone and does not increase the ratio of a larger activity to a smaller one. In particular, reference activities of nearby labels remain comparable after clamping.

Dirichlet energy and approximation

For a finite reversible Markov kernel \(P\) with stationary law \(\mu\), its Dirichlet energy is \[ \mathcal E_{\mu,P}(f) =\frac12\sum_{x,y}\mu(x)P(x,y)(f(x)-f(y))^2. \tag{4}\] A Poincaré inequality \(\mathop{\mathrm{Var}}_\mu f\le\gamma^{-1}\mathcal E_{\mu,P}(f)\) means that the spectral gap is at least \(\gamma\). A symmetric proposal \(Q\) has Metropolis acceptance probability [14, 8] \(\min\{1,\mu(y)/\mu(x)\}\) for a proposed move from \(x\) to \(y\). Its off-diagonal stationary capacity is \[ \mu(x)P(x,y)=Q(x,y)\min\{\mu(x),\mu(y)\}. \tag{5}\] We regard inapplicable proposals as holding moves. All state spaces used below contain at least one perfect matching; thus their positive activities define probability laws with full support on that space.

Total variation is \(\|\mu-\rho\|_{\mathop{\mathrm{TV}}}=\frac12\sum_x|\mu(x)-\rho(x)|\). A deterministic map, or a common randomized postprocessing kernel, does not increase total variation, by the triangle inequality. Two finite laws at total variation distance \(\eta\) admit a coupling that disagrees with probability \(\eta\): first match the common masses \(\min(\mu(x),\rho(x))\), then couple the remainders. Applying this construction successively bounds the discrepancy probability of an adaptive simulation by the sum of its conditional one-step errors.

Controlling the cost of unmatched vertices

This section proves the bound that will control the additional edges in our sampling graph. It uses only alternating paths and differentiation of a finite partition function.

Let \(V\) have even cardinality \(n\ge2\), and give every edge of the complete logical graph \(K_V\) a positive activity \(\lambda_{ij}\). Use the weighted matching notation of 2, abbreviating \(\mathcal M(K_V-U)\) to \(\mathcal M(-U)\). For any positive activity array \(a\) on this graph, define the row maxima \[r_i(a)=\max_{j\ne i}g_a(ij).\] The activities \(a\) are balanced if \(1/4\le r_i(a)\le1\) for every \(i\). Let \(B\) be the bottleneck similarity of \(\lambda\) from (1), and let \(\Phi_B\) be its pairing capacity from (2).

The estimate we need controls every even hole set, although balance only bounds the two-hole ratios:

Theorem 3 (Logical hole bound). Let \(\lambda\) be balanced, let \(B\) be its bottleneck similarity, and set \[D_0=10^8(n+1)^4.\] For every even set \(U\subseteq V\), \[ g_\lambda(U)\Phi_B(U)\le 2D_0^{|U|/2}. \tag{6}\]

To prove this, we will add a small activity proportional to \(B_{ij}\) on every pair. Bounds for two and four holes keep the resulting partition inflation below two. Any pairing of an arbitrary hole set can then be inserted using the added edges, giving the stated bound.

We use two elementary alternating-path comparisons. Such weight-preserving overlays also underlie the weighted matching encodings in [10, 11]; the comparisons and their constants needed here are proved below. In an overlay of two matchings, edges retain their layer. Common edges can be kept as two parallel copies. A path starting at a vertex unmatched in exactly one layer is then uniquely determined, and switching its edges between the layers preserves the product of their weights.

Lemma 4 (Four-hole inequality). For any positive activities \(\mu\) and four distinct vertices \(a,b,c,d\), \[g_\mu(abcd)\le g_\mu(ab)g_\mu(cd)+g_\mu(ac)g_\mu(bd) +g_\mu(ad)g_\mu(bc).\] Consequently, if every row maximum is at most \(4\), then \[ g_\mu(\varnothing)=1,\qquad g_\mu(U)\le4\quad(|U|=2),\qquad g_\mu(U)\le48\quad(|U|=4). \tag{7}\]

Proof. Overlay \(M\in\mathcal M(-\{a,b,c,d\})\) and \(P\in\mathcal M(-\varnothing)\). The alternating path from \(a\) ends at one of \(b,c,d\), say \(b\). Switch that path between the layers. The output layers miss \(\{c,d\}\) and \(\{a,b\}\), respectively, and their product weight is unchanged. This map is injective for the specified endpoint \(b\): in the output overlay, follow the path from \(a\) and switch it back. The same argument applies to endpoints \(c,d\). Summing the three injective comparisons and dividing by \(Z_\mu^2\) proves the inequality. The remaining assertions follow immediately. ◻

The four-hole comparison controls small hole sets by row maxima. We next need an additional factor when two holes are joined by a strong path. Normalizing by the row maximum at the moving hole will make the successive relocation errors add, without multiplying along the path.

The next lemma is stated with \(\mu\ge\lambda\) so that it continues to apply while we add activities to the graph. Its bottleneck similarity always remains the one defined from \(\lambda\).

Lemma 5 (Relocating a hole along a strong path). Let \(B\) be defined by (1), and suppose that \(\mu_e\ge\lambda_e\) for every edge and \[\frac18\le r_i(\mu)\le4\qquad(i\in V).\] If \(|U|\in\{2,4\}\) and \(i,j\in U\) are distinct, then \[ g_\mu(U)\le\frac{10^5n}{B_{ij}}. \tag{8}\]

Proof. Throughout this proof, omit the subscript \(\mu\) from \(g\) and \(r\). Write \(B=B_{ij}\). For \(B\le8\), the assertion follows from (7). Suppose therefore that \(B>8\), and choose a simple path from \(i\) to \(j\) whose \(\lambda\)-activities, and hence its \(\mu\)-activities, are all at least \(B\).

We first give one step of the relocation. Let \(a\) be the hole currently on this path, let \(S\) be the current hole set, and let \(z\) be the next vertex. Thus \(a\in S\) and \(\mu_{az}\ge B\). If \(z\in S\), inserting \(az\) in a matching missing \(S\) is injective and increases its weight by \(\mu_{az}\). Hence \[ \frac{g(S)}{r_a}\le \frac{g(S\setminus\{a,z\})}{B r_a}\le\frac{32}{B}. \tag{9}\] The last inequality uses \(|S|\le4\), (7), and \(r_a\ge1/8\).

Now suppose \(z\notin S\). Choose \(p\ne z\) with \(g(zp)=r_z\). Inserting \(az\) gives \(g(az)\le1/\mu_{az}\le1/B<1/8\), so \(p\ne a\). Overlay \(M\in\mathcal M(-S)\) and \(P\in\mathcal M(-\{z,p\})\). The path from \(a\) starts with an edge of \(P\). Its endpoint belongs to exactly one of the following three cases.

  1. It ends at \(z\). Switching the path gives layers missing \(S\setminus\{a\}\cup\{z\}\) and \(\{a,p\}\). The product weight is unchanged.

  2. It ends at \(p\), which requires \(p\notin S\). Switching gives layers missing \(S\setminus\{a\}\cup\{p\}\) and \(\{a,z\}\). Insert \(az\) in the second layer, making it perfect. The product weight increases by \(\mu_{az}\ge B\).

  3. It ends at \(x\in S\setminus\{a,p\}\). Switching gives layers missing \(S\setminus\{a,x\}\) and \(\{z,p,a,x\}\). Insert \(az\) in the second layer; its remaining holes are \(\{p,x\}\). Again the product weight increases by at least \(B\).

These cases exhaust the possibilities. Indeed, the degree-one vertices in the overlay are exactly the symmetric difference of the two hole sets; if \(p\in S\), then \(p\) is isolated and cannot be an endpoint of the path.

The edge \(az\) is absent from both input layers, since the first misses \(a\) and the second misses \(z\). Switching cannot create an edge absent from the overlay. Each map is injective when its case and endpoint are specified. For case (i), the inverse switches the output path from \(a\). For cases (ii) and (iii), first remove the inserted edge \(az\) from the second output layer, then switch the path from \(a\) in the resulting overlay. This reconstructs both input layers, including their common edges. Summing over all inputs, using \(g(ap)\le r_a\), and dividing by \(Z_\mu^2r_z\) yields \[ \begin{split} g(S)\le{}&\frac{r_a}{r_z} g(S\setminus\{a\}\cup\{z\})\\ &+\frac{1}{B r_z}\left[ \mathbf 1_{\{p\notin S\}}g(S\setminus\{a\}\cup\{p\}) +\sum_{x\in S\setminus\{a,p\}} g(S\setminus\{a,x\})g(px)\right]. \end{split} \tag{10}\] An inapplicable first term inside the brackets is omitted entirely. The brackets are at most \(96\): for \(|S|=4\) their first term is at most \(48\) and their at most three product terms are each at most \(16\); for \(|S|=2\) the corresponding bound is \(8\). After division by \(r_a\), therefore, \[ \frac{g(S)}{r_a}\le \frac{g(S\setminus\{a\}\cup\{z\})}{r_z} +\frac{6144}{B}. \tag{11}\]

Starting at \(a=i\), apply this recurrence along the chosen path, keeping all holes in \(U\setminus\{i\}\) fixed. Stop just before reaching the first of these fixed holes; such a hole exists because the path ends at \(j\). The path is simple, so there are at most \(n-2\) recurrence steps, followed by (9). The normalization by the current row maximum makes the leading terms telescope. Since \(r_i\le4\), \[g(U)\le\frac{4\bigl(6144(n-2)+32\bigr)}{B} \le\frac{10^5n}{B},\] as required. ◻

Proof of 3. Temporarily add a distinguished parallel edge of activity \(tB_{ij}/D_0\) to every pair \(ij\), where \(0\le t\le1\). Collapsing parallel edges gives activities \[\mu_{ij}(t)=\lambda_{ij}+tB_{ij}/D_0.\] Write \(Z(t)=Z_{\mu(t)}\) and \(g_t=g_{\mu(t)}\); \(B\) remains fixed. All partition functions involved are polynomials in \(t\), and \(Z(t)>0\). Differentiation of their finite sums gives \[ \frac{d}{dt}\log Z(t)=\frac1{D_0}\sum_{ij}B_{ij}g_t(ij), \tag{12}\] where sums over edges are unordered, and for distinct \(x,y\), \[ \frac{d}{dt}g_t(xy) =\frac1{D_0}\sum_{ij:\{i,j\}\cap\{x,y\}=\varnothing} B_{ij}g_t(xyij) -g_t(xy)\frac{d}{dt}\log Z(t). \tag{13}\]

On any initial time interval during which all row maxima belong to \([1/8,4]\), Lemma 5 bounds every summand \(B_{ij}g_t(ij)\) and every summand \(B_{ij}g_t(xyij)\) by \(10^5n\). Since \[\frac{\binom n2\,10^5n}{D_0}<\eta, \qquad \eta=10^{-3},\] we obtain, throughout that interval, \[0\le\frac{d}{dt}\log Z(t)\le\eta, \qquad -\eta g_t(xy)\le\frac{d}{dt}g_t(xy)\le\eta.\] Integrating gives \[e^{-\eta t}g_0(xy)\le g_t(xy)\le g_0(xy)+\eta t.\] For the lower row bound, fix a neighbor maximizing the row at time zero; the moving row maximum is at least this one evolving entry. Consequently, balance at time zero implies \[\frac14e^{-\eta}\le r_i(\mu(t))\le1+\eta.\] Both bounds lie strictly inside \([1/8,4]\). By continuity, the row maxima cannot first leave this interval before time \(1\): at a proposed first exit the displayed strict bounds still hold and persist on a neighborhood. Thus all preceding estimates hold on \([0,1]\), and \[ \frac{Z(1)}{Z(0)}\le e^\eta<2. \tag{14}\]

Choose a pairing \(Q\) of \(U\) attaining \(\Phi_B(U)\). At time \(1\), keep the original and added parallel edges distinguished. To each original matching in \(\mathcal M(-U)\), add the edges of \(Q\) using their added copies, of activities \(B_{ij}/D_0\). This is an injective map into perfect matchings at time \(1\), and it multiplies every weight by \(\Phi_B(U)/D_0^{|U|/2}\). Hence \[Z_\lambda(-U)\frac{\Phi_B(U)}{D_0^{|U|/2}}\le Z(1).\] Divide by \(Z(0)=Z_\lambda\) and apply (14). ◻

A subdivision with controlled holes

The sampler will use additional clique edges. To control the mass these edges introduce, we first replace each logical edge by a path. The path profile has two roles: equal adjacent factors make the ratio of its two matching patterns telescope, and the gradual change from each endpoint to the middle makes incident effective strengths comparable. We first construct the enlarged graph and identify its marked laws, then bound the mass introduced by its additional edges.

Throughout this section the logical graph is the complete graph on an even number \(n\ge2\) of vertices, with positive rational activities \(\lambda_{uv}\le4^K\), where \(K\ge0\) is an integer. Write \(B\) for its bottleneck similarity, and put \[ H_u=\max_{v\ne u}B_{uv},\qquad p=2K+2,\qquad N=n+4p\binom n2,\qquad D=100N^2D_0. \tag{15}\] Here \(D_0=10^8(n+1)^4\) is the constant in 3. Thus \(1\le B_{uv}\le H_u\le4^K\).

The path profile

Orient each logical edge \(e=uv\) by the fixed vertex order, and replace it by a path \[x_0=u,x_1,\ldots,x_{4p},x_{4p+1}=v.\] Internal vertices of different paths are distinct. Denote the activity of \(x_{j-1}x_j\) by \(t_j=t_j^e\). For \(1\le r\le p\), set \[\begin{align*} t_{2r-1}=t_{2r} &=\max\{B_{uv},H_u2^{-(r-1)}\},\\ t_{4p+3-2r}=t_{4p+2-2r} &=\max\{B_{uv},H_v2^{-(r-1)}\},\tag{16}\\ t_{2p+1}&=\lambda_{uv}. \end{align*}\] We call these the real edges and write \(Z'\) and \(g'\) for their partition function and hole ratios. Let \(B'\) be their bottleneck similarity. The two innermost equal pairs have activity \(B_{uv}\), because \(H_u2^{-(p-1)},H_v2^{-(p-1)}\le1/2\).

Lemma 6. The real graph has \(N\) vertices. Its perfect matchings are in bijection with logical perfect matchings, and \[ Z'=C_0 Z_\lambda, \qquad C_0=\prod_e\prod_{\substack{1\le j\le4p+1\\j\text{ even}}}t_j^e. \tag{17}\] On a noncentral real edge, its effective strength \(B'\) equals its activity. On the central edge of the path for \(uv\), it equals \(B_{uv}\). Incident effective strengths differ by a factor of at most two. For an internal vertex \(x_j\), its maximum incident effective strength is \[T_j= \begin{cases} t_j,&1\le j\le2p,\\ t_{j+1},&2p+1\le j\le4p. \end{cases}\] Its home terminal is \(u\) in the first case and \(v\) in the second. Every edge on its leg to its home has activity at least \(T_j\).

Proof. An intact path has exactly two ways to match its internal vertices: the even-indexed edges, which use neither terminal, or the odd-indexed edges, which use both. The ratio of the latter weight to the former is \(\lambda_{uv}\), since all the noncentral factors cancel in equal adjacent pairs. A real perfect matching therefore chooses the odd tiling precisely on a logical perfect matching. This proves the bijection and [eq:real-partition].

Every noncentral edge has an equal-activity twin sharing an internal vertex of degree two. A path connecting its endpoints that avoids that edge must use the twin. Its bottleneck therefore cannot exceed the edge activity, and the direct edge attains that activity.

The minimum activity on the full path replacing \(e\) is \(\lambda_e\). Consequently, for every \(t>1\), real edges of activity at least \(t\) connect two terminals exactly when logical edges of activity at least \(t\) connect them: a simple path between terminals traverses complete subdivision paths. In particular \(B'\) restricted to terminals is \(B\). Let \(a=x_{2p}\) and \(b=x_{2p+1}\) be the ends of the central edge. The legs from \(a,b\) to \(u,v\) have minimum activity \(B_{uv}\). If \(B_{uv}>\max\{1,\lambda_{uv}\}\), a logical path attaining \(B_{uv}\) avoids \(uv\), and its subdivision together with these legs connects \(a\) to \(b\) with bottleneck \(B_{uv}\). If \(B_{uv}=\max\{1,\lambda_{uv}\}\), the central edge and the floor at one already give the lower bound. For the upper bound, any alternative path from \(a\) to \(b\) must first use an edge on a leg of activity \(B_{uv}\). Thus \(B'_{ab}=B_{uv}\) in all cases.

Along each half of a path the displayed profile is nonincreasing toward the center and successive values differ by at most two. The effective strength at the center agrees with both innermost pairs. At a terminal \(u\), every first edge has activity \(H_u\). These facts give all remaining assertions. ◻

The enlarged matching law

For each integer \(0\le k\le\lfloor\log_2\max_uH_u\rfloor\), take one label for every component of the enlarged graph whose retained edges have effective strength at least \(2^k\), including singleton components. A label at level \(k>0\) has as parent its containing component at level \(k-1\). At level zero there is one component; these labels therefore form a rooted tree. Components recurring at different levels are still different labels.

Label each real edge \(xy\) by the component containing it at level \(\lfloor\log_2B'_{xy}\rfloor\). A vertex belongs precisely to the labels of its incident real edges. Equal-level incident labels are identical, and the factor-two bound in 6 implies that there are at most two incident levels. If there are two, they are consecutive and their labels are parent and child. Thus these memberships satisfy 2. In particular, a bag is the set of vertices with that membership; it need not be the entire threshold component defining its label.

Within every bag of label \(l\) and height \(h_l\), add a virtual edge of activity \(h_l/D\) for each vertex pair. Collapse any real edge of color \(l\) into the virtual edge with the same endpoints and color, adding its activity. This gives one colored edge per common label, of activity \[W_{xy,l}=h_l/D+ \begin{cases} t_{xy},&xy\text{ is a real edge with label }l,\\ 0,&\text{otherwise}. \end{cases}\] Since a real edge assigned to \(l\) has \(t_{xy}\le B'_{xy}<2h_l\), these weights satisfy [eq:bag-weight-range]. Also \(1/D\le W_{xy,l}\le3\cdot4^K\).

For each logical edge \(e\), split off activity \(1/D\) from the virtual activity on its central colored edge, and mark that portion as the probe for \(e\). This is possible because \(h_l\ge1\). After sampling a colored matching, independently reveal the portion of each used edge in proportion to its real, probe, and remaining virtual activities; zero portions are omitted.

1 shows the two real tilings and the probe on one illustrative path.

One subdivision path with \(K=1\), \(p=4\) and \(4p+1=17\) edges. The top labels are the real activities: \(H_u=4\), \(H_v=B_{uv}=2\), and \(\lambda_{uv}=1/2\); the central edge has effective strength \(B'_{x_8x_9}=2\). Solid edges show the selected real tiling. The even tiling uses neither terminal, and the odd tiling uses both; the odd-to-even weight ratio is \(\lambda_{uv}\). The last row uses the probe portion of the central colored bag edge and real portions elsewhere. Here the central label has height \(h_l=2\), so its collapsed activity \(1/2+2/D\) consists of real activity \(1/2\), probe activity \(1/D\), and remaining virtual activity \(1/D\). The probe forces the real edges on the two outer legs to use both terminals. Their combined weight equals the even-tiling weight, so the remaining paths represent a logical matching with \(u,v\) deleted.

Let \(Z_{\mathrm{bag}}\) be the colored partition function of the enlarged graph, and put \(I=Z_{\mathrm{bag}}/Z'\). This ratio measures the mass introduced by the auxiliary edges.

Proposition 7 (Marked matching laws). For arbitrary positive logical activities, sample from the bag matching law and reveal the edge portions as above. The all-real event has probability \(1/I\); conditional on this event, the decoded logical matching has law \(\pi_\lambda\). For each logical edge \(uv\), \[ \mathbb P(\text{probe for }uv\text{ is used and all other edges are real}) =\frac{g_\lambda(uv)}{DI}. \tag{18}\] Conditional on this event, the residual logical matching has the \(\lambda\)-weighted perfect-matching law on the vertices other than \(u,v\).

Proof. Revealing portions recovers the weighted law before the real and virtual activities were collapsed. The all-real matchings have total weight \(Z'=C_0Z_\lambda\), and their normalized law is transported to \(\pi_\lambda\) by 6.

Now require the probe on the path for \(uv\) and real edges everywhere else. The probe matches \(x_{2p}\) to \(x_{2p+1}\). The remaining vertices on its path have unique real tilings: the left one uses \(u\), and the right one uses \(v\). Equal adjacent activities in (16) show that their combined weight is exactly the even-edge baseline weight of this path. Other paths incident to \(u\) or \(v\) must use their even tilings. The remaining paths retain their even and odd alternatives, with ratio \(\lambda_e\). Consequently these marked matchings are in bijection with logical matchings missing \(u,v\), and every weight is multiplied by \(C_0/D\). Their total mass is \(C_0 Z_\lambda(-uv)/D\). Dividing by \(Z_{\mathrm{bag}}=IC_0Z_\lambda\) proves (18); the same constant weight multiplier proves the conditional-law assertion. ◻

The identities show what the enlarged graph provides to the counting algorithm. To use its all-real event with polynomially many samples, we also need a uniform lower bound on that event’s probability. The next lower-bound estimate requires balance; the construction and the exact laws above do not.

Proposition 8 (Bounded inflation). If the logical activities are balanced, then \[ 1\le I\le2. \tag{19}\]

We prove this bound in the remainder of the section. A collection of virtual edges leaves a set \(U\) of endpoints to be removed from a real matching. Its added weight must therefore be compared with \(g'(U)\). The next two subsections transfer the logical hole estimate to these enlarged hole sets.

Exact accounting for deleted vertices

We next describe exactly what deleting internal vertices does to the logical graph. A path is broken if at least one of its internal vertices is deleted. Let \(E_{\mathrm{br}}(U)\) be the set of logical edges whose paths are broken by a hole set \(U\).

Consider the ordered internal holes on a broken path. If a real completion exists, successive hole indices alternate in parity, because the intervening internal run must have even order. A first hole of even index forces the prefix to match the terminal \(u\); we say that this hole consumes \(u\) and map it to \(u\). A last hole of odd index similarly consumes and maps to \(v\). Remove all consumed holes (zero, one, or two) from the list. The remaining holes split, in their order, into pairs \((j,k)\) with \(j\) odd and \(k\) even; call these neutral pairs. There is no ambiguity when the list has one hole, since it cannot both have even and odd index.

Let \(R\) be the set of explicitly deleted terminals together with all consumed terminals. Feasibility requires these terminals to be distinct. To each consumed hole \(x_j\) assign the factor \[f_j= \begin{cases} 1,&\text{if it maps to its home terminal},\\ \lambda_e/T_j,&\text{if it maps to the other terminal}. \end{cases}\] For a neutral pair \((j,k)\) assign \[ f_{jk}= \begin{cases} T_j^{-1},&j,k\le2p,\\ T_k^{-1},&j,k\ge2p+1,\\ \lambda_e/(T_jT_k),&j\le2p<k. \end{cases} \tag{20}\] Let \(F=F(U)\) be the product of all these factors on all broken paths; an empty product is one. Both \(R\) and \(F\) depend only on \(U\) and the fixed path profiles, not on a choice of completion.

For a set \(E_0\) of logical edges, write \(Z_\lambda(-R;E_0\text{ forbidden})\) for the partition function after deleting \(R\) and forbidding those edges.

Lemma 9. If an even hole set \(U\) has a real completion, then \(R\) is even, \(|R|\le|U|\), and \[ Z'(-U) =C_0 F(U) Z_\lambda\bigl(-R;E_{\mathrm{br}}(U)\text{ forbidden}\bigr). \tag{21}\] In particular, \(g'(U)\le F(U)g_\lambda(R)\).

Proof. Fix a broken path. A prefix ending immediately before a first hole of index \(j\) has \(j-1\) internal vertices. If \(j\) is odd it uses the even tiling and leaves \(u\) unused; if \(j\) is even it uses the odd tiling and consumes \(u\). The suffix has the analogous alternatives. Every run between consecutive holes has a unique tiling, since its order is even. These parity conditions prove the stated description of consumed holes and neutral pairs. On each path the number of consumed holes has the same parity as the number of internal holes. Adding explicit terminal holes gives \(|R|\equiv|U|\pmod2\). Distinctness and \(|R|\le|U|\) follow from feasibility and the fact that each consumed terminal is charged to a different hole.

For completeness, all factors can be obtained from one prefix ratio. For even \(j\), define \[P(j)= \frac{\prod_{i\le j,\ i\text{ odd}}t_i} {\prod_{i\le j,\ i\text{ even}}t_i}, \qquad P(0)=1.\] The profile gives \[P(j)= \begin{cases} 1,&j\le2p,\\ \lambda_e/T_j,&j\ge2p+2. \end{cases}\] This is the factor for a first even-indexed hole consuming \(u\); reflection gives the factor for a last odd-indexed hole consuming \(v\). For a neutral pair \((j,k)\), its shifted tiling relative to the even-edge baseline contributes \[\frac{\prod_{i=j+2,j+4,\ldots,k-1}t_i} {\prod_{i=j+1,j+3,\ldots,k}t_i} = \frac{P(k)}{P(j-1)t_j}.\] If \(j\) is odd on the left, its denominator is \(T_j\); if \(j\) is odd on the right, its denominator is \(\lambda_e\), also when \(j=2p+1\). Substitution proves [eq:neutral-factors]. Prefixes and suffixes that do not consume a terminal, and runs outside these shifted intervals, retain their baseline even edges. Thus the product \(F\) accounts for all changes to the baseline on broken paths.

Every completion now determines a logical matching on the intact paths, using exactly the terminals outside \(R\). Conversely, take any logical perfect matching on the vertices outside \(R\) that uses no broken edge. Give its selected intact paths their odd tilings, give other intact paths their even tilings, and fill all broken paths by the uniquely forced runs just described. The distinctness conditions ensure that no terminal is used twice or is both used and deleted. This reconstructs a real completion and is inverse to the first map. Its weight is \(C_0F\) times the logical weight, which proves [eq:deletion-identity]. Omitting the forbidden-edge condition and dividing by [eq:real-partition] gives the inequality. ◻

Charging the pairing capacity

The deletion identity gives a factor \(F(U)\) and a logical hole set \(R\). To transfer the logical bound, we must compare the pairing capacity of \(U\) with that of \(R\). The next lemma expresses both capacities through threshold classes. Throughout the comparison, these classes belong to the original undeleted graphs, so they are independent of the completion being counted.

Lemma 10 (Pairings in a hierarchy). Let \(B\ge1\) be a symmetric similarity on a finite vertex set \(X\), satisfying \(B_{ij}\ge\min\{B_{ik},B_{kj}\}\). Let \(\mathcal C_t\) be the equivalence classes of \(B\ge t\), including singletons. For every even set \(U\subseteq X\), \[ \log\Phi_B(U) =\int_1^\infty\sum_{C\in\mathcal C_t} \left\lfloor\frac{|C\cap U|}{2}\right\rfloor\frac{dt}{t}. \tag{22}\] There is one pairing that attains the maximum number of internal pairs in every threshold class simultaneously.

Proof. For any pairing \(Q\), \[\log\prod_{ij\in Q}B_{ij} =\int_1^\infty |\{ij\in Q:B_{ij}\ge t\}|\,\frac{dt}{t}.\] Inside a threshold class \(C\), there are at most \(\lfloor |C\cap U|/2\rfloor\) pairs of \(Q\), proving the upper bound.

The threshold classes form a laminar family: any two are disjoint or one contains the other. Process its finitely many distinct classes from smaller to larger, starting with the singletons. In each class, pair its currently unpaired elements of \(U\) arbitrarily until at most one remains. When a class \(C\) has been processed, exactly \(\lfloor|C\cap U|/2\rfloor\) pairs lie inside it. Subsequent processing cannot create another pair inside \(C\), because at most one element of \(C\cap U\) remains unpaired. The final class is \(X\), and \(|U|\) is even, so the procedure produces a pairing. It attains every floor count, and therefore attains the integral upper bound. ◻

Lemma 11. If the logical activities are balanced, then for every even set \(U\) of enlarged vertices, \[g'(U)\Phi_{B'}(U)\le2D_0^{|U|/2}.\] More precisely, for every \(U\) with a real completion, the deterministic quantities above satisfy \[ F(U)\Phi_{B'}(U)\le\Phi_B(R). \tag{23}\]

Proof. The assertion is immediate if \(U\) has no completion, so suppose otherwise. For a threshold \(t>1\) and any set \(A\) of enlarged vertices, let \[S'_t(A)=\sum_{C}\left\lfloor\frac{|A\cap C|}{2}\right\rfloor,\] where \(C\) ranges over the threshold classes of \(B'\). Define \(S_t\) on logical vertices in the same way using \(B\). These definitions make sense even when \(A\) has odd cardinality. The threshold partitions remain those of the undeleted graphs throughout this proof; only the sets of holes are changed.

By 6, an internal vertex \(x_j\) is isolated in the threshold partition precisely when \(T_j<t\); otherwise it is connected to its home terminal. Call it active in the latter case. The threshold relation induced on terminals is exactly the logical relation. These statements can equivalently be checked using raw real edges of activity at least \(t\), since taking the bottleneck closure leaves threshold components unchanged.

Remove the neutral pairs one at a time from the current hole set. For a pair on the same side, its active vertices lie in one class. Removing it reduces \(S'_t\) by at most \[\mathbf 1_{\{\max(T_j,T_k)\ge t\}}.\] Indeed, two active holes are removed from one class, one active hole reduces a class floor by at most one, and an inactive hole is in a singleton class and contributes zero. On the left \(\max(T_j,T_k)=T_j\); on the right it is \(T_k\). For a cross pair, the loss is at most \[\mathbf 1_{\{T_j\ge t\}}+\mathbf 1_{\{T_k\ge t\}} -\mathbf 1_{\{\lambda_e\ge t\}}.\] To see the subtracted term, when \(\lambda_e\ge t\) both vertices are active and are connected by the full path, so their removal reduces a single class floor by one. Otherwise the bound is the sum of the separate active-hole bounds. These arguments apply to the current set after any preceding removals.

Next consider each consumed hole mapping away from home. If it is active and \(\lambda_e<t\), discard it. The floor loss is at most \[\mathbf 1_{\{T_j\ge t\}}-\mathbf 1_{\{\lambda_e\ge t\}}.\] The expression is nonnegative, since \(T_j\ge B_e\ge\lambda_e\). Every remaining active consumed hole can be mapped to its consumed terminal within its threshold class: a home mapping always has this property, and an away mapping retained by the rule has \(\lambda_e\ge t\). Together with explicitly deleted terminals, these maps are injective, by the distinctness in 9. Inactive internal holes lie in singleton classes and contribute no floor. Hence the floor sum remaining after the removals and discards is at most \(S_t(R)\).

Integrate these bounds against \(dt/t\) on \((1,\infty)\). By 10, the integral of \(S'_t(U)\) is \(\log\Phi_{B'}(U)\), and that of \(S_t(R)\) is \(\log\Phi_B(R)\). For a same-side neutral pair the integrated charge is exactly \(-\log f_{jk}\). For a cross pair it is \[\log T_j+\log T_k-\log\max\{1,\lambda_e\} \le-\log f_{jk}.\] For an away-mapped hole it is \[\log T_j-\log\max\{1,\lambda_e\}\le-\log f_j.\] Home mappings cost zero. Summing proves \(\log\Phi_{B'}(U)\le\log\Phi_B(R)-\log F\), which is [eq:threshold-charge]. Finally, [lem:deletion-accounting,thm:logical-hole-bound] give \[g'(U)\Phi_{B'}(U) \le g_\lambda(R)\Phi_B(R) \le2D_0^{|R|/2} \le2D_0^{|U|/2}.\] ◻

Proof of 8. Expand the partition function before collapsing real and virtual portions. A nonempty partial matching \(Q\) of \(a\) colored virtual edges, with endpoint set \(U\), contributes relative to \(Z'\) the mass \[g'(U)\prod_{xy,l\in Q}\frac{h_l}{D}.\] Vertices sharing \(l\) lie in the same threshold component at \(h_l\), so \(h_l\le B'_{xy}\). Their pairing therefore gives \[g'(U)\prod_{xy,l\in Q}\frac{h_l}{D} \le D^{-a}g'(U)\Phi_{B'}(U) \le2(D_0/D)^a\] by 11. A vertex pair has at most two common labels, so there are fewer than \(N^2\) colored virtual edges and at most \(N^{2a}\) choices for \(Q\). The empty \(Q\) contributes one. Consequently, \[1\le I\le1+2\sum_{a\ge1}(N^2D_0/D)^a =1+\frac2{99}<2.\] ◻

A quadrangulation adapted to the labels

We now turn to the sampling branch of the proof. Its input is a tree-bag graph as in 2; no balance assumption is needed. To compare two alternating matchings on a cycle, we shall subdivide its polygon into four-corner cells. A cell side may stand for a long arc of the original cycle. We first describe the matching patterns on such an arc and the endpoint repairs the cells must permit, then construct a quadrangulation with those properties.

Let \(\mathcal C\) be a simple even cycle of length \(m\ge4\) in the colored bag graph. Each edge retains its color, which is a node of the label tree. For a vertex \(v\) of \(\mathcal C\), define \[S_v=\{\text{labels of the two edges of $\mathcal C$ incident to $v$}\}.\] Thus \(S_v\) is a singleton or consists of two adjacent tree nodes. These sets refer to the original full cycle throughout the construction; adding a diagonal never changes them. In particular, the cyclic sequence of edge labels is a walk on the tree, with repetitions allowed.

An arc is one of the two paths in \(\mathcal C\) between distinct vertices, specified together with its endpoints. Its length is its number of edges. We use only odd arcs. An arc is admissible if its endpoints \(u,v\) satisfy \(S_u\cap S_v\ne\varnothing\). The clique property then supplies an edge joining them with any chosen label in this intersection.

For an admissible odd arc \(J=(v_0,\ldots,v_s)\), choose such a colored endpoint chord \(e_J\) and put \[T_J=\{v_0v_1,v_2v_3,\ldots,v_{s-1}v_s\},\qquad N_J=\{v_1v_2,v_3v_4,\ldots,v_{s-2}v_{s-1}\}, \qquad C_J=N_J\cup\{e_J\}.\] All path edges retain their cycle colors. The through pattern \(T_J\) and the closed pattern \(C_J\) both perfectly match the vertices of \(J\); the interior pattern \(N_J\) leaves only its two endpoints unmatched. The symbol \(C_J\) denotes a matching, not the original cycle. Call \(J\) short if \(s=1\) and long otherwise. On a short arc choose its actual cycle edge as \(e_J\), so \(T_J=C_J\). When a diagonal later represents two complementary arcs, we use the same colored chord in both patterns. 2 shows these patterns on a long arc.

The two patterns on a long odd arc, illustrated for \(J=(v_0,\ldots,v_5)\). Solid edges form the indicated matching; faint dashed edges only locate the underlying path. Both \(T_J\) and \(C_J\) perfectly match the same vertices. The latter uses the interior pattern \(N_J\) and the endpoint chord \(e_J\); their union \(T_J\cup C_J\) is the alternating cycle consisting of \(J\) and its chord. Replacing \(T_J\) by \(C_J\) can change interior edges; this replacement need not be a single chain update.

Besides closing an arc with a chord, we shall sometimes need to free its endpoints while starting from its through pattern. Removing the first and last edges of a long arc from \(T_J\) uncovers its endpoints and its two leaves \(v_1,v_{s-1}\). Call \(J\) good if it is short or if \[S_{v_1}\cap S_{v_{s-1}}\ne\varnothing.\] For a good long arc, choose an edge between its leaves with a label in this intersection, called a leaf repair. After the two boundary edges are removed, inserting this repair matches all internal vertices and leaves both endpoints free. For a short arc, deleting its sole edge does the same. This is the matching operation encoded by the good-arc condition. The boundary edges of an arc mean only its first and last edges, which coincide for a short arc.

Realize the vertices of \(\mathcal C\) in their cyclic order as a convex polygon. A quadrangulation is a subdivision of this polygon into quadrilaterals by noncrossing diagonals. A side of a cell represents the arc of the original cycle from one corner to the next corner, containing no other corner of that cell. Consequently the four sides of each cell represent four consecutive arcs partitioning the entire cycle. An interior diagonal has two occurrences as a cell side, and their arcs are complementary in the original cycle.

Lemma 12 (Label-adapted quadrangulation). The polygon of \(\mathcal C\) has a quadrangulation such that every cell side represents an admissible odd arc and the following hold in every cell:

  1. some opposite pair of sides consists of good arcs;

  2. if both arcs in an opposite pair are long, both arcs in the other opposite pair are good.

There are \((m-2)/2\) cells and \((m-4)/2\) interior diagonals. One can construct the quadrangulation in time polynomial in \(m\) and the encoding length of the label tree.

Each diagonal may be assigned any common label from the fixed sets at its endpoints, used consistently in its two occurrences. For a short side, use the color of its actual cycle edge. These choices need not coincide with the auxiliary labels used in the construction.

Proof. We give a recursive splitting rule. A subproblem is an admissible odd arc \(J=(v_0,\ldots,v_s)\); its exterior is its complementary arc in the full cycle. Choose a label \(P\in S_{v_0}\cap S_{v_s}\), and write \(a_i\) for the label of \(v_iv_{i+1}\), \(0\le i<s\). Adjacent terms of this sequence are equal or adjacent in the tree. If \(s=1\), no cell is needed. For \(s\ge3\), we find indices \[ 0<p_1<p_2<s,\qquad p_1\text{ odd},\quad p_2\text{ even}, \tag{24}\] such that the three subarcs with successive endpoint pairs \[(v_0,v_{p_1}),\qquad (v_{p_1},v_{p_2}),\qquad (v_{p_2},v_s)\] are admissible. They and the exterior arc form the four sides of the new cell. We call these the first, middle, third, and exterior sides, respectively.

We repeatedly use the following elementary fact about a tree. If a contiguous part of the label walk avoids \(P\) and its first and last labels are adjacent to \(P\), these two labels coincide: the walk lies in a single component of the tree with \(P\) removed, and that component has just one node adjacent to \(P\).

The exterior is good.

It suffices to make either the middle side short or both the first and third sides short. Either alternative immediately implies (i) and (ii), because the exterior is good.

First ensure that some \(a_i\) equals \(P\). If none does, \(a_0\) and \(a_{s-1}\) are adjacent to \(P\), because the endpoint sets contain \(P\). The elementary tree fact gives \(a_0=a_{s-1}=Q\) for a neighbor \(Q\) of \(P\). Replace \(P\) by \(Q\), which also lies in both endpoint sets. We now distinguish the exhaustive possibilities below.

  1. Suppose \(a_i=P\) for an odd \(i\). Set \(p_1=i\) and \(p_2=i+1\). The middle side is short. The first side’s two endpoints contain \(P\), as do the third side’s two endpoints, so all three sides are admissible.

  2. Otherwise all occurrences of \(P\) have even indices. If their first index is \(i>0\), set \(p_1=i-1\) and \(p_2=i\). The prefix \(a_0,\ldots,a_{i-1}\) avoids \(P\), and its first and last labels are adjacent to \(P\). They therefore equal the same neighbor \(Q\). The first side’s endpoints both contain \(Q\), and the third side’s endpoints both contain \(P\). The middle side is short.

  3. Suppose the first occurrence is at \(0\), but the last occurrence is at \(j<s-1\). Set \(p_1=j+1\) and \(p_2=j+2\). The suffix \(a_{j+1},\ldots,a_{s-1}\) avoids \(P\) and has its two end labels adjacent to \(P\), so they equal one neighbor \(Q\). The first side’s endpoints contain \(P\), the third side’s endpoints contain \(Q\), and the middle side is short.

  4. In the remaining case \(a_0=a_{s-1}=P\). Set \(p_1=1\) and \(p_2=s-1\). Both outer sides are short, and the middle side’s endpoints both contain \(P\).

All indices satisfy (24). For example, in (b) the even index \(i\) is at least \(2\), and in (c) the even index \(j\) is at most \(s-3\).

The exterior is not good.

The exterior is then long. At least one of its leaves lacks \(P\) in its fixed label set, since otherwise its two leaves would share \(P\). Reverse the indexing of \(J\) if necessary so that this leaf is the exterior neighbor of \(v_0\). The exterior edge at \(v_0\) cannot have label \(P\). Since \(P\in S_{v_0}\), the first edge of \(J\) must have label \(a_0=P\).

If \(a_{s-1}=P\) as well, choose \(p_1=1,p_2=s-1\). Both outer sides are short, and the middle side is admissible. Otherwise let \(t-1\) be the last index with \(a_{t-1}=P\). Thus \(1\le t\le s-1\). The suffix \(a_t,\ldots,a_{s-1}\) avoids \(P\). Its first label is adjacent to \(P\), and its last label is adjacent to \(P\) because \(P\in S_{v_s}\). Hence \[a_t=a_{s-1}=Q\] for the same neighbor \(Q\) of \(P\).

  • If \(t\) is even, set \(p_1=1,p_2=t\). The first side is short. The middle side’s endpoints both contain \(P\), and the third side’s endpoints both contain \(Q\). The third side is good: if long, both its boundary edges have label \(Q\), so both its leaves contain \(Q\).

  • If \(t\) is odd, set \(p_1=t,p_2=s-1\). The third side is short. The first side’s endpoints both contain \(P\), and the middle side’s endpoints both contain \(Q\). The first side is good because, if long, both its boundary edges have label \(P\).

The required strict inequalities follow from \(t\ge2\) in the even case and \(t\le s-2\) in the odd case. In either case the first and third sides are good and at least one is short. This proves (i). The only opposite pair that can contain two long sides is the middle–exterior pair, and its other pair is good, proving (ii).

Recursion and consistent diagonals.

Start with any arc of length \(m-1\), whose exterior is the remaining single cycle edge. Its endpoints share that edge’s label. Apply the splitting rule and recurse on each of the three subarcs whose length exceeds one, always using the original sets \(S_v\) and the complement in the original cycle as exterior. The three subpolygons have disjoint interiors, so all diagonals are noncrossing. Each recursive child has odd length and admissible endpoints by the construction. The splitting label \(P\) is only an auxiliary witness to admissibility; it does not constrain the color of the closing diagonal. Thus each diagonal can be colored once and the same color used on both sides.

For an odd arc of length \(s\), the resulting number of cells is \((s-1)/2\): this is zero for \(s=1\), and a split into odd lengths \(s_1+s_2+s_3=s\) gives \[1+\sum_{i=1}^{3}\frac{s_i-1}{2}=\frac{s-1}{2}.\] The root therefore gives \((m-2)/2\) cells. Each nonroot recursive subproblem that creates a cell has one closing diagonal, giving one fewer interior diagonals than cells. A direct implementation scans at most \(m\) labels in each of the \((m-2)/2\) nontrivial subproblems; the recursion also has \(m-1\) short leaf arcs. Fixing total orders for any choices makes the construction deterministic, with \(O(m^2)\) label comparisons and polynomial bit cost. ◻

For each cell, choose its colored side chords as in 12; for each good long side, choose one leaf repair. These are precisely the additional edges needed for the local matching constructions in the next section.

Lemma 13 (Comparability within a cell). Consider the four colored side chords of a cell, the first and last cycle edges of each of its four arcs, and one leaf repair for each good long arc. The labels of any two edges in this collection have tree distance at most \(6\). Consequently their activities lie within a factor \[A_0=1000D\] of one another. The same conclusion holds after clamping every edge activity to any common interval \([a,b]\subset(0,\infty)\).

Proof. Two consecutive side chords have labels in the same fixed set \(S_v\) at their common cell corner, so their labels are equal or adjacent. Any two of the four side-chord labels therefore have distance at most \(2\). A boundary edge of an arc and its side chord have labels in the same \(S_v\) at the relevant endpoint, giving distance at most \(1\). A leaf repair and the boundary edge at either of its leaves have labels in that leaf’s fixed set, again giving distance at most \(1\). Thus each edge in the stated collection is at distance at most \(2\) from its side chord, and the diameter is at most \(2+2+2=6\).

Adjacent labels have heights differing by a factor \(2\). If edges \(e,f\) have labels \(\ell,\ell'\) with distance at most \(6\), the assumed activity bounds imply \[\frac{W_e}{W_f} \le \frac{3h_\ell}{h_{\ell'}/D} \le 3D\,2^6=192D\le A_0.\] The same bound holds with \(e,f\) exchanged. Finally the common clamp \(\psi(x)=\max\{a,\min\{b,x\}\}\) satisfies \[1\le\frac{\psi(x)}{\psi(y)}\le\frac{x}{y} \qquad (x\ge y>0).\] For example this follows by observing that \(\log\psi(e^u)\) is the clamp of \(u\) to \([\log a,\log b]\), a nondecreasing \(1\)-Lipschitz function. Clamping therefore preserves the factor bound. ◻

A two-coordinate energy inequality

This section proves the sampling argument’s main inequality. The four side chords of each cell give a two-edge switch whose changed edges have comparable activities. Long arc conversions are used in an exact signed identity and need not be individual chain moves. We control the resulting context errors by swapping an alternating cycle with an independent matching. Encodings by two matchings change only a bounded number of edges in their multiset union, and their preimage counts give polynomial load bounds. The variance-to-energy comparison is related to the flow method of [15], but we do not invoke a path-congestion theorem: the signed identity and its context-error estimates are established for the present pair kernel.

Fix a tree-bag graph on \(N\ge2\) vertices, with at least one perfect matching, and let \(w\) be either its reference activities or any common clamp of them. Write \(\pi(M)=\operatorname{wt}_w(M)/Z_w\) and \(\mathcal M\) for its colored perfect matchings. Throughout this section put \[ A_0=1000D,\qquad \mathcal T=(10N)^{30},\qquad L=(10^4ND)^{100}. \tag{25}\]

The pair kernel

On \((A,B)\in\mathcal M^2\), choose each of the following proposal types with probability \(1/3\).

  1. Two-edge switch. Choose an unordered pair of distinct edges of \(A\) uniformly, and choose either alternative pairing of their four endpoints with probability \(1/2\). For each proposed edge, choose index \(1\) or \(2\) with probability \(1/2\) from the ordered list of common labels of its endpoints. If an index is absent, stay put. If \(A\) has fewer than two edges, stay put.

  2. Color change. Choose an edge of \(A\) uniformly and choose index \(1\) or \(2\) from the common-label list with probability \(1/2\). An absent index gives a holding move.

  3. Cycle swap. Choose uniformly one discrepancy cycle of \(A,B\) and interchange its two layers. If there is no discrepancy cycle, stay put.

Accept each proposal by the Metropolis rule for \(\pi\otimes\pi\). Denote the resulting kernel by \(P\) and its energy by \(\mathcal E\). The proposal is symmetric. For the first two types, the reverse choice has the same edge, pairing, and color-index probabilities; the possible holding choices do not change this fact. For the third type, the discrepancy cycles and their number are unchanged by the swap. In particular, a cycle swap always has acceptance probability one, since its product weight is unchanged.

Theorem 14 (Pair energy inequality). For every two real functions \(f_1,f_2\) on \(\mathcal M\), \[ \mathop{\mathrm{Var}}_\pi f_1\le L\, \mathcal E\bigl((A,B)\mapsto f_1(A)+f_2(B)\bigr). \tag{26}\] The same constant works for every common-interval clamp of the reference activities.

In the proof write \(F(A,B)=f_1(A)+f_2(B)\) and \(E=\mathcal E(F)\). A two-edge switch is called safe if its four removed or inserted colored edges have activities within a factor \(A_0\) of one another. Let \(\mathcal S(A)\) be its possible safe destinations, and let \(\mathcal K(A)\) be its possible destinations by changing one edge color. Consecutive labels have comparable heights, so every color change has activity ratio in \([A_0^{-1},A_0]\).

Lemma 15 (Elementary energy bounds). With the notation above, \[\begin{align*} \sum_A\pi(A)\sum_{A'\in\mathcal S(A)} (f_1(A)-f_1(A'))^2 &\le60N^2A_0^2 E, \tag{27}\\ \sum_A\pi(A)\sum_{A'\in\mathcal K(A)} (f_1(A)-f_1(A'))^2 &\le12NA_0 E, \tag{28}\\ \sum_{A,B}\pi(A)\pi(B)\sum_{C\in\mathcal C(A,B)} \bigl(F(A,B)-F((A,B)^C)\bigr)^2 &\le6NE. \tag{29}\end{align*}\] Here \(\mathcal C(A,B)\) denotes the discrepancy cycles, and \((A,B)^C\) is the pair after swapping \(C\).

Proof. Every specified legal two-edge switch has proposal probability at least \(1/(30N^2)\); its Metropolis acceptance is at least \(A_0^{-2}\) when safe. Every specified color change has proposal probability at least \(1/(6N)\) and acceptance at least \(A_0^{-1}\). These moves change only the \(f_1\) summand of \(F\), so summing the second-coordinate law and using the factor \(1/2\) in the energy proves the first two bounds. There are at most \(N\) discrepancy cycles. Each specified swap therefore has proposal probability at least \(1/(3N)\) and is accepted; this proves the third bound. ◻

An exact identity on a cycle

Fix a pair of demand matchings \((I_1,I_2)\) and a simple discrepancy cycle \(C\) of length at least four. All orientations and choices below are deterministic, using the orders fixed in 2. Let \(R\) be the edges of \(I_1\) outside \(C\), and let \(O_0=I_1\) and \(O_1\) be the matching obtained by toggling \(C\) in \(I_1\). Thus both orientations use \(R\) outside \(C\). Put \[D_C=f_1(O_0)-f_1(O_1).\] Apply 12 and fix the colors of its diagonals consistently. A cell’s four sides always mean the four odd arcs of the original whole cycle, not paths formed from earlier diagonals.

Use the through, interior, and closed patterns \(T_J,N_J,C_J\) from 5, with the chosen chord colors. A side \(J\) is through in \(O_\varepsilon\) if \(T_J\subseteq O_\varepsilon\). Exactly one orientation \(O_\varepsilon\) contains \(T_J\); define \[ H_J=(O_\varepsilon\setminus T_J)\cup C_J, \qquad g_J=f_1(O_\varepsilon)-f_1(H_J). \tag{30}\] For a short side, the chord is its actual cycle edge, so \(g_J=0\).

The reason for using the original cycle on every cell side is already visible on a six-cycle \(C=(v_0,\ldots,v_5,v_0)\). Take \[O_0=R\cup\{v_0v_1,v_2v_3,v_4v_5\},\qquad O_1=R\cup\{v_1v_2,v_3v_4,v_5v_0\},\] and suppose the diagonal \(e=v_0v_3\) is admissible. In the two cells it represents the complementary arcs \(J=(v_3,v_4,v_5,v_0)\) and \(\bar J=(v_0,v_1,v_2,v_3)\), respectively. Both conversions yield the same matching \[H_J=H_{\bar J}=H=R\cup\{v_1v_2,e,v_4v_5\}.\] Thus \(g_{\bar J}-g_J=f_1(O_0)-f_1(O_1)=D_C\); the shared diagonal contributes one whole-cycle difference, not zero. 3 displays this common converted matching. This example isolates the complementary-gain identity. Its cells have only one long side each, so the context errors introduced below vanish; cells with two opposite long sides require a further estimate.

An admissible diagonal \(e=v_0v_3\) cuts a six-cycle into two cells. In the upper cell its side follows the lower boundary arc \(J\); in the lower cell its side follows the upper boundary arc \(\bar J\). The two occurrences use the same colored edge \(e\). Converting the through pattern on either arc gives the restriction of \(H\) shown on the right (the common outside matching \(R\) is omitted), so their signed gains sum to \(D_C\). The drawing concerns the signed identity, not a sequence of chain transitions.

In a cell, let \(P\) be its opposite pair of sides through in \(O_0\), and \(Q\) its opposite pair through in \(O_1\). Let \(A_P\) use \(N_J\) on every side and the chords of the two sides of \(P\), together with \(R\). Define \(A_Q\) analogously and put \[\Delta=f_1(A_P)-f_1(A_Q).\] These are legal perfect matchings: the interior vertices are matched by the \(N_J\)’s, and the two chosen chords match the four corners. Their difference is a safe two-edge switch by 13.

Order each opposite pair as \((Y,X)\). For the orientation in which both are through, first convert \(Y\) and then \(X\). Write \(A^{(0)}=O_\varepsilon\) and \(A^{(1)}=H_Y\) for the two pre-conversion contexts of \(X\). For a matching \(R'\) on the vertices outside \(X\), define \[ \partial_X f(R')=f(T_X\cup R')-f(C_X\cup R'). \tag{31}\] The context error of the ordered opposite pair is \[ E_{Y,X} =\partial_X f_1(A^{(1)}\setminus T_X) -\partial_X f_1(A^{(0)}\setminus T_X). \tag{32}\] It is zero if either side is short. Denote these errors by \(E_P,E_Q\) for the two ordered pairs of the cell.

Lemma 16 (Cell identity and cancellation). The quantities just defined satisfy \[ D_C=\Delta+\sum_{J\in P}g_J-\sum_{J\in Q}g_J+E_P-E_Q \tag{33}\] for each cell. Consequently, \[ D_C=\sum_{\text{cells of }C}(\Delta+E_P-E_Q). \tag{34}\]

Proof. The first conversion in an opposite pair has its canonical gain. The second has its canonical gain plus the error in (32). Thus \[f_1(O_0)-f_1(A_P)=\sum_{J\in P}g_J+E_P, \qquad f_1(O_1)-f_1(A_Q)=\sum_{J\in Q}g_J+E_Q.\] Subtracting proves (33).

Consider an interior diagonal with complementary arcs \(J,\bar J\). They are through in opposite whole-cycle orientations, and their converted matchings coincide: \[H_J=H_{\bar J}=R\cup N_J\cup N_{\bar J}\cup\{e_J\}.\] Therefore the two signed canonical gains contributed by this diagonal sum to \(f_1(O_0)-f_1(O_1)=D_C\). The signs here are precisely those in (33): the arc through in \(O_0\) has positive sign and the other negative sign. Boundary sides have zero gain. Summing (33) over the cells therefore gives one copy of \(D_C\) per cell on the left and one per interior diagonal on the right, in addition to the displayed local terms. The number of cells is one more than the number of diagonals, which proves (34). ◻

Encoding the demands

A switch demand specifies \((I_1,I_2)\), a simple discrepancy cycle \(C\), and one cell of its fixed quadrangulation. Its value is \(\Delta\) above. An error demand specifies these data and one opposite pair with two long sides, in its fixed order \((Y,X)\). Its value is \(E_{Y,X}\). The weight of either demand is \(\rho(d)=\pi(I_1)\pi(I_2)\). Repeated demands from different cells or different cycles are included separately in all sums.

Lemma 17 (Encodings with a bounded number of preimages). Every switch demand has an encoding \((A_P,B)\) by two perfect matchings, and every error demand has encodings \((A^{(j)},B^{(j)})\) for \(j=0,1\), with the following properties.

  1. For each encoding \((A,B)\), \(\rho(d)\le A_0^4\pi(A)\pi(B)\).

  2. For each encoding type and each fixed output pair, there are at most \(\mathcal T\) demand preimages. This bound includes the choices of cycle, cell, opposite pair, and context.

  3. For an error demand, both guide matchings satisfy \(C_X\subseteq B^{(j)}\).

Proof. We first describe a repair operation. Start with the union of the four through patterns \(T_J\) in a cell. Each corner is covered twice, once by each incident side. Select a good opposite pair of sides. For each selected short side delete its sole edge. For each selected long side delete its first and last edges, and insert its chosen leaf repair. Each corner loses exactly one incident edge. On a long selected side the only newly uncovered internal vertices are its two leaves, which the repair matches. Thus the resulting edges form a perfect matching of all cycle vertices. This verifies legality also for a side of length three: its two leaves are distinct and its repair is an ordinary colored edge between them.

Switch demands.

Use \(A_P\) as the first output. In the second output retain the edges of \(I_2\) outside \(C\), start with all four through patterns, and apply the preceding repair operation to a good opposite pair, which exists by 12(i). Call the result \(B\). Before these modifications, the original multiset union contains exactly one \(T_J\) and one \(N_J\) on each side. The output union adds the two \(P\)-chords and the leaf repairs and drops the selected boundary edges. If \(r\in\{0,1,2\}\) selected sides are long, the numbers added and dropped are both \(2+r\le4\).

Error demands, context zero.

The first output is \(A^{(0)}=O_\varepsilon\), the canonical orientation in which \(X,Y\) are through. Start the second output with the complementary cycle orientation and the edges of \(I_2\) outside \(C\). It has the \(N\) patterns on \(X,Y\). Insert their two chords. The other opposite pair is good by 12(ii), because \(X,Y\) are both long. On that other pair delete boundary edges and insert leaf repairs as above. The result is a perfect matching \(B^{(0)}\), containing both \(C_X\) and \(C_Y\). Again, the multiset union differs from the original by equally many added and dropped edges, at most four of each.

Error demands, context one.

Interchange the patterns \(T_Y\) and \(C_Y\) between \(A^{(0)},B^{(0)}\). Each pattern perfectly matches the entire vertex set of \(Y\), so the interchange is legal and gives \(A^{(1)}=H_Y\) and a guide \(B^{(1)}\). The vertex sets of the opposite arcs \(X,Y\) are disjoint; hence \(B^{(1)}\) still contains \(C_X\). This interchange does not change the multiset union or product weight.

In every case all added and dropped edges are among the chords, boundary edges, and good-side leaf repairs of this one cell. They have pairwise activity ratio at most \(A_0\) by 13. Since the two lists have equal length at most four, the input product weight is at most \(A_0^4\) times the output product weight. Division by \(Z_w^2\) proves (i).

For completeness we give an inverse, including the information it needs. Attach a tag consisting of the four cell corners in cyclic order, lists of the added and dropped colored edges padded to length four each, one orientation bit, and fixed flags for the encoding type (switch, error context zero, or error context one), opposite pair, and order. An edge in these lists is an occurrence in the multiset union; coincident colored edges retain their multiplicities. Given the output pair and tag, remove the added occurrences and reinsert the dropped occurrences in its multiset union. This recovers the original colored union \(I_1\uplus I_2\). Its component containing the first tagged corner is the active simple cycle \(C\). The orientation bit specifies which of the two alternating classes at that corner belongs to \(I_1\), so alternation determines both original layers on all of \(C\). Outside \(C\), the output layers were unchanged; they recover \(I_1,I_2\) there directly. The fixed quadrangulation can now be reconstructed. Its tagged corners identify the cell, and the flags identify the term and, if appropriate, its ordered pair. Thus this is an inverse on every tag produced by the construction.

There are at most \(2N^2\) possible colored edges. Allowing a padding symbol, the tags have at most \[128N^4(1+2N^2)^8 \le128\cdot3^8N^{20}< (10N)^{30}=\mathcal T\] possibilities for \(N\ge2\). Here the factor \(128\) more than covers the orientation bit and the fixed flags; the lists themselves may be stored in the fixed colored-edge order. This proves (ii), and the constructions already proved (iii). ◻

The encodings provide two kinds of control. Their bounded preimage count converts a sum over demands to a sum over pairs of matchings. For context errors, the guide also contains a prescribed closed arc; this additional condition must survive that summation. We use the bounded preimage count for switches below, then retain the closed-arc condition when treating context errors in the next subsection.

We apply this lemma first to switches. For a fixed encoded pair \((A,B)\) there are at most \(\mathcal T\) demands, and each has its associated destination \(A_Q\) in \(\mathcal S(A)\). Therefore \[\begin{align*} \sum_{d\text{ switch}}\rho(d)\Delta_d^2 &\le A_0^4\mathcal T\sum_{A,B}\pi(A)\pi(B) \sum_{A'\in\mathcal S(A)}(f_1(A)-f_1(A'))^2 \\ &\le60N^2A_0^6\mathcal TE. \tag{35}\end{align*}\]

Controlling context errors by cycle swaps

Here an identity \(X\) means a directed, colored, simple odd path of length at least three together with a specified colored edge joining its endpoints. It determines \(T_X,C_X\) and (31). We may sum over all such identities: this is a finite proof device, and the algorithm does not enumerate them. Put \[p_X=\pi\{B:C_X\subseteq B\}.\] We omit identities with \(p_X=0\). Every identity arising from an error demand has \(p_X>0\), by the guide constructed in 17. For any first matching \(A\supseteq T_X\) and either \(j=0,1\), that lemma gives the following conditional demand-mass bound: \[ \sum_{\substack{d\text{ error}:X(d)=X\\ A^{(j)}(d)=A}} \rho(d) \le A_0^4\mathcal T\,\pi(A)p_X. \tag{36}\] Indeed, for each guide \(B\supseteq C_X\) there are at most \(\mathcal T\) preimages of \((A,B)\); now sum its product weight over these guides. The factor \(p_X\) is essential and will cancel the conditioning below.

The next comparison averages over precisely those guides counted by \(p_X\). That conditional law can be concentrated on a very rare event. We therefore retain \(p_X\) in the demand bound instead of estimating it from below.

For a fresh guide \(B\sim\pi\), define \[\mu_X=\mathbb E\bigl[\partial_X f_2(B\setminus C_X) \mid C_X\subseteq B\bigr].\] For an error demand, (32) and \((a-b)^2\le2(a-c)^2+2(b-c)^2\) imply \[E_d^2\le 2\sum_{j=0}^1 \bigl(\partial_X f_1(A^{(j)}\setminus T_X)-\mu_X\bigr)^2.\] Applying (36), and then Jensen’s inequality to the conditional expectation defining \(\mu_X\), gives \[\begin{align*} \sum_{d\text{ error}}\rho(d)E_d^2 &\le4A_0^4\mathcal T \sum_X\sum_{A\supseteq T_X}\pi(A)p_X \bigl(\partial_X f_1(A\setminus T_X)-\mu_X\bigr)^2 \\ &\le4A_0^4\mathcal T\,\Sigma_{\rm swap}, \tag{37}\end{align*}\] where \[ \Sigma_{\rm swap}= \sum_X\sum_{\substack{A\supseteq T_X\\ B\supseteq C_X}} \pi(A)\pi(B) \bigl(\partial_X f_1(A\setminus T_X) -\partial_X f_2(B\setminus C_X)\bigr)^2. \tag{38}\] In detail, for a fixed \(X,A\) Jensen bounds the squared difference from \(\mu_X\) by \[\frac1{p_X}\sum_{B\supseteq C_X}\pi(B) \bigl(\partial_X f_1(A\setminus T_X) -\partial_X f_2(B\setminus C_X)\bigr)^2.\] Multiplication by the \(p_X\) in (36) removes this denominator exactly. No lower bound on \(p_X\) is used.

Lemma 18 (Swap sum). The sum in (38) satisfies \(\Sigma_{\rm swap}\le12N^2E\).

Proof. For a pair in (38), the matchings \(T_X\) and \(C_X\) cover exactly the same vertex set, and their union is one alternating cycle: the path \(X\) together with its closing chord. Their edges are disjoint since \(X\) is long and simple. Thus this is an entire discrepancy component of \(A,B\), not a portion of a larger one. Swapping it changes \(F\) by exactly \[\partial_X f_1(A\setminus T_X) -\partial_X f_2(B\setminus C_X).\] For a fixed fresh pair \((A,B)\) and one of its discrepancy cycles, an identity \(X\) is determined by marking the closing chord in the second matching and choosing a direction around that cycle. The remaining colored path is then read from the pair. There are at most \(2N\) such choices. Consequently \[\Sigma_{\rm swap}\le2N\sum_{A,B}\pi(A)\pi(B) \sum_{C\in\mathcal C(A,B)} \bigl(F(A,B)-F((A,B)^C)\bigr)^2 \le12N^2E\] by (29). ◻

Completion of the energy proof

Proof of 14. Take independent \(I_1,I_2\) with law \(\pi\). Toggle their discrepancy cycles in the order of their least vertices, converting \(I_1\) to \(I_2\). Cauchy–Schwarz over the at most \(N\) cycles gives \[(f_1(I_1)-f_1(I_2))^2 \le N\sum_C (\text{the $f_1$ difference at the step for $C$})^2.\] For each selected \(C\), toggle all earlier cycles in both demand matchings. This preserves their product weight, their union, and the selected cycle. It is its own inverse, since the union fixes the same cycle order. The term at that step becomes \(D_C^2\) for the new demand pair, with the definition used above. Since \(\mathop{\mathrm{Var}}_\pi f_1=\tfrac12\mathbb E(f_1(I_1)-f_1(I_2))^2\), we obtain the convenient slightly weaker bound \[ \mathop{\mathrm{Var}}_\pi f_1\le N\sum_{I_1,I_2}\pi(I_1)\pi(I_2) \sum_{C\in\mathcal C(I_1,I_2)}D_C^2. \tag{39}\]

A length-two discrepancy cycle is a color change in \(I_1\). For a fixed \(I_1\) and specified change, summing the mass of \(I_2\) that supplies the other color costs at most one. Its total contribution to the sum in (39) is therefore at most \(12NA_0E\), by (28).

For a simple cycle, there are fewer than \(N\) cells, so (34) and Cauchy–Schwarz give \[D_C^2\le3N\sum_{\text{cells}} (\Delta^2+E_P^2+E_Q^2).\] Sum over all such cycle demands. The errors with a short side vanish; all others are precisely the error demands already bounded. Equations (35), (37), and 18 bound the simple-cycle contribution by \[3N\bigl(60N^2A_0^6\mathcal T+48N^2A_0^4\mathcal T\bigr)E.\] Combining the two cycle types in (39) and using \(A_0,\mathcal T\ge1\) yields \[\mathop{\mathrm{Var}}_\pi f_1 \le\bigl(12N^2A_0+324N^4A_0^6\mathcal T\bigr)E \le1000N^4A_0^6\mathcal TE.\] Finally \[1000N^4A_0^6\mathcal T =10^{51}N^{34}D^6 \le(10^4ND)^{100}=L.\] All comparisons used only 13 and the adjacent-label comparison for color changes. Both hold under any common clamp, proving the final assertion as well. ◻

A sampler from replicated adjacent tiers

The two-coordinate inequality controls an additive function of a pair; it is not a Poincaré inequality for all functions of that pair. We now turn it into a Poincaré inequality on a larger product space. The construction uses adjacent weight tiers, with many independent copies at each tier. Orthogonality of product projections controls the terms involving both members of a pair. The slot order ensures that no orthogonal interaction component occurs in two different pair residuals. Averaging over many guides then makes their total contribution small enough to absorb. Using several adjacent distributions in one product chain has antecedents in replica Monte Carlo [17, 20]. Here the coordinates are colored perfect matchings, the pair moves exchange alternating cycles, and the effect of replication is quantified by the proof below.

Throughout this section, the tree-bag graph has \(N\ge2\) vertices, \(b_{\rm tree}\) labels, maximum level at most \(2K\), and the integer parameter \(D\) of 2, where \(K\) is a nonnegative integer. Its reference activities are positive rationals. Let \(\mathcal M\) denote its common, nonempty set of colored perfect matchings. By [eq:bag-weight-range], \[ D^{-1}\le W_e\le 3\cdot4^K. \tag{40}\]

An exact refresh at unit activities

Lemma 19. The unit-activity partition function is computable by a dynamic program on the label tree. With exact rational categorical choices, its tables also produce an exact sample. The tables can be computed with \(O((b_{\rm tree}+1)(N+1)^3)\) arithmetic operations on counts of \(O(N\log(N+1))\) bits. Label and loop indices use \(O(\log(b_{\rm tree}+1)+\log(N+1))\) additional bits. Once the tables are available, a sample uses polynomially many integer operations and at most \(4(b_{\rm tree}+N+1)\) rational categorical choices, each with at most \(N+1\) outcomes. A positive table also yields a matching by entirely deterministic backtracking.

Proof. A colored matching assigns each vertex to the color of its matched edge. Conversely, assign each vertex to one of its one or two bags, and pair the vertices assigned to each bag. These two operations are inverse. Thus, if \(a_l\) vertices are assigned to bag \(l\), the number of matchings for that assignment is \(\prod_l J(a_l)\), where \[J(0)=1,\qquad J(a)=(a-1)!!\quad\text{for even }a>0, \qquad J(a)=0\quad\text{for odd }a.\] The values of \(J\) count pairings of a complete graph.

For a nonroot bag \(C\), write \(S_C\) for its interface with its parent, and put \(s_C=|S_C|\); for the root use \(S_C=\varnothing\). Let \(u_C\) be the number of vertices belonging to \(C\) alone. All interfaces incident to a bag are disjoint. For a fixed subset of \(k\) vertices of \(S_C\) assigned to \(C\), let \(F_C(k)\) count the assignments and pairings within the subtree of \(C\); the other vertices of \(S_C\) are assigned to its parent. The answer depends only on \(k\): vertices of \(S_C\) belong to no bag other than \(C\) and its parent, and they are interchangeable in the complete clique of color \(C\).

If \(C_1,\ldots,C_d\) are the children of \(C\), set \(s_i=s_{C_i}\). Choosing \(\ell_i\) vertices of the \(i\)th interface to be assigned downward gives the recurrence \[ F_C(k)=\sum_{\ell_1=0}^{s_1}\cdots\sum_{\ell_d=0}^{s_d} J\!\left(u_C+k+\sum_{i=1}^d(s_i-\ell_i)\right) \prod_{i=1}^d\binom{s_i}{\ell_i}F_{C_i}(\ell_i). \tag{41}\] The required partition function is \(F_{\rm root}(0)\). There is no exponential enumeration in evaluating this recurrence. Form the polynomial \[H_C(z)=\prod_{i=1}^d \left(\sum_{\ell=0}^{s_i} \binom{s_i}{\ell}F_{C_i}(\ell)z^{s_i-\ell}\right).\] Its degree is at most \(N\), and \[F_C(k)=\sum_{a=0}^N[z^a]H_C(z)\,J(u_C+k+a),\] with impossible indices contributing zero. Naive convolutions suffice for the asserted arithmetic bound. The intermediate counts enumerate assignments and partial pairings on at most \(N\) vertices. There are at most \(2^N\) assignments, and for any one assignment at most \(N!\) such pairings, so \(2^N N!\) bounds these counts. This gives the bit bound.

For sampling, begin at the root with \(k=0\). At a visited bag, choose \(a\) with probability proportional to \([z^a]H_C(z)J(u_C+k+a)\). Backtrack the stored convolutions to choose the individual \(\ell_i\), then choose uniformly the corresponding interface subsets. Recurse on each child with its chosen subset, and independently choose a uniform pairing of the vertices assigned to the current bag. Every choice is proportional to its number of completions in [eq:base-dp]; induction on the subtree therefore gives the uniform law on colored matchings. A uniform subset is generated by sequential inclusion choices, and a uniform pairing by repeatedly pairing the least remaining vertex with a uniformly chosen other vertex. The total number of interface vertices is at most \(N\), since a shared vertex belongs to exactly one interface. There are at most \(N/2\) partner choices, \(b_{\rm tree}\) total-size choices, and \(b_{\rm tree}-1\) convolution choices. This proves the stated draw bound. Choosing any positive-count branch instead yields a deterministic matching. ◻

The product chain

Set \[ c=1+N^{-2},\qquad T=\min\{t\in\mathbb Z_{\ge0}:c^t\ge\max(D,3\cdot4^K)\}, \qquad q=32L, \tag{42}\] where \(L=(10^4ND)^{100}\) is the integer in 14. At tier \(t\in\{0,\ldots,T\}\), clamp every reference activity to \([c^{-t},c^t]\) and denote the matching law by \(\pi_t\). Thus \(\pi_0\) is the uniform colored matching law and \(\pi_T\) is the desired law. Moreover, \[ \frac12\le\frac{\pi_{t-1}(A)}{\pi_t(A)}\le2 \qquad(A\in\mathcal M,\ 1\le t\le T). \tag{43}\] Indeed, an individual activity changes by a factor in \([c^{-1},c]\), so unnormalized matching weights and partition functions each change by factors in \([c^{-N/2},c^{N/2}]\). The probability ratio is therefore in \([c^{-N},c^N]\), and \(c^N\le\exp(1/N)<2\). Also \(\log(1+N^{-2})\ge(2N^2)^{-1}\), whence \[ T\le1+2N^2\log\max(D,3\cdot4^K) =O\bigl(N^2(K+\log D+1)\bigr). \tag{44}\] Here and below, unbased logarithms are natural.

Use \(q\) slots at each tier, with product stationary law \[\nu=\bigotimes_{t=0}^T\pi_t^{\otimes q}.\] An allowed pair \((x,y)\) consists of a slot \(x\) at tier \(t\ge1\) and any slot \(y\) at tier \(t-1\). On this pair use exactly the symmetric proposal of 14, with local proposals acting on \(x\), and accept by Metropolis for \(\pi_t\otimes\pi_{t-1}\). Across unequal tiers a cycle swap uses this Metropolis acceptance ratio as well; the acceptance-one observation for two identical laws in 6 no longer applies. For each base slot there is instead the update that refreshes it from \(\pi_0\), using 19. There are \[ M=Tq^2+q \tag{45}\] updates. The chain \(P\) holds with probability \(1/2\); otherwise it chooses one of these \(M\) updates uniformly. Every update preserves \(\nu\) and is reversible, so the same is true of \(P\).

Write \(\mathcal E_{xy}\) for the energy of one allowed pair update, with all other coordinates integrated against \(\nu\), and \(\mathcal E_i\) for the energy of a refresh of base slot \(i\). In this notation \[ \mathcal E_{\nu,P}(f) =\frac1{2M}\left(\sum_{xy}\mathcal E_{xy}(f) +\sum_{i\text{ base}}\mathcal E_i(f)\right). \tag{46}\]

For later use, the two-coordinate inequality also applies across adjacent tiers. The pair state space and symmetric proposal are identical for the targets \(\pi_t\otimes\pi_t\) and \(\pi_t\otimes\pi_{t-1}\). By [eq:adjacent-density], the latter target density is at least half the former at every pair state. The Metropolis capacity formula [eq:metropolis-capacity] thus shows that the unequal-tier energy dominates half the equal-tier energy. Consequently, for any functions \(a\) and \(b\) of the two slots, \[ \mathop{\mathrm{Var}}_{\pi_t}a \le 2L\,\mathcal E_{xy}\bigl(a(x)+b(y)\bigr). \tag{47}\] In this display the energy is on the two slots alone; it can also be applied conditionally on any fixed values of other slots.

Lemma 20. The lazy product chain has spectral gap at least \(3/(8M)\), and hence at least \(1/(20LM)\). The dependence on \(L\) in the stronger bound is carried by \(q=32L\), and hence by \(M\).

Proof. Order the slots from highest tier to lowest, resolving ties arbitrarily. Thus every allowed guide \(y\) follows its upper slot \(x\). For each slot \(x\), let \(U_x\) be the set of its predecessors and put \[h_x=\mathbb E[f\mid U_x,x]-\mathbb E[f\mid U_x].\] These are the orthogonal martingale increments, so \[ \mathop{\mathrm{Var}}_\nu f=\sum_x\|h_x\|_{L^2(\nu)}^2. \tag{48}\] Fix an allowed pair \((x,y)\), abbreviate \(U=U_x\), and define \[k_{xy}=\mathbb E[f\mid U,y]-\mathbb E[f\mid U],\qquad g_{xy}=\mathbb E[f\mid U,x,y],\] \[ r_{xy}=g_{xy}-\mathbb E[f\mid U]-h_x-k_{xy}. \tag{49}\] For fixed \(U\), \(h_x\) is centered over \(x\) and \(k_{xy}\) over \(y\). Applying [eq:unequal-pair-energy] and then averaging over \(U\) gives \[\|h_x\|_2^2\le2L\mathcal E_{xy}(h_x+k_{xy}).\] Conditional expectation onto \(U,x,y\) decreases \(\mathcal E_{xy}\): the pair kernel is independent of all the other coordinates, and Jensen’s inequality applies to each difference across a transition. For any stationary Markov kernel, [eq:dirichlet] and \((a-b)^2\le2a^2+2b^2\) give \(\mathcal E(v)\le2\|v\|_2^2\). Using [eq:ladder-residual], and observing that functions of \(U\) have zero pair energy, we conclude that \[\begin{align*} \|h_x\|_2^2 &\le 2L\bigl(2\mathcal E_{xy}(g_{xy})+2\mathcal E_{xy}(r_{xy})\bigr) \\ &\le4L\mathcal E_{xy}(f)+8L\|r_{xy}\|_2^2. \tag{50}\end{align*}\]

We now have an estimate for one upper slot and one guide, but it contains a residual involving both slots. Replication helps only if these residual terms can be charged collectively. The ordering of slots makes that collective estimate possible.

The key point is that the residuals in this bound are orthogonal over all allowed pairs. To verify it explicitly, use the orthogonal product (ANOVA) decomposition of Efron and Stein [6], written here as \[f=\sum_{S}f_S,\qquad f_S=\sum_{A\subseteq S}(-1)^{|S|-|A|}\mathbb E[f\mid A],\] where \(S\) ranges over subsets of the slot set. Each \(f_S\) depends only on the coordinates in \(S\) and is centered in each coordinate of \(S\). Therefore distinct \(f_S\) are orthogonal, and \(\mathbb E[f\mid A]=\sum_{S\subseteq A}f_S\). Substitution into [eq:ladder-residual] gives \[ r_{xy}=\sum_{\substack{S\subseteq U_x\cup\{x,y\}\\x,y\in S}}f_S. \tag{51}\] Every set \(S\) in this sum has \(y\) last and \(x\) penultimate in the fixed slot order: all its other coordinates lie in \(U_x\). These two positions determine the allowed pair uniquely. Thus even pairs that share a slot use disjoint sets of orthogonal components. Since every component here is nonconstant, \[ \sum_{xy}\|r_{xy}\|_2^2\le\mathop{\mathrm{Var}}_\nu f. \tag{52}\] This decomposition is only an identity in the proof; the algorithm does not compute it.

For a base slot \(i\), conditional expectation onto \(U_i,i\) similarly decreases its refresh energy. The refresh energy of \(h_i\) equals \(\|h_i\|_2^2\), because \(h_i\) is centered over \(i\) given \(U_i\). Hence \(\|h_i\|_2^2\le\mathcal E_i(f)\). Average [eq:ladder-one-pair] over the \(q\) guides of each nonbase slot and sum over slots. [eq:ladder-martingale,eq:ladder-residual-sum] yield \[\mathop{\mathrm{Var}}_\nu f \le\frac{4L}{q}\sum_{xy}\mathcal E_{xy}(f) +\frac{8L}{q}\mathop{\mathrm{Var}}_\nu f +\sum_{i\text{ base}}\mathcal E_i(f).\] Since \(q=32L\), absorption gives \[\mathop{\mathrm{Var}}_\nu f \le\frac16\sum_{xy}\mathcal E_{xy}(f) +\frac43\sum_{i\text{ base}}\mathcal E_i(f) \le\frac{8M}{3}\mathcal E_{\nu,P}(f).\] This proves the first gap bound. The second follows from \(L\ge1\). ◻

A quantitative sampling guarantee

Theorem 21. Define \(T,q,M\) by [eq:ladder-parameters,eq:ladder-update-count], and put \[\begin{align*} \Lambda&=10Nq(T+1) \bigl(K+\lceil\log_2(ND+2)\rceil+1\bigr), \tag{53}\\ s(\xi)&=\left\lceil20LM \bigl(\Lambda+\lceil\log_2(1/\xi)\rceil+1\bigr)\right\rceil \qquad(0<\xi<1). \tag{54}\end{align*}\] Initialize all slots to any one colored perfect matching and run the exact chain for \(s(\xi)\) steps. The resulting product law is at total variation distance at most \(\xi\) from \(\nu\). In particular, any top-tier slot has law within \(\xi\) of the desired weighted matching law.

All tables, state representations, and transition probabilities are computable by rational arithmetic. Their sizes, arithmetic operation counts, and rational bit lengths are polynomial in \(N,D,K\), \(b_{\rm tree}\), \(\log(1/\xi)\), and the bit lengths of the reference activities. Exact rational choices here define an ideal process; the bounded-bit implementation in 9 adds at most \(\xi\) to the total variation error.

Proof. Every colored matching consists of \(N/2\) vertex pairs, each with at most two color choices. In particular, \(|\mathcal M|\le(2N^2)^N\). At every tier, all activities remain in the interval [eq:ladder-global-range]. For any \(A\in\mathcal M\) this gives \[\pi_t(A)\ge \frac1{(2N^2)^N(3D4^K)^{N/2}}.\] Taking the product over \(q(T+1)\) slots and using \(N\ge2,D\ge1\) shows that \[ \log\frac1{\min\nu}\le\Lambda. \tag{55}\] For example, with \(a=\lceil\log_2(ND+2)\rceil\), the logarithm of the denominator in the preceding display is at most \(N(K+\tfrac52a+2)\), which is at most \(10N(K+a+1)\).

For completeness, the finite-state spectral argument gives a direct mixing bound. Reversibility makes \(P\) self-adjoint on \(L^2(\nu)\). Its laziness makes its eigenvalues nonnegative, and 20 bounds every eigenvalue on the centered subspace above by \(1-\gamma\), where \(\gamma=1/(20LM)\). Starting from a point \(z\), the centered initial density has squared norm \(1/\nu(z)-1\). By diagonalization, reversibility, and [eq:ladder-minimum-mass], \[\|P^s(z,\cdot)-\nu\|_{\mathop{\mathrm{TV}}} \le\frac12(1-\gamma)^s\sqrt{\frac1{\nu(z)}-1} \le\frac12\exp(-\gamma s+\Lambda/2).\] Substitution of [eq:ladder-steps] makes this at most \(\xi\). Projection onto a chosen top-tier coordinate cannot increase total variation.

It remains to specify the computation represented by this chain. The unit-activity tables are supplied by 19; a positive table supplies an initial matching if one has not already been constructed. There are at most \(N^2\) colored edges and \(q(T+1)\) matching coordinates. Precompute the clamped activities at every tier using rational powers of \(c\). The tier bound [eq:ladder-tier-bound] is polynomial in the stated parameters, and these powers have polynomial bit length. A scan choice can be made by an integer in \(\{1,\ldots,M\}\), decoding either a base slot or an upper tier and two slot indices. A pair proposal is implemented by inspecting two matchings: the alternating components can be listed by following the union of their edges, and the local switch and color proposals require only finite lists of edges and at most two color choices per new edge. Metropolis acceptance uses a ratio of products of at most \(2N\) activities; the unknown partition functions cancel. A refresh uses the precomputed integer tables. Thus a step has polynomial arithmetic cost and rational probabilities of polynomial bit length. The bound \(s(\xi)\) is itself polynomial in the displayed parameters, which proves the assertion about the ideal computation.

For the finite-bit assertion in this generality, including arbitrarily many empty bags, use the draw and option bounds \[R_{\rm draw}^{\rm gen}=100(s(\xi)+1)(b_{\rm tree}+N+1),\qquad R_{\rm opt}=10(M+N^2+1).\] Indeed a refresh uses at most \(4(b_{\rm tree}+N+1)\) categorical choices, and laziness and the scan use two more. A pair step uses at most eight choices. A final revelation of edge types, when present, uses at most \(N\) further choices. These fit the displayed draw bound. Every choice has at most \(R_{\rm opt}\) options. Take a fixed integer \(k\) with \(2^k\ge2R_{\rm draw}^{\rm gen}R_{\rm opt}/\xi\). 24 and successive coupling then bound the cumulative simulation discrepancy by \(\xi\). This precision and the resulting bit cost are polynomial in the stated parameters, including \(b_{\rm tree}\). For the hierarchy constructed in 4, the smaller specialized bookkeeping in 9 follows from \(b_{\rm tree}\le N(2K+1)\). ◻

From samples to the number of perfect matchings

We now give the counting algorithm. Its sampling calls use only the tree-bag sampler proved above. In particular, neither balancing nor estimating a partition ratio requires an additional oracle. Positive completion, gradual suppression of nonedges, and estimation of successive partition ratios follow the annealing framework used for the permanent [11]. The marked observables and vertex-scale update below supply the general-graph implementation and its balance guarantees.

The schedule and vertex scales

If \(n=|V|=0\), return one. If a binary vertex count is used and \(n>2|E|\), return zero: the listed edges cannot cover all vertices. On the remaining nonempty input, perform a deterministic perfect-matching existence test and return zero if it fails. Thus the remaining case has even \(n\ge2\) and \(Z(G)\ge1\). Set \[ b=1+\frac1n,\qquad K=\min\left\{k\in\mathbb N:k\ge1,\quad n^{n/2}b^{-k}\le\frac\varepsilon{32}\right\}. \tag{56}\] Since \(\log(1+1/n)\ge1/(2n)\), \[ K\le 1+2n\left(\frac n2\log n+\log(32/\varepsilon)\right). \tag{57}\] At stage \(j\in\{0,\ldots,K\}\) the complete logical graph has raw activities \[w^{(j)}_{uv}= \begin{cases}1,&uv\in E,\\ b^{-j},&uv\notin E.\end{cases}\] Write \(Z_j\) for its perfect-matching partition function. Then \[ Z_0=(n-1)!!,\qquad Z_K=(n-1)!!\prod_{j=0}^{K-1}\frac{Z_{j+1}}{Z_j}. \tag{58}\]

For sampling, we additionally maintain positive vertex scales \(s_i\) and use activities \(\lambda_{ij}=w^{(j)}_{ij}s_i s_j\). Every perfect matching has the same vertex factor \(\prod_i s_i\). Consequently \[ Z_\lambda=Z_j\prod_i s_i, \qquad g_\lambda(ij)=\frac{g_{w^{(j)}}(ij)}{s_i s_j}. \tag{59}\] Initialize \(s_i=1/\left\lfloor\sqrt{n-1}\right\rfloor\). At stage zero, \[g_\lambda(ij)=\frac{\left\lfloor\sqrt{n-1}\right\rfloor^2}{n-1}\in[1/4,1],\] so the logical graph is balanced. The update defined below always multiplies each scale by a positive number at most two, whether or not the estimates succeed. Starting from scales at most one and making at most \(K\) updates, we therefore have at every sampling call \[ 0<\lambda_{ij}\le4^K. \tag{60}\] We use the same structural parameters throughout a trial: \[ D_0=10^8(n+1)^4,\qquad p=2K+2,\qquad N=n+4p\binom n2,\qquad D=100N^2D_0. \tag{61}\] For each current \(\lambda\), construct the enlarged graph and marked bag edges of 4.

Observables from one marked sample

Let \(\lambda^+\) denote the activities at the next raw stage, with the current vertex scales retained. If \(P\) is a logical perfect matching, or a logical matching missing one specified pair of vertices, put \[u(P)=b^{-\#\{e\in P:e\notin E\}}.\] Thus \(\operatorname{wt}_{\lambda^+}(P)=u(P)\operatorname{wt}_\lambda(P)\) and \[ \frac12<b^{-n/2}\le u(P)\le1. \tag{62}\] The strict left inequality follows from \((1+1/n)^{n/2}<\mathrm e^{1/2}<2\).

Sample a colored perfect matching from the bag graph and reveal the real, virtual, and probe portions of its edges. Define the following observables, all in \([0,1]\): \[\begin{align*} a&=\mathbf 1_{\{\text{all edges real}\}},\\ d&=\mathbf 1_{\{\text{all edges real}\}}u(P),\\ z_{ij}&=\mathbf 1_{\{\text{probe }ij\text{ and all other edges real}\}}u(P). \end{align*}\] Here \(P\) is decoded only on the indicated event; elsewhere the observable is zero. On the all-real event it is a full logical perfect matching. On the sole-probe event it is a logical perfect matching missing \(i,j\). Write \(I=Z_{\rm bag}/Z'\) for the inflation factor. Under the exact marked bag law, the means satisfy \[ \mathbb Ea=\frac1I,\qquad \mathbb Ed=\frac{Z_{\lambda^+}}{I Z_\lambda},\qquad \mathbb Ez_{ij}=\frac{Z_{\lambda^+}(-ij)}{D I Z_\lambda}. \tag{63}\] The all-real probability in 7 gives the first equality. The other two follow by multiplying the weights in that event, or in the sole-probe identity (18), by \(u(P)\) and summing. In particular, \[ R:=\frac{Z_{j+1}}{Z_j} =\frac{Z_{\lambda^+}}{Z_\lambda} =\frac{\mathbb Ed}{\mathbb Ea},\qquad g_{\lambda^+}(ij)=D\frac{\mathbb Ez_{ij}}{\mathbb Ed}. \tag{64}\] Thus one batch of marked samples will estimate both the next raw partition ratio and the two-hole ratios needed to choose the next vertex scales.

Estimating and restoring balance

Use \[ \alpha=10^{-5},\qquad \sigma=\min\left\{\frac\alpha{100D},\frac\varepsilon{1000K}\right\},\qquad S=\left\lceil 10\sigma^{-2}(n+K+1)\right\rceil,\qquad \xi=\frac1{1000KS}. \tag{65}\] At each stage make \(S\) independent fresh sampler runs, each with marked output law at total variation distance at most \(3\xi\) from the exact marked bag law. 9 implements these runs in bounded bit time. Let bars denote the empirical means of the observables. Set \[ \widehat R= \begin{cases}\bar d/\bar a,&\bar a>0,\\1,&\bar a=0. \end{cases} \tag{66}\] If \(\bar d>0\), form the symmetric array \[ G_{ij}=\max\left\{\alpha, \min\left\{3,D\frac{\bar z_{ij}}{\bar d}+\alpha\right\} \right\} \quad (i\ne j). \tag{67}\] If \(\bar d=0\), set all \(G_{ij}=1\). The following elementary balancing procedure will be useful.

Lemma 22. Suppose \(G\) is symmetric and \(\alpha\le G_{ij}\le3\) for \(i\ne j\). Initialize \(v_i=2\) for every vertex and visit the vertices in their fixed order, setting \[ v_i\leftarrow\max_{j\ne i}\frac{G_{ij}}{v_j}. \tag{68}\] Every coordinate only decreases, all final coordinates lie in \([\alpha/2,2]\), and the final vector satisfies \(v_i v_j\ge G_{ij}\) with an equality in every row.

Proof. Initially all products equal four and hence dominate \(G\). At an update, feasibility shows that the new value is at most the old value. The definition restores all constraints involving \(i\) and leaves all other constraints unchanged. Since every other coordinate is at most two, the new value is at least \(\alpha/2\). At least one constraint involving \(i\) is tight. If its neighbor is visited later, that neighbor cannot decrease without violating this tight constraint. Thus the equality persists to the end. ◻

After estimating the current ratio, perform this procedure and replace \(s_i\) by \(s_i v_i\). These scales are used with the next raw stage.

Algorithm outline.

After the zero test, one trial uses the parameters in [eq:schedule,eq:counting-structural-parameters,eq:statistical-parameters] and the initial scales above. For \(j=0,\ldots,K-1\):

  1. Form \(\lambda_{uv}=w^{(j)}_{uv}s_us_v\) and its marked bag graph.

  2. Obtain \(S\) independent fresh marked samples using the bounded-bit implementation of 21. Compute the empirical means, then \(\widehat R_j\) and \(G\) by [eq:ratio-estimate,eq:upper-estimate], including their zero-denominator conventions.

  3. Run the one-pass update (68) on \(G\), replace \(s_i\) by \(s_iv_i\), and advance to the next raw stage.

The trial returns \(Y=(n-1)!!\prod_{j=0}^{K-1}\widehat R_j\); the final algorithm takes the median of independent trials as specified below. The current scales are held fixed during each ratio estimate, so their common factors cancel. Every empirical history executes these same steps with the unconditional caps above. Balance is used only to prove the accuracy of histories whose estimates succeed.

Lemma 23. Suppose the current logical activities are balanced and every empirical mean is within \(\sigma\) of its exact mean. Then the next scaled activities are balanced and \[ \left|\frac{\widehat R}{R}-1\right| \le10\sigma\le\frac\varepsilon{100K}. \tag{69}\]

Proof. By 8 and (62), \[\mathbb Ea\ge\frac12,\qquad \mathbb Ed\ge\frac14, \qquad\frac12\le R\le1.\] Reweighting both a full matching and a matching with two holes by factors in \([1/2,1]\) gives \[\frac12 g_\lambda(ij)\le g_{\lambda^+}(ij) \le2g_\lambda(ij).\] In particular the pre-update row maxima lie in \([1/8,2]\). Write \(g^+_{ij}=g_{\lambda^+}(ij)\). Since \(\bar d\ge\mathbb Ed-\sigma>0\), \[\begin{align*} \left|D\frac{\bar z_{ij}}{\bar d}-g^+_{ij}\right| &\le\frac{D|\bar z_{ij}-\mathbb Ez_{ij}| +g^+_{ij}|\bar d-\mathbb Ed|}{\mathbb Ed-\sigma}\\ &\le\frac{(D+2)\sigma}{1/4-\sigma}<\alpha. \end{align*}\] The last inequality follows from \(D\ge1\) and \(\sigma\le\alpha/(100D)\). Since \(0\le g^+_{ij}\le2\), both truncations in (67) preserve \[ g^+_{ij}\le G_{ij}\le g^+_{ij}+2\alpha. \tag{70}\]

During the scaling procedure every updated coordinate satisfies \(v_i\ge\max_jG_{ij}/2\ge1/16\). At the end all entries of the newly scaled two-hole matrix are at most one, by feasibility and (59). In each row choose a final tight neighbor. For that pair, \[\frac{g^+_{ij}}{v_i v_j} \ge1-\frac{2\alpha}{v_i v_j} \ge1-512\alpha>\frac14.\] This proves balance.

For the ratio estimate, using \(R\ge1/2\) and \(\bar a\ge1/2-\sigma\), \[\left|\frac{\widehat R}{R}-1\right| \le\frac{|\bar d-\mathbb Ed|+R|\bar a-\mathbb Ea|} {R(\mathbb Ea-\sigma)} \le\frac{2\sigma}{(1/2)(1/2-\sigma)} <10\sigma.\] The final bound in (69) is the other choice in (65). ◻

Success probability and output

The form of Hoeffding’s inequality [9] used here is: if \(X_1,\ldots,X_S\) are independent, take values in \([0,1]\), and have a common mean \(\mu\), then, for every \(t>0\), \[ \mathbb P\left[\left|S^{-1}\sum_{i=1}^S X_i-\mu\right|>t\right] \le2\exp(-2St^2). \tag{71}\] The theorem applies separately to each observable; the observables within a single sample need not be independent.

Condition on any history in which all preceding stages succeeded. By 23, the current activities are balanced. For independent ideal samples, a union bound over the at most \(n^2+2\) observables gives failure probability at most \[2(n^2+2)\exp(-2S\sigma^2) \le2(n^2+2)\exp(-20(n+K+1))<\frac1{100K}.\] One elementary verification of the last strict inequality is \(\log(200K(n^2+2))\le6+K+2n<20(n+K+1)\) for \(n\ge2,K\ge1\). The actual fresh runs can be coupled to these ideal samples with disagreement probability at most \(3S\xi=3/(1000K)\). Therefore the conditional probability of failure at the first unsuccessful stage is at most \(13/(1000K)\). Summing over all \(K\) stages proves that a whole trial succeeds with probability at least \(1-13/1000>0.9\).

The trial output is the nonnegative rational \[ Y=(n-1)!!\prod_{j=0}^{K-1}\widehat R_j. \tag{72}\] On success, 23 and \(\prod_i(1-t_i)\ge1-\sum_i t_i\) for \(t_i\in[0,1]\) imply \[(1-\varepsilon/100)Z_K\le Y\le\exp(\varepsilon/100)Z_K.\] Every matching using a nonedge has raw final weight at most \(b^{-K}\). There are at most \((n-1)!!\le n^{n/2}\) perfect matchings on the complete graph, so \[ Z(G)\le Z_K\le Z(G)+n^{n/2}b^{-K} \le(1+\varepsilon/32)Z(G). \tag{73}\] For \(0<\varepsilon<1\), the resulting lower bound exceeds \((1-\varepsilon)Z(G)\), and the upper bound is at most \((1+\varepsilon)Z(G)\). For example, \(\exp(\varepsilon/100)\le1+\varepsilon/50\), which gives \[\exp(\varepsilon/100)(1+\varepsilon/32) \le1+\left(\frac1{50}+\frac1{32}+\frac1{1600}\right)\varepsilon <1+\varepsilon.\]

To amplify, let \(\ell=\left\lceil\log_2(1/\delta)\right\rceil\), computed by rational comparisons with powers of two. Run \(r=10(\ell+1)+1\) independent trials and return their median. This is an odd number of trials. Since each succeeds with probability at least \(0.9\), Hoeffding’s inequality for their success indicators bounds the probability of fewer than half succeeding by \[\exp\bigl(-2(0.4)^2r\bigr) \le\exp\bigl(-3.2(\ell+1)\bigr) <2^{-\ell}\le\delta.\] Whenever a majority succeed, the median belongs to the desired interval. The deterministic zero branch was taken before any trials. This proves the correctness and probability assertions of 1, subject only to the bit implementation established next.

A bounded-bit implementation

We finish by specifying a classical finite-bit implementation and proving a worst-case bound. The argument is uniform over all empirical histories, including histories on which balance is lost. Balance controls the statistical accuracy of a successful trial; the unconditional caps in the algorithm control its running time.

Sizes of the parameters and state spaces

Let \(\mathsf b\) be the total binary input length. We use a standard explicit encoding of a finite graph and of the two rationals. If isolated vertices are specified by a binary vertex count, first return zero when \(n>2|E|\). This test is valid for every nonempty graph admitting a perfect matching and ensures that the nonzero branch has \(n\le2|E|=O(\mathsf b)\). The deterministic existence test [5] therefore has polynomial bit cost on the original graph. It is the only matching-existence oracle used.

[eq:schedule-length] bounds \(K\) polynomially in \(\mathsf b\). It can be found without logarithms by iterating rational powers of \(b\) and comparing the two sides of (56). The parameters \(p,N,D_0,D\) are integers of polynomial numerical size in \(n,K\). The hierarchy has at most \[ H_{\rm tree}=N(2K+1) \tag{74}\] nodes, since its levels are \(0,\ldots,2K\) and every level has at most \(N\) components. The number of colored edges is less than \(N^2\).

Use the ladder parameters \(c,T,L,q,M,\Lambda\) from [eq:energy-constants,eq:ladder-parameters,eq:ladder-update-count,eq:ladder-lambda], and write \[t_{\rm mix}=s(\xi),\] where \(s(\xi)\) is defined in (54). The structural parameters \(N,D,K\) are fixed throughout a trial. Hence the same \(T\) makes the final tier unclamped on every empirical history, by [eq:unconditional-height-bound,eq:ladder-global-range]. It can be found by iterating rational powers of \(c\) until the defining inequality in (42) holds. The bound (44) is polynomial in \(N,K,D\). Ceilings of binary logarithms are found by integer or rational comparisons with powers of two. These bounds and the product-state size \(q(T+1)\) are polynomial in \(\mathsf b\) and \(\varepsilon^{-1}\). Indeed, \[\sigma^{-1}\le C(D+K\varepsilon^{-1}),\qquad S=O\bigl((D^2+K^2\varepsilon^{-2})(n+K+1)\bigr),\qquad \xi^{-1}=1000KS,\] for an absolute constant \(C\). The exponent \(100\) in \(L\) is fixed.

There is no initial-sampling problem at the upper tiers. Pair the logical vertices in their fixed order and expand this matching by the path tilings. All logical activities are positive, so this is an available real perfect matching with assigned colors. Initialize every slot to that matching. The mixing bound applies from this deterministic product state.

Rational bit lengths

We record explicitly why the adaptive scales do not create an arithmetic blowup. Put \[ B_G=1+n\left\lceil\log_2(n+1)\right\rceil+\left\lceil\log_2(S+1)\right\rceil +\left\lceil\log_2(D+1)\right\rceil. \tag{75}\] Absolute multiplicative constants in the bit bounds below are independent of the input.

Every nonzero sample contribution is \((n/(n+1))^a\) for some \(0\le a\le n/2\). These fractions have the common denominator \(Q=(n+1)^{n/2}\). Thus empirical means, their ratios, and the capped entries \(G_{ij}\) have \(O(B_G)\) numerator and denominator bits. This bound does not involve the current scales.

An assignment in (68) chooses one maximizer \(j\) and sets \(v_i=G_{ij}/v_j\). At that moment \(v_j\) is either the initial value two or an expression formed at an earlier update. Following such dependencies strictly decreases the update index, so it produces a chain of at most \(n\) factors. Each \(v_i\) consequently has \(O(nB_G)\) bits. Accumulating at most \(K\) scale updates gives \(O(KnB_G)\) bits per scale. The raw activities have \(O(K\log(n+1))\) bits. These estimates apply even when all observations are unfavorable, because the clipping and branch conventions are unconditional.

Bottleneck entries \(B_{ij}\) and the maxima \(H_i=\max_{j\ne i}B_{ij}\) select from finitely many input activities and one; they do not involve sums over paths. Initialize \(B_{ij}=\max\{1,\lambda_{ij}\}\) and, for each vertex \(k\), update the entries with distinct \(i,j\ne k\) by \[B_{ij}\leftarrow\max\{B_{ij},\min\{B_{ik},B_{kj}\}\}.\] This is the max–min Floyd–Warshall recurrence: after processing \(k\), the entries allow the processed vertices as internal path vertices. It uses \(O(n^3)\) rational comparisons. The path profiles add only powers of two of bit length \(O(K)\). Bag activities are sums of a real activity and a dyadic height divided by \(D\). Finally \(c^{\pm t}\) has \(O(T\log(N+1))\) bits for \(t\le T\).

It follows that every single-edge activity used by the sampler has numerator and denominator lengths at most the integer bound \[ B_W=C_1\bigl(KnB_G+K+\left\lceil\log_2(D+1)\right\rceil +T\left\lceil\log_2(N+1)\right\rceil+1\bigr), \tag{76}\] where \(C_1\) is a sufficiently large absolute positive integer. A product of at most \(N\) such activities has \(O(NB_W)\) bits. In a Metropolis acceptance ratio the unknown normalizing constants cancel. Thus even a cycle exchange at unequal tiers requires only rational products of this size. The real and probe revelation probabilities are likewise rational, respectively the real portion divided by the collapsed activity and \(1/(DW)\) for the probe portion.

By 19, the bottom-tier dynamic program uses counts of \(O(N\log(N+1))\) bits. Its categorical normalizers count the same partial completions and obey the same bound. Label and loop indices use an additional \(O(\log(H_{\rm tree}+1)+\log(N+1))\) bits, since \(b_{\rm tree}\le H_{\rm tree}\) in the constructed hierarchy. The table computation and sampling therefore use polynomially many integer operations with polynomial bit lengths.

Random choices with a fixed number of bits

Lemma 24. Let \(p_1,\ldots,p_r\) be nonnegative rational numbers summing to one. Choose a uniform integer \(J\in\{0,\ldots,2^k-1\}\) using exactly \(k\) fair bits, and return the least index \(i\) such that \(J/2^k<\sum_{j\le i}p_j\). The output law is at total variation distance at most \(2r\,2^{-k}\) from \((p_i)_{i=1}^r\).

Proof. For any interval \([a,b)\subseteq[0,1)\), the number of grid points \(j/2^k\) in the interval differs from \(2^k(b-a)\) by at most two. Apply this to the successive cumulative-probability intervals and sum the absolute probability discrepancies. The factor one half in total variation only improves the stated bound. An outcome with \(p_i=0\) has an empty interval and is never returned. ◻

The exact categorical choices in the unit-tier dynamic program define an ideal transition law. The actual algorithm implements each such choice, along with every proposal and acceptance choice, by the fixed grid in 24. Hence exactness of the dynamic program is a counting identity; sampling from its tables in bounded bit time incurs the error budget derived below.

Every choice in the chain is either uniform on an explicitly indexed finite set, Bernoulli, or proportional to a list of nonnegative integers supplied by the dynamic program. For each used edge, final revelation is a rational categorical choice with at most three outcomes. Subsets and pairings are sampled sequentially, so no exponential list is needed. Uniform choices among the \(M\) scan positions can be implemented by integer arithmetic on the index rather than by enumerating the scan positions.

A bound on the number of random choices in one complete sampler run, including marking its output, is \[ R_{\rm draw}=100(t_{\rm mix}+1)(N+1)^2(K+2). \tag{77}\] To see this, laziness and the scan take two choices per step, and a pair update takes at most eight further choices. By 19, a refresh takes at most \(4(H_{\rm tree}+N+1)\) choices. Allowing both bounds at every step and adding the at most \(N\) choices for final marking gives \[t_{\rm mix}\bigl(10+4(H_{\rm tree}+N+1)\bigr)+N.\] Since \(H_{\rm tree}=N(2K+1)\), this is bounded by (77). The bound therefore includes every categorical choice made by the implemented sampler. The number of options in any one choice is at most \[ R_{\rm opt}=10(M+N^2+1). \tag{78}\] Choose the same bit budget \(k\) for all these choices, with \[ 2^k\ge\frac{2R_{\rm draw}R_{\rm opt}}\xi. \tag{79}\] This integer is found by doubling; \(k\) is polynomially bounded. By 24, the sum of all conditional simulation errors is at most \(\xi\). Successive coupling, while the simulated and exact histories agree, bounds the total variation error of the whole run and its marking by \(\xi\). The exact-kernel mixing error is at most \(\xi\), so the implemented marked sample is within \(2\xi\), and in particular \(3\xi\), of the required law. The number of fair bits used has a deterministic bound \(kR_{\rm draw}\). There is no rejection loop or random convergence test.

Total bit cost

The preceding bounds already give a polynomial-time implementation. To make the accounting explicit, take a common bit bound \[B_* = C\bigl(NB_W+N\log(N+1)+\mathsf b +\log(M+1)+\log(t_{\rm mix}+1) +\log(\xi^{-1}+1)+1\bigr)\] with a sufficiently large absolute constant \(C\) and \(B_W\) from (76). In particular \(NB_W\) dominates \(KB_G\), the bit cost of multiplying the \(K\) empirical ratios. The bound \(B_*\) covers all integers used in weight products, dynamic-program counts, cumulative choices, acceptance comparisons, and output products. All categorical laws just described admit common-denominator integer weights, so computing their cumulative sums respects the same bound. Schoolbook arithmetic and the Euclidean algorithm perform the needed operations within \(O(B_*^3)\) bit time per operation.

A deliberately loose bound of \(O((H_{\rm tree}+1)(N+1)^4)\) arithmetic operations covers graph construction, the bottom-tier tables, and any one transition or refresh; storing the product state additionally takes \(O(q(T+1)N B_*)\) bits. Thus a trial, including all \(K\) stages and \(S\) fresh runs at each stage, has bit cost bounded by a fixed polynomial in \[K,\ S,\ t_{\rm mix},\ H_{\rm tree},\ N,\ q(T+1),\ B_*.\] For example, the sum of \[CKS(t_{\rm mix}+1)(H_{\rm tree}+1)(N+1)^4B_*^3 \quad\text{and}\quad CKSq(T+1)(N+1)B_*^3\] is a valid coarse envelope for arithmetic, repeated initialization, and storage operations. Each displayed parameter is polynomial in \(\mathsf b\) and \(\varepsilon^{-1}\). The \(r=10(\left\lceil\log_2(1/\delta)\right\rceil+1)+1\) repetitions and the rational comparisons used to select their median add a factor polynomial in \(\log\delta^{-1}\) and the input length.

All data structures, loop bounds, and rational comparisons have now been specified by finite procedures. Every auxiliary parameter is bounded by a polynomial of fixed degree, and the bound holds on every random history. Together with 8, this completes the proof of 1.

Prescribed-degree subgraphs and fixed-cardinality matchings

We record two counting consequences of 1 and a corresponding output-sampling guarantee. Throughout this section, the input host \(G=(V,E)\) is a finite simple undirected unweighted graph whose vertices and edges are explicitly listed, including any isolated vertices. Only edges in \(E\) may be selected, so absent edges may be forbidden arbitrarily. The objects counted are labeled edge subsets, not isomorphism classes. For binary-encoded integer demands \(f=(f_v)_{v\in V}\) and a binary-encoded integer \(k\), define \[\begin{aligned} \mathcal F(G,f)&=\{F\subseteq E:\deg_F(v)=f_v\text{ for every }v\in V\},\\ \mathcal M_k(G)&=\{M\subseteq E:M\text{ is a matching and }|M|=k\}. \end{aligned}\]

Corollary 25. For either family \(\mathcal A=\mathcal F(G,f)\) or \(\mathcal A=\mathcal M_k(G)\), there are uniform classical randomized algorithms with the following guarantees.

  1. Given rational \(0<\varepsilon<1\) and \(0<\delta<1/2\), the counting algorithm returns a nonnegative rational \(\widehat N\) such that \[\mathbb P[(1-\varepsilon)|\mathcal A|\le \widehat N\le(1+\varepsilon)|\mathcal A|] \ge1-\delta.\] If \(\mathcal A\) is empty, it returns zero with certainty. Its bit running time on every execution is polynomial in the full input encoding length, \(\varepsilon^{-1}\), and \(\log\delta^{-1}\).

  2. Given rational \(0<\tau<1\), the sampling algorithm reports infeasibility exactly when \(\mathcal A\) is empty. Otherwise it returns a member \(X\) of \(\mathcal A\) on every execution, and \[\mathop{\mathrm{TV}}(\mathcal L(X),U_{\mathcal A})\le\tau,\] where \(U_{\mathcal A}\) is the uniform law on \(\mathcal A\) and \(\mathop{\mathrm{TV}}(\mu,\nu)=\frac12\sum_x|\mu(x)-\nu(x)|\). Its bit running time on every execution is polynomial in the full input encoding length and \(\tau^{-1}\).

Only the stated total-variation and polynomial-in-\(\tau^{-1}\) sampling guarantee is asserted. In particular, the statement does not assert exact or pointwise almost-uniform sampling. The explicit simple unweighted host model does not encode edge weights or compressed multiplicities.

Constant-fibre reductions

Write \(n=|V|\), \(m=|E|\), and \(d_v=\deg_G(v)\).

The prescribed-degree reduction.

We use Tutte’s reduction of prescribed degrees to perfect matchings [18], keeping the dummy vertices labeled so that its counting multiplicity is explicit. If some \(f_v\) is outside \(0\le f_v\le d_v\), the family is empty and we return zero or report infeasibility, as appropriate. For valid demands put \(s_v=d_v-f_v\). Construct a simple unweighted graph \(H_f\) with one tagged port \((v,e)\) for every incidence of an edge \(e\) at \(v\). For each original edge \(e=\{u,v\}\), join \((u,e)\) to \((v,e)\) by a cross edge. At each \(v\), add \(s_v\) labeled private dummy vertices, each adjacent to all \(d_v\) ports at \(v\). There are no other edges. The tags distinguish ports and dummies, so simplicity of \(G\) makes \(H_f\) simple. Its sizes satisfy \[|V(H_f)|=2m+\sum_v s_v=4m-\sum_v f_v\le4m, \qquad |E(H_f)|=m+\sum_v d_vs_v\le m+2m(n-1).\] Thus the gadget is explicit and polynomial in the host size; the initial demand check prevents expansion of arbitrarily large binary demands.

Project a perfect matching of \(H_f\) to the original edges whose cross edges it contains. Each dummy at \(v\) uses a distinct \(v\)-port. The remaining \(f_v\) ports must use cross edges, so the projection lies in \(\mathcal F(G,f)\). Conversely, an \(f\)-factor fixes its cross edges. Its remaining \(s_v\) ports at \(v\) can be bijected to the labeled dummies in \(s_v!\) ways, independently at each vertex. Hence every factor has the same number of preimages, and \[ C_f=\prod_v(d_v-f_v)!,\qquad Z(H_f)=C_f|\mathcal F(G,f)|. \tag{80}\] The fibre may be factorial, but \(\log C_f=O(m\log(n+1))\), so \(C_f\) has polynomial bit length. For an edgeless host with all demands zero, both the unique factor and the gadget’s unique perfect matching are empty, and \(C_f=1\) by \(0!=1\). Other infeasible valid inputs give gadgets without perfect matchings by the same correspondence.

The fixed-cardinality reduction.

If \(k<0\) or \(2k>n\), the family is empty, so return zero or report infeasibility, as appropriate. Otherwise put \(q=n-2k\). Form \(H_k\) by adding \(q\) labeled dummy vertices to \(G\), joining each dummy to every original vertex, and adding no edges between dummies. Keep all original edges. This is a simple unweighted graph with at most \(2n\) vertices and \(m+n^2\) edges. In every perfect matching, the dummies use \(q\) distinct original vertices; the remaining \(2k\) original vertices are paired by exactly \(k\) host edges. Conversely, a \(k\)-matching leaves \(q\) original vertices, which can be bijected to the dummies in \(q!\) ways. Therefore \[ C_k=(n-2k)!,\qquad Z(H_k)=C_k|\mathcal M_k(G)|. \tag{81}\] Here \(\log C_k=O(n\log(n+1))\). The same bijection covers \(k=0\), \(2k=n\), and \(n=k=0\), using \(0!=1\).

Proof of 25(i). Apply 1 to the appropriate gadget and divide its nonnegative rational output by the corresponding positive integer \(C_f\) or \(C_k\). Compute these factorial products exactly and perform exact rational division, without rounding to an integer. Their displayed bit lengths and the polynomial gadget sizes preserve the asserted relative error, confidence, certain-zero behavior, and every-execution bit bound. This proves the counting assertion. The correspondences also make feasibility equivalent to perfect-matching feasibility in the gadget. ◻

A deletion sampler for perfect matchings

The conversion from counts to samples uses the self-reduction framework of Jerrum, Valiant, and Vazirani [12]. We give the deletion procedure explicitly to retain feasibility on every execution and to track its total-variation and bit-time bounds. It uses 1 only through its counting guarantee.

Lemma 26. Given a finite simple undirected unweighted graph \(H_0\) whose vertices and edges are explicitly listed, and a rational \(0<\tau<1\), there is a uniform classical randomized algorithm that reports infeasibility exactly when \(H_0\) has no perfect matching. Otherwise it returns a perfect matching on every execution, and its output law is at total variation distance at most \(\tau\) from the uniform perfect-matching law. Its bit running time on every execution is polynomial in the full input encoding length and \(\tau^{-1}\).

Proof. First decide perfect-matching feasibility by the deterministic polynomial-time matching algorithm of Edmonds [5]. Report infeasibility if appropriate, and return the empty matching when \(V(H_0)=\varnothing\). Otherwise set \(m_0=|E(H_0)|\) and \(m_*=\max\{1,m_0\}\). Choose \[\eta=\gamma=\frac{\tau}{8m_*},\qquad t=\min\{j\in\mathbb N:2^j\ge 8m_*/\tau\}.\] The integer \(t\) is computed by doubling and exact rational comparison.

Maintain a feasible residual graph \(H\) and the already selected edges. Choose the first residual edge \(e=uv\) in a fixed deterministic ordering. Perfect matchings of \(H\) excluding \(e\) are counted by \(Z(H-e)\); those including \(e\) correspond bijectively, after deleting \(e\), to perfect matchings of \(H-u-v\). Test both child graphs for feasibility exactly. At least one is feasible. If only one is feasible, take it. If both are feasible, make two fresh calls to 1, with relative error \(\eta\) and failure probability \(\gamma\), obtaining nonnegative rational estimates \(A\) for \(Z(H-u-v)\) and \(B\) for \(Z(H-e)\). If \(A+B=0\), take the exclusion child. Otherwise put \(\widehat p=A/(A+B)\), draw exactly \(t\) fresh fair bits as a uniform integer \(J\in\{0,\ldots,2^t-1\}\), and take the inclusion child precisely when \[J<\left\lfloor 2^t\widehat p\right\rfloor.\] Replace \(H\) by the chosen child. Whenever the inclusion child is taken, including a forced choice, append \(e\) to the selected edges. All ratio and floor operations are exact rational or integer operations.

Every chosen child is feasible, regardless of the estimates. Each decision removes at least one residual edge, so there are at most \(m_0\) decisions. When no residual edges remain, feasibility forces the residual vertex set to be empty. The selected edges then form a perfect matching of \(H_0\) on every execution.

For the error bound, compare this process to the ideal deletion sampler that takes the inclusion child with its exact count ratio. These exact ratios telescope, giving the uniform perfect-matching law. At a history where both children are feasible, write their positive counts as \(z_+\) and \(z_-\), with \(p=z_+/(z_++z_-)\). When both estimates succeed, write \(A=z_+(1+a)\) and \(B=z_-(1+b)\), where \(|a|,|b|\le\eta\). Then \[|\widehat p-p| =\frac{z_+z_-|a-b|} {(z_++z_-)(z_+(1+a)+z_-(1+b))} \le\frac{\eta}{2(1-\eta)}.\] The last step uses \(z_+z_-\le(z_++z_-)^2/4\). Fresh call randomness bounds the conditional probability that either estimate fails by \(2\gamma\), at every adaptive history. On failure the branch law can change by at most one in total variation, while the dyadic floor changes the successful branch probability by at most \(2^{-t}\). The fallback \(A+B=0\) occurs only on a failed estimate when both true counts are positive. Thus the conditional branch-law error is at most \[\beta=\frac{\eta}{2(1-\eta)}+2\gamma+2^{-t}.\] Forced branches have zero error. Couple the two deletion processes until their prefixes differ. With at most \(m_0\) decisions, the output total-variation error is at most \(m_0\beta\). Since \(\eta<1/8\) and \(2^{-t}\le\eta\), we have \(\beta\le4\eta\) and hence \[m_0\beta\le4m_*\eta=\tau/2<\tau.\]

There are at most \(2m_0\) counting calls and \(2m_0+1\) exact feasibility tests, all on simple graphs no larger than \(H_0\). The inverse relative error is \(8m_*/\tau\), and the logarithmic confidence cost is \(\log(8m_*/\tau)\). The every-execution bit bound of 1 also bounds the bit lengths of its outputs on failed calls. Therefore the exact ratio and floor computations, the \(t=O(\log(m_*/\tau))\) fresh bits per branch, and all graph updates have bit cost polynomial in the full input length and \(\tau^{-1}\) on every execution. No rejection loop or random stopping criterion is used. ◻

Proof of 25(ii). For sampling, apply 26 to \(H_f\) or \(H_k\) and decode by keeping the original edges represented by selected cross edges, or by discarding the dummy-incident edges, respectively. Exact feasibility testing of the gadget reports infeasibility precisely for an empty target family. Uniform perfect matchings project to the uniform target law because the fibres in (80) and (81) are constant across target members. Deterministic decoding cannot increase total variation and takes polynomial time, without enumerating any fibre. Every decoded output is feasible, which proves the sampling assertion. ◻

  1. 99 urlstyle
  2. Ivona Bezáková, Daniel Štefankovič, Vijay V. Vazirani, and Eric Vigoda. Accelerating simulated annealing for the permanent and combinatorial counting problems. SIAM Journal on Computing, 37(5): 1429–1454, 2008. doi: 10.1137/050644033.
  3. Jin-Yi Cai and Tianyu Liu. Counting perfect matchings and the eight-vertex model. In Artur Czumaj, Anuj Dawar, and Emanuela Merelli, editors, 47th International Colloquium on Automata, Languages, and Programming (ICALP 2020), volume 168 of Leibniz International Proceedings in Informatics, pages 23:1–23:18. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 2020. doi: 10.4230/LIPIcs.ICALP.2020.23. URL https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.ICALP.2020.23.
  4. Xiaoyu Chen, Heng Guo, Eric Vigoda, and Xiongxin Yang. Fast FPRAS for the permanent. Preprint, arXiv:2609.20717v1, 2026. URL https://arxiv.org/abs/2609.20717v1.
  5. Xiaoyu Chen, Eric Vigoda, and Xiongxin Yang. Faster FPRAS for the permanent via restricted Poincaré inequalities and coupled flows. Preprint, arXiv:2608.26599v1, 2026. URL https://arxiv.org/abs/2608.26599v1.
  6. Jack Edmonds. Paths, trees, and flowers. Canadian Journal of Mathematics, 17: 449–467, 1965. doi: 10.4153/CJM-1965-045-4.
  7. Bradley Efron and Charles Stein. The jackknife estimate of variance. The Annals of Statistics, 9 (3): 586–596, 1981. doi: 10.1214/aos/1176345462.
  8. Yumou Fei, Leslie Ann Goldberg, and Pinyan Lu. Two-state spin systems with negative interactions. Information and Computation, 307: 105340, 2025. doi: 10.1016/j.ic.2025.105340.
  9. W. K. Hastings. Monte Carlo sampling methods using Markov chains and their applications. Biometrika, 57 (1): 97–109, 1970. doi: 10.1093/biomet/57.1.97.
  10. Wassily Hoeffding. Probability inequalities for sums of bounded random variables. Journal of the American Statistical Association, 58 (301): 13–30, 1963. doi: 10.1080/01621459.1963.10500830.
  11. Mark Jerrum and Alistair Sinclair. Approximating the permanent. SIAM Journal on Computing, 18 (6): 1149–1178, 1989. doi: 10.1137/0218077.
  12. Mark Jerrum, Alistair Sinclair, and Eric Vigoda. A polynomial-time approximation algorithm for the permanent of a matrix with nonnegative entries. Journal of the ACM, 51 (4): 671–697, 2004. doi: 10.1145/1008731.1008738.
  13. Mark R. Jerrum, Leslie G. Valiant, and Vijay V. Vazirani. Random generation of combinatorial structures from a uniform distribution. Theoretical Computer Science, 43: 169–188, 1986. doi: 10.1016/0304-3975(86)90174-X.
  14. P. W. Kasteleyn. Dimer statistics and phase transitions. Journal of Mathematical Physics, 4 (2): 287–293, 1963. doi: 10.1063/1.1703953.
  15. Nicholas Metropolis, Arianna W. Rosenbluth, Marshall N. Rosenbluth, Augusta H. Teller, and Edward Teller. Equation of state calculations by fast computing machines. The Journal of Chemical Physics, 21 (6): 1087–1092, 1953. doi: 10.1063/1.1699114.
  16. Alistair Sinclair. Improved bounds for mixing rates of Markov chains and multicommodity flow. Combinatorics, Probability and Computing, 1: 351–370, 1992. URL https://people.eecs.berkeley.edu/ sinclair/flow.pdf.
  17. Daniel Štefankovič, Eric Vigoda, and John Wilmes. On counting perfect matchings in general graphs. In Michael A. Bender, Martín Farach-Colton, and Miguel A. Mosteiro, editors, LATIN 2018: Theoretical Informatics, volume 10807 of Lecture Notes in Computer Science, pages 873–885. Springer, 2018. doi: 10.1007/978-3-319-77404-6_63. Full version: arXiv:1712.07504v1. URL https://arxiv.org/abs/1712.07504v1.
  18. Robert H. Swendsen and Jian-Sheng Wang. Replica Monte Carlo simulation of spin-glasses. Physical Review Letters, 57 (21): 2607–2609, 1986. doi: 10.1103/PhysRevLett.57.2607.
  19. W. T. Tutte. A short proof of the factor theorem for finite graphs. Canadian Journal of Mathematics, 6: 347–352, 1954. doi: 10.4153/CJM-1954-033-3.
  20. Leslie G. Valiant. The complexity of computing the permanent. Theoretical Computer Science, 8 (2): 189–201, 1979. doi: 10.1016/0304-3975(79)90044-6.
  21. Jian-Sheng Wang and Robert H. Swendsen. Replica Monte Carlo simulation (revisited). Progress of Theoretical Physics Supplement, 157: 317–323, 2005. doi: 10.1143/PTPS.157.317. Preprint version: https://arxiv.org/abs/cond-mat/0407273v1.
LEVEL 1 COMPLETE!
You read 19,369 words and 1,407 formulas. Your math teacher would be proud.
Converted from the LaTeX source. Something look off? The original PDF is the real thing.

Cool Links: openai/math   Lean   Mathlib   arXiv   the real Coolmath Games