arXiv:2610.26803cs.DSOct 2026

Manuscript Offprint

arXiv:2610.26803

A simplified proof of the FPRAS for counting perfect matchings

Chenghua Liu, Boning Meng

Abstract

We give a simplified, self-contained proof of OpenAI's FPRAS for counting perfect matchings in general graphs. As in the original proof, we use a restricted Poincaré inequality for two matchings to sample weighted perfect matchings and estimate their total weight. We simplify the proof of this inequality by isolating parts of alternating cycles directly on the original vertex set and controlling the resulting error terms. This avoids the auxiliary vertices and tree constructions used in the original proof. The argument preserves the required parameter bounds and yields the same FPRAS guarantee.

1 Introduction

A perfect matching of a graph is a set of edges that covers every vertex exactly once. Finding one and counting all of them have very different complexity. Edmonds [7] gave a polynomial-time algorithm for maximum matching in general graphs, whereas Valiant [16] proved that counting perfect matchings is #P-complete even in bipartite graphs. In the bipartite case, the count is the permanent of the bipartite adjacency matrix. Planar graphs admit polynomial-time exact counting through Kasteleyn's Pfaffian method [12]. For unrestricted graphs, can the count be approximated to prescribed relative error in randomized polynomial time?

Approximate counting is closely tied to almost-uniform sampling through the reductions of Jerrum, Valiant, and Vazirani [11] for self-reducible counting problems. Jerrum and Sinclair [9] gave a fully polynomial randomized approximation scheme (FPRAS) for counting all matchings in an arbitrary graph, summed over all cardinalities. For counting perfect matchings, their method also allows near-perfect matchings, which leave exactly two vertices unmatched. Its guarantee requires a polynomial bound on the ratio of near-perfect to perfect matchings. Otherwise, rejection from the enlarged state space may succeed with exponentially small probability. Jerrum, Sinclair, and Vigoda [10] removed this restriction for bipartite graphs, obtaining an FPRAS for the permanent of every nonnegative matrix. They reweighted the near-perfect classes according to their unmatched vertices and learned these weights during annealing. Bezáková, Štefankovič, Vazirani, and Vigoda [2] subsequently improved the cooling schedule and mixing analysis.

The extension to general graphs encounters concrete obstructions. Štefankovič, Vigoda, and Wilmes [15, full version, Theorem 2.2] constructed graphs on which every chain with the transitions in [10] and weights depending only on the unmatched vertices either mixes exponentially slowly or assigns exponentially small stationary mass to perfect matchings. Reweighting these classes alone therefore cannot repair the chain. Blossoms, the odd-cycle structures used in Edmonds' algorithm, do not give an immediate remedy: uniformly sampling all blossoms through a specified unmatched vertex is intractable unless NP = RP, while restricting to minimum blossoms leaves the bottleneck [15, full version, Section 3]. Their recursion based on the Gallai–Edmonds decomposition handles further structured cases and the slow-mixing examples, but can take exponential time in general [15, full version, Section 4].

Restricting the state space to perfect matchings raises a different difficulty. Two-edge switches are not even irreducible on a chordless even cycle of length at least six. On quasimonotone graphs, Dyer and Müller [5] proved rapid mixing of the two-edge switch chain, but they also exhibited exponentially slow mixing on examples in a larger hereditary class. A sampler based on two-edge switches therefore needs both a connectivity argument and a mixing bound.

Other approaches obtain approximation guarantees under additional assumptions on the graph or its edge weights. When a graph is regular and has sufficiently strong expansion, Ebrahimnejad, Nagda, and Oveis Gharan [6] bound the ratio of near-perfect to perfect matchings. When its degree is also bounded, this yields a polynomial-time sampler. Analytic methods provide a different route through hafnians, the weighted perfect-matching sums for general graphs. When all off-diagonal entries lie in [θ,1][\theta, 1] for fixed θ>0\theta > 0, Barvinok [1] gives deterministic quasipolynomial-time relative approximation. When the support has minimum degree at least (1/2+γ)n(1/2 + \gamma)n and nonzero weights lie in [θ,1][\theta, 1], with fixed 0<γ<1/20 < \gamma < 1/2 and 0<θ≤10 < \theta \leq 1, Yi [17] gives a deterministic fully polynomial-time approximation scheme. An FPRAS for general graphs must also handle arbitrary sparse graphs without any expansion assumption.

Mixing analyses also developed beyond the original matching chains. Sinclair’s multicommodity-flow bounds [14] relate mixing to the load placed on chain transitions. In the bipartite setting, recent improvements for the permanent use restricted Poincaré inequalities and energy-based flows [4, 3]. For arbitrary graphs, OpenAI’s September 2026 manuscript [13] obtains an FPRAS for counting perfect matchings by combining a two-matching energy comparison with replication, completion, and marked-edge estimators. We give a simplified proof of their result, including its worst-case bit guarantee.

Theorem 1.1 (OpenAI [13]). There is a randomized algorithm which, given a finite simple graph G and rational 0<ε,δ<10 < \varepsilon, \delta < 1, returns a nonnegative rational Z^\widehat{Z} such that

P[(1−ε)Z(G)≤Z^≤(1+ε)Z(G)]≥1−δ,\mathbb{P}\big[(1-\varepsilon)Z(G)\leq\widehat{Z}\leq(1+\varepsilon)Z(G)\big]\geq1-\delta,

where Z(G)Z(G) is the number of perfect matchings of GG. Its worst-case bit running time and number of fair random bits are polynomial in the total input length, ε−1\varepsilon^{-1}, and log⁡(1/δ)\log(1/\delta).

The simplification concerns the comparison argument in Sections 4–6 of [13]. We carry it out directly on the original vertex set and retain OpenAI's framework for converting the comparison into sampling and counting algorithms. We give the required arguments below.

To describe this framework, let n be even and assign each edge e of the complete graph KnK_n a positive weight aea_e, also called its activity. A perfect matching has weight equal to the product of its edge weights. Its sampling probability is proportional to this product:

wa(M)=∏e∈Mae,Za=∑Mwa(M),πa(M)=wa(M)/Za,(1.1)w_{a}(M)=\prod_{e\in M}a_{e},\qquad Z_{a}=\sum_{M}w_{a}(M),\qquad\pi_{a}(M)=w_{a}(M)/Z_{a}, \tag{1.1}

where M ranges over perfect matchings and ZaZ_{a}, the total weight, is the partition function. The counting algorithm starts with every edge weight equal to one. The initial total weight can then be computed directly. The algorithm gradually lowers the weights of edges absent from G, keeping the weights of graph edges equal to one. This procedure is called annealing. At the end, the total weight differs from Z(G)Z(G) by the small contribution of matchings using nonedges. Each successive ratio of total weights is estimated by averaging the multiplicative changes in matching weights over samples from the current distribution. Multiplying the estimated ratios by the known initial total weight gives the final estimate. The main algorithmic task is therefore to sample the weighted matching distributions along this sequence.

Sampling must remain efficient even when edge weights differ greatly. OpenAI's completion [13, proof of Theorem 3.1] uses the following hierarchy. Keep only edges above a chosen weight threshold. As the threshold decreases, connected components merge into larger groups, forming a hierarchy. OpenAI use these connection thresholds to assign auxiliary weights to vertex pairs. Adding these to the original weights gives completed weights that are within a polynomial factor of hierarchical reference weights. They also show how to apply this completion while increasing the total matching weight by at most a constant factor.

For a distribution with this structure, consider two independent matchings M1,M2∼πaM_{1}, M_{2} \sim \pi_{a}. Their differing edges form disjoint even cycles, with edges alternating between the two matchings.

The comparison uses two operations: a two-edge switch replaces two edges in M1M_{1} by another pairing of their endpoints, and a cycle exchange swaps the alternating patterns of M1M_{1} and M2M_{2} on an entire cycle. These operations are combined into a reversible random update. For a numerical quantity on matchings, we compare its overall fluctuation, measured by variance, with its mean squared change in one update. The restricted Poincaré inequality in Theorem 2.1 provides the comparison needed for the sampling construction. Its constant depends polynomially only on the number of vertices and the largest ratio of an edge weight to its corresponding reference weight, even when the reference weights differ greatly.

To prove Theorem 2.1, we first reduce the variance bound to controlling changes in the chosen quantity under cycle exchanges. We call these changes cycle gains. We view each cycle as a polygon and divide it along the weight hierarchy. Adapting OpenAI's identity [13, Lemma 6.3], we express its gain through changes under two-edge switches and gains on smaller cycles, with errors from different exterior matchings. OpenAI's proof introduces auxiliary vertices for this decomposition. We instead isolate each smaller region directly from the original matching pair by one two-edge switch, so that a cycle exchange can act on it alone. The resulting weight loss has the same bound at every depth, and the construction uses only the original vertices.

We apply the same gain identity to each smaller cycle. Its gain appears in the larger cycle's expansion and on the left-hand side of its own identity. Direct isolation can change the exterior matching and hence the gain. Combining the identities leaves the difference between the two gains as an error. Subtracting the same mean from both gains expresses this error as a difference of centered gains. Cycle exchanges control these errors after summing over matching pairs. This adapts OpenAI's use of centering to control exterior errors [13, Section 6.4].

The expansion contains two-edge switch gains and centered gains controlled by cycle exchanges. Summing either type requires bounds on repeated contributions from different matching pairs. Adapting OpenAI's encoding [13, Lemma 6.4], we encode each contribution by an ordered matching pair for weight comparison and an auxiliary record. These data recover the original pair and the chosen expansion term. Since the record takes polynomially many values, only polynomially many contributions can give the same output pair. Comparing input and output weights then bounds their total probability mass. For a centered gain, the output pair contains the two alternating patterns on its cycle, allowing cycle exchanges to control the errors after summation. Finally, Cauchy–Schwarz bounds the square of the full gain expansion by a polynomial factor times the sum of squared terms. These estimates prove Theorem 2.1.

OpenAI’s replication construction uses joint matching updates to turn the comparison into a polynomial-time approximate sampler for the completed weights. To relate these samples to the weights before completion, OpenAI mark sampled edges as real or virtual, distinguishing original and auxiliary weight contributions. The marked samples estimate the successive total-weight ratios used in annealing, completing the counting algorithm [13, Section 8.2].

We begin in Section 2 by proving the comparison under the hierarchical weight assumption. Section 3 uses it to construct a sampler. Section 4 gives the completion and controls its increase in total matching weight, then applies the sampler to obtain marked matchings. Section 5 combines these ingredients to prove Theorem 1.1. Appendix A supplies a finite-precision implementation with worst-case polynomial bounds on bit running time and random-bit use.

References (16)