---
abstract: 'Using Jeřábek’s framework for probabilistic reasoning, we formalize the correctness of two fundamental ${\mathsf{RNC}}^{2}$ algorithms for bipartite perfect matching within the theory ${\textit{VPV}}$ for polytime reasoning.  The first algorithm is for testing if a bipartite graph has a perfect matching, and is based on the Schwartz-Zippel Lemma for polynomial identity testing applied to the Edmonds polynomial of the graph.  The second algorithm, due to Mulmuley, Vazirani and Vazirani, is for finding a perfect matching, where the key ingredient of this algorithm is the Isolating Lemma.' 
address: 'Department of Computer Science, University of Toronto'
author:
- Dai Tri Man Lê
- 'Stephen A. Cook'
bibliography:
- 'wphp.bib'
title: Formalizing Randomized Matching Algorithms
---

Introduction
============

There is a substantial literature on theories such as ${\textit{PV}}$, $S^1_2$, ${\textit{VPV}}$, $V^1$ which capture polynomial time reasoning [@Coo75; @Bus86; @Kra95; @CN10].  These theories prove the existence of polynomial time functions, and in many cases they can prove properties of these functions that assert the correctness of the algorithms computing these functions.  But in general these theories cannot prove the existence of probabilistic polynomial time relations such at those in ${\mathsf{ZPP}},{\mathsf{RP}}, {\mathsf{BPP}}$ because defining the relevant probabilities involves defining cardinalities of exponentially large sets.  Of course stronger theories, those which can define ${\mathsf{\#P}}$ or ${\mathsf{PSPACE}}$ functions can treat these probabilities, but such theories are too powerful to capture the spirit of feasible reasoning. 

Note that we cannot hope to find theories that exactly capture probabilistic complexity classes such as ${\mathsf{ZPP}},{\mathsf{RP}},{\mathsf{BPP}}$ because these are ‘semantic’ classes which we suppose are not recursively enumerable (cf. [ @Tha02]).  Nevertheless there has been significant progress toward developing tools in weak theories that might be used to describe some of the algorithms in these classes. 

Paris, Wilkie and Woods [@PWW88] and Pudlák [@Pud91] observed that we can simulate *approximate counting* in bounded arithmetic by applying variants of the weak pigeonhole principle.  It seems unlikely that any of these variants can be proven in the theories for polynomial time, but they can be proven in Buss’s theory $S_ {2}$ for the polynomial hierarchy.  The first connection between the weak pigeonhole principle and randomized algorithms was noticed by Wilkie (cf. [ @Kra95]), who showed that randomized polytime functions witness $\Sigma_{1}^{b}$-consequences of $S^{1}_{2}+{\mathsf{sWPHP}}({\textit{PV}})$ (i.e., $\Sigma_{1}^ {B}$-consequences of $V^{1}+{\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$ in our two-sorted framework), where ${\mathsf{sWPHP}}({\textit{PV}})$ denotes the surjective weak pigeonhole principle for all ${\textit{PV}}$ functions (i.e. polytime functions). 

Building on these early results, Jeřábek [@Jer04] showed that we can “compare” the sizes of two bounded ${\mathsf{P}/\mathsf{poly}}$ definable sets within ${\textit{VPV}}$ by constructing a surjective mapping from one set to another.  Using this method, Jeřábek developed tools for describing algorithms in ${\mathsf{ZPP}}$ and ${\mathsf{RP}}$. He also showed in [@Jer04; @Jer05] that the theory ${\textit{VPV}}+{\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$ is powerful enough to formalize proofs of very sophisticated derandomization results, e.g. the Nisan-Wigderson theorem [@NW94] and the Impagliazzo-Wigderson theorem [@IW97]. ( Note that Jeřábek actually used the single-sorted theory ${\textit{PV}}_{1}+{\mathsf{sWPHP}}({\textit{PV}})$, but these two theories are isomorphic.) 

In [@Jer07], Jeřábek developed an even more systematic approach by showing that for any bounded ${\mathsf{P}/\mathsf{poly}}$ definable set, there exists a suitable pair of surjective “counting functions” which can approximate the cardinality of the set up to a polynomially small error.  From this and other results he argued convincingly that ${\textit{VPV}}+{\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$ is the “right” theory for reasoning about probabilistic polynomial time algorithms.  However so far no one has used his framework for feasible reasoning about specific interesting randomized algorithms in classes such as ${\mathsf{RP}}$ and ${\mathsf{RNC}}^{2}$.

In the present paper we analyze (in ${\textit{VPV}}$) two such algorithms using Jeřábek’s framework.  The first one is the ${\mathsf{RNC}}^{2}$ algorithm for determining whether a bipartite graph has a perfect matching, based on the Schwartz-Zippel Lemma [@Sch80; @Zip89] for polynomial identity testing applied to the Edmonds polynomial [@Edm67] associated with the graph.  The second algorithm, due to Mulmuley, Vazirani and Vazirani [@MVV87], is in the function class associated with ${\mathsf{RNC}}^2$, and uses the Isolating Lemma to find such a perfect matching when it exists.  Proving correctness of these algorithms involves proving that the probability of error is bounded above by $1/2$. We formulate this assertion in a way suggested by Jeřábek’s framework (see Definition \[def:prob\]).  This involves defining polynomial time functions from ${\{0,1\}}^n$ onto ${\{0,1\}}\times \Phi(n)$, where $\Phi(n)$ is the set of random bit strings of length $n$ which cause an error in the computation.  We then show that ${\textit{VPV}}$ proves that the function is a surjection. 

Our proofs are carried out in the theory ${\textit{VPV}}$ for polynomial time reasoning, without the surjective weak pigeonhole principle ${\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$. Jeřábek used the ${\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$ principle to prove theorems justifying the above definition of error probability, but we do not need it to apply his definition. 

Many proofs concerning determinants are based on the *Lagrange expansion* (also known as the Leibniz formula) $${\mathsf{Det}}(A) = \sum_{\sigma\in S_{n}} \mathsf{sgn}(\sigma) \prod_{i=1}^{n} A(i,\sigma(i))$$ where the sum is over exponentially many terms.  Since our proofs in ${\textit{VPV}}$ can only use polynomial time concepts, we cannot formalize such proofs, and must use other techniques.  In the same vein, the standard proof of the Schwartz-Zippel Lemma assumes that a multivariate polynomial given by an arithmetic circuit can be expanded to a sum of monomials.  But this sum in general has exponentially many terms so again we cannot directly formalize this proof in ${\textit{VPV}}$.

Preliminaries
=============

Basic bounded arithmetic {#s:basicBA}
------------------------

The theory ${\textit{VPV}}$ for polynomial time reasoning used here is a two-sorted theory described by Cook and Nguyen [@CN10].  The two-sorted language has variables $x,y,z,\ldots$ ranging over $\mathbb{N}$ and variables $X,Y,Z,\ldots$ ranging over finite subsets of $\mathbb{N}$, interpreted as bit strings.  Two sorted vocabulary $\mathcal{L}_{A}^{2}$ includes the usual symbols $0,1,+,
\cdot,=,\le$ for arithmetic over $\mathbb{N}$, the length function $|X|$ for strings, the set membership relation $\in$, and string equality $=_{2}$ (subscript 2 is usually omitted).  We will use the notation $X(t)$ for $t\in X$, and think of $X(t)$ as the $t^{\text{th}}$ bit in the string $X$.

The number terms in the base language $\mathcal{L}_{A}^{2}$ are built from the constants $0,1$, variables $x,y,z,
\ldots$ and length terms $|X|$ using $+$ and $\cdot$. The only string terms are string variables, but when we extend $\mathcal{L}_{A}^{2}$ by adding string-valued functions, other string terms will be built as usual.  The atomic formulas are $t=u$, $X=Y$, $t\le u$, $t\in X$ for any number terms $u,t$ and string variables $X,Y$. Formulas are built from atomic formulas using $\wedge,\vee,\neg$ and $\exists x$, $\exists X$, $\forall x$, $\forall X$. Bounded number quantifiers are defined as usual, and bounded string quantifier $\exists X\le t, \varphi$ stands for $\exists X (|X|\le t\, \wedge \varphi)$ and $\forall X\le t, \varphi$ stands for $\forall X (|X|\le t \rightarrow \varphi)$, where $X$ does not appear in term $t$.

$\Sigma_{0}^{B}$ is the class of all $\mathcal{L}_{A}^{2}$-formulas with no string quantifiers and only bounded number quantifiers.  $\Sigma_{1}^{B}$-formulas are those of the form $\exists \vec{X}< \vec{t}\,\varphi$, where $\varphi\in \Sigma_{0}^{B}$ and the prefix of the bounded quantifiers might be empty.  These classes are extended to $\Sigma_{i}^{B}$ (and $\Pi_{i}^{B}$) for all $i\ge 0$, in the usual way. 

Two-sorted complexity classes contain relations $R(\vec{x},\vec{X})$, where $\vec{x}$ are number arguments and $\vec{X}$ are string arguments.  In defining complexity classes using machines or circuits, the number arguments are represented in unary notation and the string arguments are represented in binary.  The string arguments are the main inputs, and the number arguments are auxiliary inputs that can be used to index the bits of strings. 

In the two sorted setting, we can define ${\mathsf{AC}}^{0}$ to be the class of relations $R(\vec{x},\vec{X})$ such that some alternating Turing machine accepts $R$ in time ${\mathcal{O}}(\log n)$ with a constant number of alternations, where $n$ is the sum of all the numbers in $\vec{x}$ and the total length of all the string arguments in $\vec{X}$. Then from the descriptive complexity characterization of ${\mathsf{AC}}^{0}$, it can be shown that a relation $R(\vec{x},\vec{X})$ is in ${\mathsf{AC}}^{0}$ iff it is represented by some $\Sigma_
{0}^{B}$-formula $\varphi(\vec{x},\vec{X})$.

Given a class of relations $C$, we associate a class $\mathit{FC}$ of string-valued functions $F
(\vec{x},\vec{X})$ and number functions $f(\vec{x},\vec{X})$ with $C$ as follows.  We require that these functions to be $p$-bounded, i.e., the length of the outputs of $F$ and $f$ is bounded by a polynomial in $x$ and $|X|$. Then we define $\mathit{FC}$ to consist of all $p$-bounded number functions whose graphs are in $C$ and all $p$-bounded string functions whose bit graphs are in $C$. 

We write $\Sigma_{i}^{B}(\mathcal{L})$ to denote the class of $\Sigma_{i}^{B}$-formulas which may have function and predicate symbols from $\mathcal{L}\cup \mathcal{L}_{A}^{2}$. A string function is $\Sigma_{0}^{B}(\mathcal{L})$-definable if it is $p$-bounded and its bit graph is represented by a $\Sigma_{0}^{B}(\mathcal{L})$-formula.  Similarly, a number function is $\Sigma_
{0}^{B}$-definable from $\mathcal{L}$ if it is $p$-bounded and its graph is represented by a $
\Sigma_{0}^{B}(\mathcal{L})$-formula. 

The theory $V^{0}$ for ${\mathsf{AC}}^{0}$ is the basis to develop theories for small complexity classes within ${\mathsf{P}}$ in [@CN10].  The theory $V^{0}$ consists of the vocabulary $\mathcal{L}_{A}^{2}$ and axiomatized by the sets of *2-BASIC* axioms as given in [Figure \[fig:2basic\]]{}, which express basic properties of symbols in $\mathcal{L}_{A}^{2}$, together with the *comprehension* axiom schema $$\begin{aligned}
&\Sigma_{0}^{B}(\mathcal{L}_{A}^{2})\textit{-COMP: } &\exists X\le y\, \forall z<y \bigl(X(z) 
\leftrightarrow \varphi(z)\bigr),\end{aligned}$$ where $\varphi \in \Sigma_{0}^{B}(\mathcal{L}_{A}^{2})$ and $X$ does not occur free in $\varphi$.

------------------------------------------------------------------------

$$\begin{aligned}
&\textbf{B1. } x+1 \not= 0                       \\
&\textbf{B2. } x+1=y+1 \rightarrow x= y          \\
&\textbf{B3. } x+0=x                         \\
&\textbf{B4. } x+(y+1)=(x+y)+1                   \\
&\textbf{B5. } x\cdot 0 =0                       \\
&\textbf{B6. } x\cdot (y+1)  = (x\cdot y)+x          \\
&\textbf{B7. }( x\le y \wedge y\le x)\rightarrow x = y\\\end{aligned}$$

$$\begin{aligned}
&\textbf{B8. } x\le x + y\\
&\textbf{B9. } 0\le x\\
&\textbf{B10. } x\le y \vee y\le x\\
&\textbf{B11. } x\le y \leftrightarrow x < y +1\\
&\textbf{B12. } x\not= 0 \rightarrow \exists y\le x \left(y+1=x\right)\\
&\textbf{L1. } X(y)\rightarrow y<|X|             \\
&\textbf{L2. } y+1 = |X| \rightarrow X(y)\\\end{aligned}$$

$\textbf{SE. } \bigl(|X|=|Y| \wedge \forall i <|X|\left(X(i)=Y(i)\right)\bigr) \rightarrow X = Y$

------------------------------------------------------------------------

In [@CN10 Chapter 5], it was shown that $V^{0}$ is finitely axiomatizable and a $p$-bounded function is in $\mathsf{FAC}^{0}$ iff it is provably total in $V^{0}$. A universally-axiomatized conservative extension $\overline{V^{0}}$ of $V^{0}$ was also obtained by introducing function symbols and their defining axioms for all $\mathsf{FAC}^{0}$ functions. 

In [@CN10 Chapter 9], Cook and Nguyen showed how to associate a theory ${\mathit{VC}}$ to each complexity class $C\subseteq {\mathsf{P}}$, where ${\mathit{VC}}$ extends $V^{0}$ with an additional axiom asserting the existence of a solution to a complete problem for $C$.  General techniques are also presented for defining a universally-axiomatized conservative extension $\overline{{\mathit{VC}}}$ of ${\mathit{VC}}$ which has function symbols and defining axioms for every function in $\mathit{FC}$, and ${\mathit{VC}}$ admits induction on open formulas in this enriched vocabulary.  It follows from Herbrand’s Theorem that the provably-total functions in $\overline{{\mathit{VC}}}$ (and hence in ${\mathit{VC}}$) are precisely the functions in $\mathit{FC}$. Using this framework, Cook and Nguyen defined explicitly theories for various complexity classes within ${\mathsf{P}}$.

Since we need some basic linear algebra in this paper, we are interested in the two-sorted theory $
{\mathit{V\#L}}$ and its universal conservative extension $\overline{{\mathit{V\#L}}}$ from [@CF10].  Recall that $\#
{\mathsf{L}}$ is usually defined as the class of functions $f$ such that for some nondeterministic logspace Turing machine $M$, $f(x)$ is the number of accepting computations of $M$ on input $x$. Since counting the number of accepting paths of nondeterministic logspace is ${\mathsf{AC}}^{0}$-equivalent to matrix powering, ${\mathit{V\#L}}$ was defined to be the extension of the base theory $V^{0}$ with an additional axiom stating the existence of powers $A^{k}$ for every matrix $A$ over $\mathbb{Z}$. The closure of $\#{\mathsf{L}}$ under ${\mathsf{AC}}^0$-reductions is called ${\mathsf{DET}}$. It turns out that computing the determinant of integer matrices is complete for ${\mathsf{DET}}$ under ${\mathsf{AC}}^{0}$-reductions.  In fact Berkowitz’s algorithm can be used to reduce the determinant to matrix powering.  Moreover, $\overline{{\mathit{V\#L}}}$ proves that the function ${\mathsf{Det}}$, which computes the determinant of integer matrices based on Berkowitz’s algorithm, is in the language of $\overline{{\mathit{V\#L}}}$. Unfortunately it is an open question whether the theory $\overline{{\mathit{V\#L}}}$ also proves the *cofactor expansion formula* and other basic properties of determinants.  However from results in [@SC04] it follows that $\overline{{\mathit{V\#L}}}$ proves that the usual properties of determinants follow from the Cayley-Hamilton Theorem (which states that a matrix satisfies its characteristic polynomial). 

In this paper, we are particularly interested in the theory ${\textit{VPV}}$ for polytime reasoning [@CN10 Chapter 8.2] since we will use it to formalize all of our theorems.  The universal theory ${\textit{VPV}}$ is based on Cook’s single-sorted theory ${\textit{PV}}$ [@Coo75], which was historically the first theory designed to capture polytime reasoning.  A nice property of ${\textit{PV}}$ (and ${\textit{VPV}}$) is that their universal theorems translate into families of propositional tautologies with polynomial size proofs in any extended Frege proof system. 

The vocabulary ${{\mathcal{L}}_{{\mathsf{FP}}}}$ of ${\textit{VPV}}$ extends that of $
\overline{V^{0}}$ with additional symbols introduced based on Cobham’s machine independent characterization of ${\mathsf{FP}}$ [@Cob65].  Let $Z^{<y}$ denote the first $y$ bits of $Z$. Formally the vocabulary ${{\mathcal{L}}_{{\mathsf{FP}}}}$ of ${\textit{VPV}}$ is the smallest set satisfying

(1) ${{\mathcal{L}}_{{\mathsf{FP}}}}$ contains the vocabulary of $\overline{V^{0}}$

(2) For any two function $G(\vec{x},\vec{X})$, $H(y,\vec{x},\vec{X},\vec{Z})$ over ${{\mathcal{L}}_{{\mathsf{FP}}}}$ and a ${\mathcal{L}}_{A}^{2}$-term $t = t(y,\vec{x},\vec{X})$, if $F$ is defined by *limited recursion* from $G$, $H$ and $t$, i.e., $$\begin{aligned}
    F(0,\vec{x},\vec{X}) &= G(\vec{x},\vec{X}),\\
    F(y+1,\vec{x},\vec{X}) &= H(y,\vec{x},\vec{X},F(y,\vec{x},\vec{X}))^{<t(y,\vec{x},\vec{X})},\end{aligned}$$ then $F\in {\mathcal{L}}_{{\mathsf{FP}}}$.

We will often abuse the notation by letting ${{\mathcal{L}}_{{\mathsf{FP}}}}$ denote the set of function symbols in ${{\mathcal{L}}_{{\mathsf{FP}}}}$.

The theory ${\textit{VPV}}$ can then be defined to be the theory over ${{\mathcal{L}}_{{\mathsf{FP}}}}$ whose axioms are those of $
\overline{V^{0}}$ together with defining axioms for every function symbols in ${{\mathcal{L}}_{{\mathsf{FP}}}}$. ${\textit{VPV}}$ proves the scheme $\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})$-*COMP* and the following schemes $$\begin{aligned}
\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})\textit{-IND: }  &&\bigl(\varphi(0)\wedge \forall x \bigl(\varphi(x)\rightarrow \varphi
(x+1)\bigr)\bigr)\rightarrow \forall x \varphi(x)\\
\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})\textit{-MIN: }  &&\varphi(y)\rightarrow \exists x \bigl(\varphi(x)\wedge \neg 
\exists z<x \varphi(z)\bigr) \\
\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})\textit{-MAX:}
&&\varphi(0)\rightarrow \exists x \le y \bigl(\varphi(x)\wedge \neg \exists z\le y \bigl(z>x \wedge 
\varphi(z)\bigr)\bigr)\end{aligned}$$ where $\varphi$ is any $\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})$-formula.  It follows from Herbrand’s Theorem that the provably-total functions in ${\textit{VPV}}$ are precisely the functions in ${{\mathcal{L}}_{{\mathsf{FP}}}}$.

Observe that ${\textit{VPV}}$ extends $\overline{{\mathit{V\#L}}}$ since matrix powering can easily be carried out in polytime, and thus all theorems of $\overline{{\mathit{V\#L}}}$ from [@CF10; @SC04] are also theorems of ${\textit{VPV}}$. From results in [@SC04] (see page 44 of [@Jer05] for a correction) it follows that ${\textit{VPV}}$ proves the Cayley-Hamilton Theorem, and hence the cofactor expansion formula and other usual properties of determinants of integer matrices. 

In our introduction, we mentioned $V^{1}$, the two sorted version of Buss’s $S^{1}_{2}$ theory [@Bus86].  The theory $V^{1}$ is also associated with polytime reasoning in the sense that the provably total functions of $V^{1}$ are ${\mathsf{FP}}$ functions, and $V^{1}$ is $\Sigma_{1}^{B}$-conservative over ${\textit{VPV}}$. However, there is evidence showing that $V^{1}$ is stronger than ${\textit{VPV}}$. For example, the theory $V^{1}$ proves the $\Sigma_{1}^{B}$*-IND*, $\Sigma_{1}^{B}$*-MIN* and $
\Sigma_{1}^{B}$*-MAX* schemes while ${\textit{VPV}}$ cannot prove these $\Sigma_{1}^{B}$ schemes, assuming the polynomial hierarchy does not collapse [@KPT91].  In this paper we do not use $V^{1}$ to formalize our theorems, since the weaker theory ${\textit{VPV}}$ suffices for all our needs. 

Notation
--------

If $\varphi$ is a function of $n$ variables, then let $\varphi(\alpha_{1},\ldots,\alpha_{n-1},\bullet)$ denote the function of one variable resulting from $\varphi$ by fixing the first $n-1$ arguments to $\alpha_{1},\ldots,\alpha_{n-1}$. We write $\psi: \Delta {\twoheadrightarrow}\Phi$ to denote that $\psi$ is a surjection from $\Delta$ *onto* $\Phi$.

We use $[X,Y)$ to denote ${\{Z\in \mathbb{Z}{\,|\,}X\le Z<Y\}}$, i.e., the interval of integers between $X$ and $Y-1$, where strings code integers using signed binary notation.  We also use the standard notation $[n]$ to denote the set ${\{1,\ldots,n\}}$.

Given a square matrix $M$, we write $M[i{\,|\,}j]$ to denote the $(i,j)$-*minor* of $M$, i.e., the square matrix formed by removing the $i$th row and $j$th column from $M$.

We write $\vec{x}$ to denote number sequence ${\left\langle    x_{1},\ldots,x_{k} \right\rangle }$ and write $\vec{X}$ to denote string sequence ${\left\langle    X_{1},\ldots,X_{k} \right\rangle }$.  We write $\vec{x}_{k\times k}$ and $\vec{X}_{k\times k}
$ to denote that $\vec{x}$ and $\vec{X}$ have $k^{2}$ elements and are treated as two-dimensional arrays ${\left\langle    x_{i,j}{\,|\,}1\le i,j\le k \right\rangle }$ and ${\left\langle    X_{i,j}{\,|\,}1\le i,j\le k \right\rangle }$ respectively, where the elements of these two-dimensional arrays are listed by rows.  Note that $\vec{x}_{k \times k}$ and $\vec{X}_{k\times k}$ can be simply encoded as integer matrices, and thus we will use matrix notation freely on them. 

We write the notation “($T {\vdash}$)” in front of the statement of a theorem to indicate that the statement is formulated and proved within the theory $T$.

The weak pigeonhole principle
-----------------------------

The *surjective weak pigeonhole principle* for a function $F$, denoted by ${\mathsf{sWPHP}}(F)$, states that $F$ cannot map $[0,nA)$ onto $[0,(n+1)A)$. Thus, the surjective weak pigeonhole principle for the class of ${\textit{VPV}}$ functions, denoted by ${\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$, is the schema $${\bigl\{{\mathsf{sWPHP}}(F){\,|\,}F\in {{\mathcal{L}}_{{\mathsf{FP}}}}\bigr\}}.$$

Note that this principle is believed to be weaker than the usual surjective “strong” pigeonhole principle stating that we cannot map $[0,A)$ onto $[0,A+1)$. For example, ${\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$ can be proven in the theory $V^{3}$ (the two-sorted version of Buss’s theory $S^{3}_{2}$) for ${\mathsf{FP}}^{\Sigma_{3}^{{\mathsf{P}}}}$ reasoning (cf. [ @Tha02]), but it is not known if the usual surjective pigeonhole principle for ${\textit{VPV}}$ functions can be proven within the theory $\bigcup_{i\ge 1} V^{i}$ for the polynomial hierarchy (the two-sorted version of Buss’s theory $S_{2}:= \bigcup_{i\ge 1} S_{2}^{i}$ in [@Bus86]). 

Jeřábek’s framework for probabilistic reasoning {#s:jerabek}
-----------------------------------------------

In this section, we give a brief and simplified overview of Jeřábek’s framework [@Jer04; @Jer05; @Jer07] for probabilistic reasoning within ${\textit{VPV}}+{\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$. For more complete definitions and results, the reader is referred to Jeřábek’s work. 

Let $F(R)$ be a ${\textit{VPV}}$ 0-1 valued function (which may have other arguments).  We think of $F$ as defining a relation on binary numbers $R$. Let $\Phi(n) = {\{R<2^{n}{\,|\,}F(R)=1\}}.$ Observe that bounding the probability ${\mathsf{Pr}}_{R<2^{n}}\bigl[F(R)=1\bigr]$ from above by the ratio $s/t$ is the same as showing that $t\cdot |\Phi(n)| \le s\cdot 2^{n}$. More generally, many probability inequalities can be restated as inequalities between cardinalities of sets.  This is problematic since even for the case of polytime definable sets, it follows from Toda’s theorem [@Tod91] that we cannot express their cardinalities directly using bounded formulas (assuming that the polynomial hierarchy does not collapse).  Hence we need an alternative method to compare the sizes of definable sets without exact counting. 

The method proposed by Jeřábek in [@Jer04; @Jer05; @Jer07] is based on the following simple observation: if $\Gamma(n)$ and $\Phi(n)$ are definable sets and there is a function $F$ mapping $\Gamma(n)$ onto $\Phi(n)$, then the cardinality of $\Phi(n)$ is at most the cardinality of $\Gamma(n)$. Thus instead of counting the sets $\Gamma(n)$ and $\Phi(n)$ directly, we can compare the sizes of $\Gamma(n)$ and $\Phi(n)$ by showing the existence of a surjection $F$, which in many cases can be easily carried out within weak theories of bounded arithmetic.  In this paper we will restrict our discussion to the case when the sets are bounded polytime definable sets and the surjections are polytime functions, all of which can be defined within ${\textit{VPV}}$, since this is sufficient for our results. 

The remaining challenge is then to formally verify that the definition of cardinality comparison through the use of surjections is a meaningful and well-behaved definition.  The basic properties of surjections like “any set can be mapped onto itself” and “surjectivity is preserved through function compositions” roughly correspond to the usual reflexivity and transitivity of cardinality ordering, i.e., $|\Phi| \le |\Phi|$ and $|\Phi| \le |\Gamma| \le |\Lambda| \rightarrow |\Phi|\le |\Lambda|$ for all bounded definable sets $\Phi$, $\Gamma$ and $\Lambda$. However more sophisticated properties, e.g., dichotomy $|\Phi| \le |\Gamma| \vee |\Gamma| \le |\Phi|$ or “uniqueness” of cardinality, turn out to be much harder to show. 

As a result, Jeřábek proposed in [@Jer07] a systematic and sophisticated framework to justify his definition of size comparison.  He observed that estimating the size of a ${\mathsf{P}/\mathsf{poly}}$ definable set $\Phi\subseteq [0,2^{n})$ within an error $2^{n}/{\mathsf{poly}}(n)$ is the same as estimating $
{\mathsf{Pr}}_{X \in [0,2^{n})} [X \in \Phi]$ within an error $1/{\mathsf{poly}}(n)$, which can be solved by drawing $
{\mathsf{poly}}(n)$ independent random samples $X \in [0,2^{n})$ and check if $X\in \Phi$. This gives us a polytime random sampling algorithm for approximating the size of $\Phi$. Since a counting argument [@Jer04] can be formalized within ${\textit{VPV}}+ {\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$ to show the existence of suitable average-case hard functions for constructing Nisan-Wigderson generators, this random sampling algorithm can be derandomized to show the existence of an *approximate cardinality* $S$ of $\Phi$ for any given error $E = 2^{n}/{\mathsf{poly}}(n)$ in the following sense.  The theory ${\textit{VPV}}+ {\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$ proves the existence of $S,y$ and a pair of ${\mathsf{P}/\mathsf{poly}}$ “counting functions” $(F,G)$ $$\begin{aligned}
F:\;&[0,y)\times \bigl(\Phi\uplus [0,E)\bigr){\twoheadrightarrow}[0,y\cdot S)\\
G:\;&\bigl[0,y\cdot (S+E)\bigr){\twoheadrightarrow}[0,y)\times \Phi\end{aligned}$$ Intuitively the pair $(F,G)$ witnesses that $S-E \le |\Phi| \le S+E$. This allows him to show many properties, expected from cardinality comparison, that are satisfied by his method within ${\textit{VPV}}+ {\mathsf{sWPHP}}({{\mathcal{L}}_{{\mathsf{FP}}}})$ (see Lemmas 2.10 and 2.11 in [@Jer07]).  It is worth noting that proving the uniqueness of cardinality within some error seems to be the best we can do within bounded arithmetic, where exact counting is not available.\
For the present paper, the following definition is all we need to know about Jeřábek’s framework. 

\[def:prob\] Let $\Phi(n) = \{R< 2^{n}{\,|\,}F(R)=1\}$, where $F(R)$ is a [*VPV*]{} function (which may have other arguments) and let $s,t$ be ${\textit{VPV}}$ terms.  Then $${\mathsf{Pr}}_{R<2^{n}}\bigl[R\in \Phi(n)]\precsim s/t$$ means that either $\Phi(n)$ is empty, or there exists a ${\textit{VPV}}$ function $G(n,\bullet)$ mapping the set $[s]\times 2^{n}$ onto the set $[t]\times \Phi(n)$.

Since we are not concerned with justifying the above definition, our theorems can be formalized in ${\textit{VPV}}$ without ${\mathsf{sWPHP}}$.

Edmonds’ Theorem
================

Let $G$ be a bipartite graph with two disjoint sets of vertices $U={\{u_1,\ldots,u_n\}}$ and $V={\{v_1,\ldots,v_n\}}$. We use a pair $(i,j)$ to encode the edge ${\{u_{i},v_{j}\}}$ of $G$. Thus the edge relation of the graph $G$ can be encoded by a boolean matrix $E_{n \times n}$, where we define $(i,j)\in E$, i.e. $E(i,j)=1$, iff ${\{u_{i},v_{j}\}}$ is an edge of $G$.

Each perfect matching in $G$ can be encoded by an $n\times n$ permutation matrix $M$ satisfying $M(i,j)\rightarrow E(i,j)$ for all $i,j\in [n]$. Recall that a *permutation matrix* is a square boolean matrix that has exactly one entry of value $1$ in each row and each column and $0$’s elsewhere. 

Let $A_{n\times n}$ be the matrix obtained from $G$ by letting $A_{i,j}$ be an indeterminate $X_{i,j}$ for all $(i,j)\in E$, and let $A_{i,j}=0$ for all $(i,j)\not\in E$. The matrix of indeterminates $A(\vec{X})$ is called the *Edmonds matrix* of $G$, and ${\mathsf{Det}}(A(\vec{X}))$ is called the *Edmonds polynomial* of $G$. In general this polynomial has exponentially many monomials, so for the purpose of proving its properties in ${\textit{VPV}}$ we consider ${\mathsf{Det}}(A(\vec{X}))$ to be a function which takes as input an integer matrix $\vec{W}_{n\times n}$ and returns an integer ${\mathsf{Det}}(A(\vec{W}))$. Thus ${\mathsf{Det}}(A(\vec{X})) \equiv 0$ means that this function is identically zero. 

The following theorem draws an important connection between determinants and matchings.  The standard proof uses the *Lagrange expansion* which has exponentially many terms, and hence cannot be formalized in ${\textit{VPV}}$. However we will give an alternative proof which can be so formalized. 

\[theo:Edmonds\] (${\textit{VPV}}{\vdash}$) Let ${\mathsf{Det}}(A(\vec{X}))$ be the Edmonds polynomial of the bipartite graph $G$. Then $G$ has a perfect matching iff ${\mathsf{Det}}(A(\vec{X})) \not\equiv 0$ (i.e. iff there exists an integer matrix $\vec{W}$ such that ${\mathsf{Det}}(A(\vec{W})) \not= 0$). 

For the direction ($\Rightarrow$) we need the following lemma. 

\[lem:permatrix\] (${\textit{VPV}}{\vdash}$) ${\mathsf{Det}}(M) \in {\{-1,1\}}$ for any permutation matrix $M$.

We will construct a sequence of matrices $$N_{n}, N_{n-1}, \ldots, N_{1},$$ where $N_{n}=M$, $N_1 = (1)$, and we construct $N_{i-1}$ from $N_{i}$ by choosing $j_{i}$ satisfying $N(i,j_{i})
=1$ and letting $N_{i-1} = N_{i}[i{\,|\,}j_{i}]$.

From the way the matrices $N_{i}$ are constructed, we can easily show by $\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})$ induction on $\ell=n,\ldots,1$ that the matrices $N_{\ell}$ are permutation matrices.  Finally, using the cofactor expansion formula, we prove by $\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})$ induction on $\ell=1,\ldots,n$ that ${\mathsf{Det}}(N_{\ell})\in {\{-1,1\}}$.

From the lemma we see that if $M$ is the permutation matrix representing a perfect matching of $G$, then ${\textit{VPV}}$ proves ${\mathsf{Det}}(A(M)) = {\mathsf{Det}}(M) \in \{1,-1\}$, so ${\mathsf{Det}}(A(\vec{X}))$ is not identically 0. 

For the direction ($\Leftarrow$) it suffices to describe a polytime function $F$ that takes as input an integer matrix $B_{n\times n} = A(\vec{W}) $, where $A(\vec{X})$ is the Edmonds matrix of a bipartite graph $G$ and $\vec{W}_{n\times n}$ is an integer value assignment, and reason in ${\textit{VPV}}$ that if ${\mathsf{Det}}(B)\not= 0$, then $F$ outputs a perfect matching of $G$.

Assume ${\mathsf{Det}}(B)\not=0$. Note that finding a perfect matching of $G$ is the same as extracting a nonzero diagonal, i.e., a sequence of nonzero entries $B(1,\sigma(1)),B(2,\sigma(2)),\ldots,B(n,\sigma(n))$, where $\sigma$ is a permutation of the set $[n]$. For this purpose, we construct a sequence of matrices $$B_{n},B_{n-1},\ldots, B_{1},$$ as follows.  We let $B_{n}=B$. For $i=n,\ldots,2$, we let $B_{i-1} = B_{i}[i{\,|\,}j_{i}]$ and the index $j_{i}$ is chosen using the following method.  Suppose we already know $B_{i}$ satisfying ${\mathsf{Det}}(B_{i})\not=0$. By the cofactor expansion along the last row of $B_{i}$, $${\mathsf{Det}}(B_{i}) = \sum_{j=1}^iB_i(i,j)(-1)^{i+j} {\mathsf{Det}}(B_{i}[i{\,|\,}j]).$$ Thus, since ${\mathsf{Det}}(B_{i})\neq 0$, at least one of the terms in the sum on the right-hand side is nonzero.  Thus, we can choose the least index $j_{i}$ such that $B_i(i,j_{i})\cdot {\mathsf{Det}}(B_{i}[i{\,|\,}j_{i}])\neq 0$.

To extract the perfect matching, we let $Q$ be an $n\times n$ matrix, where $Q(i,j) = j$. Then we construct a sequence of matrices $$Q_{n},Q_{n-1},\ldots, Q_{1},$$ where $Q_{n}=Q$ and $Q_{i-1}=Q_{i}[i{\,|\,}j_{i}]$, i.e., we delete from $Q_{i}$ exactly the row and column we deleted from $B_{i}$. We define a permutation $\sigma$ by letting $\sigma(i)=Q_{i}(i,j_{i})$. Then $\sigma(i)$ is the column number in $B$ which corresponds to column $j_i$ in $B_i$, and the set of edges $${\bigl\{(i,\sigma(i)){\,|\,}1\le i \le n\bigr\}}$$ is our desired perfect matching. 

Schwartz-Zippel Lemma \[sec:SZ\]
================================

The Schwartz-Zippel Lemma [@Sch80; @Zip89] is one of the most fundamental tools in the design of randomized algorithms.  The lemma provides us a ${\mathsf{coRP}}$ algorithm for the *polynomial identity testing problem* (<span style="font-variant:small-caps;">Pit</span>): given an arithmetic circuit computing a multivariate polynomial $P(\vec{X})$ over a field $\mathbb{F}$, we want to determine if $P(\vec{X})$ is identically zero.  The <span style="font-variant:small-caps;">Pit</span> problem is important since many problems, e.g., primality testing [@AB03], perfect matching [@MVV87], and software run-time testing [@WB97], can be reduced to <span style="font-variant:small-caps;">Pit</span>.  Moreover, many fundamental results in complexity theory like ${\mathsf{IP}}={\mathsf{PSPACE}}$ [@Sha92] and the PCP theorem [@Aro98; @AS98] make heavy use of <span style="font-variant:small-caps;">Pit</span> in their proofs.  The Schwartz-Zippel lemma can be stated as follows. 

Let $P(X_1,\ldots,X_n)$ be a non-zero polynomial of degree $D \ge 0$ over a field (or integral domain) $\mathbb{F}$. Let $S$ be a finite subset of $\mathbb{F}$ and let $\vec{R}$ denote the sequence ${\left\langle    R_1,\ldots, R_n \right\rangle }$.  Then $${\mathsf{Pr}}_{\vec{R}\in S^{n}}\bigl[P(\vec{R})=0\bigr]\leq \frac{D}{|S|}.$$

Using this lemma, we have the following ${\mathsf{coRP}}$ algorithm for the <span style="font-variant:small-caps;">Pit</span> problem when $\mathbb{F} = \mathbb{Z}$. Given a polynomial $$P(X_1,\ldots,X_n)$$ of degree at most $D$, we choose a sequence $\vec{R}\in [0,2D)^{n}$ at random.  If $P$ is given implicitly as a circuit, the degree of $P$ might be exponential, and thus the value of $P(\vec{R})$ might require exponentially many bits to encode.  In this case we use the method of Ibarra and Moran [@IM83] and let $Y$ be the result of evaluating $P(\vec{R})$ using arithmetic modulo a random integer from the interval $[1,D^k]$ for some fixed $k$. If $Y=0$, then we report that $P\equiv 0$. Otherwise, we report that $P\not\equiv 0$. (Note that if $P$ has small degree, then we can evaluate $P(\vec{R})$ directly.) 

Unfortunately the Schwartz-Zippel Lemma seems hard to prove in bounded arithmetic.  The main challenge is that the degree of $P$ can be exponentially large.  Even in the special case when $P$ is given as the symbolic determinant of a matrix of indeterminates and hence the degree of $P$ is small, the polynomial $P$ still has up to $n!$ terms.  Thus, we will focus on a much weaker version of the Schwartz-Zippel Lemma that involves only Edmonds’ polynomials since this will suffice for us to establish the correctness of a ${\mathsf{FRNC}}^{2}$ algorithm for deciding if a bipartite graph has a perfect matching. 

Edmonds’ polynomials for complete bipartite graphs
--------------------------------------------------

In this section we will start with the simpler case when every entry of an Edmonds matrix is a variable, since it clearly demonstrates our techniques.  This case corresponds to the Schwartz-Zippel Lemma for Edmonds’ polynomials of complete bipartite graphs. 

Let $A$ be the full $n \times n$ Edmonds’ matrix $A$, where $A_{i,j} = X_{i,j}$ for all $1\le i,j \le n$. We consider the case that $S$ is the interval of integers $S = [0,s)$ for $s \in \mathbb{N}$, so $|S|=s$. Then ${\mathsf{Det}}(A(\vec{X}))$ is a nonzero polynomial of degree exactly $n$, and we want to show that $$\begin{aligned}
{\mathsf{Pr}}_{\vec{r}\in S^{n^{2}}}\bigl[{\mathsf{Det}}(A(\vec{r}))=0\bigr] \precsim \frac{n}{s}.  \end{aligned}$$ Let $${\mathcal{Z}}(n,s):={\bigl\{\vec{r}\in S^{n^2}{\,|\,}{\mathsf{Det}}(A(\vec{r}))=0\bigr\}},$$ i.e., the set of zeros of the Edmonds polynomial ${\mathsf{Det}}(A(\vec{X}))$. Then by [Definition \[def:prob\]]{}, it suffices to exhibit a ${\textit{VPV}}$ function mapping $[n]\times S^{n^{2}}$ onto $S\times {\mathcal{Z}}(n,s)$. For this it suffices to give a ${\textit{VPV}}$ function mapping $[n]\times S^{n^{2}-1}$ onto ${\mathcal{Z}} (n,s)$. We will define a ${\textit{VPV}}$ function $$F(n,s,\bullet):[n]\times S^{n^2-1} {\twoheadrightarrow}{\mathcal{Z}}(n,s),$$ so $F(n,s,\bullet)$ takes as input a pair $(i,\vec{r})$, where $i\in [n]$ and $\vec{r}\in S^{n^2-1}$ is a sequence of $n^{2}-1$ elements. 

Let $B$ be an $n\times n$ matrix with elements from $S$. For $i\in [n]$ let $B_i$ denote the leading principal submatrix of $B$ that consists of the $i\times i$ upper-left part of $B$. In other words, $B_{n} = B$, and $B_{i-1}:=B_{i}[i{\,|\,}i]$ for $i=n,\ldots,2$. The following fact follows easily from the least number principle $\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})\textit{-MIN}$.

\[f:detB\](${\textit{VPV}}{\vdash}$) If ${\mathsf{Det}}(B)=0$, then there is $i\in [n]$ such that ${\mathsf{Det}}(B_j)=0$ for all $i\le j\le n$, and either $i=1$ or $i>1$ and ${\mathsf{Det}}(B_{i-1})\ne 0$.

We claim that given ${\mathsf{Det}}(B)=0$ and given $i$ as in the fact, the element $B(i,i)$ is uniquely determined by the other elements in $B$. Thus if $i=1$ then $B(i,i)=0$, and if $i>1$ then by the cofactor expansion of ${\mathsf{Det}}(B_i)$ along row $i$, $$\label{e:fix}
     0 = {\mathsf{Det}}(B_i) = B_i(i,i) \cdot {\mathsf{Det}}(B_{i-1}) + {\mathsf{Det}}(B'_i)$$ where $B'_i$ is obtained from $B_i$ by setting $B'(i,i)=0$. This equation uniquely determines $B_i(i,i)$ because ${\mathsf{Det}}(B_{i-1})\ne 0$.

The output of $F(n,s,(i,\vec{r}))$ is defined as follows.  Let $B$ be the $n\times n$ matrix determined by the $n^2-1$ elements in $\vec{r}$ by inserting the symbol $\ast$ (for unknown) in the position for $B(i,i)$. Try to use the method above to determine the value of $\ast= B_i(i,i)$, assuming that $\ast$ is chosen so that ${\mathsf{Det}}(B)=0$. This method could fail because ${\mathsf{Det}}(B_{i-1}) =0$. In this case, or if the solution to the equation (\[e:fix\]) gives a value for $B_i(i,i)$ which is not in $S$, output the default “dummy” zero sequence $\vec{0}_{n\times n}$. Otherwise let $C$ be $B$ with $\ast$ replaced by the obtained value of $B_i(i,i)$. If ${\mathsf{Det}}(C) = 0$ then output $C$, otherwise output the dummy zero sequence. 

\[theo:Knn\](${\textit{VPV}}{\vdash}$) Let $A(\vec{X})$ be the Edmonds matrix of a complete bipartite graph $K_{n,n}$. Let $S$ denote the set $[0,s)$. Then the function $F(n,s,\bullet)$ defined above is a polytime surjection that maps $[n]\times S^{n^2-1}$ onto ${\mathcal{Z}}(n,s)$.

It is easy to see that $F(n,s,\bullet)$ is polytime (in fact it belongs to the complexity class ${\mathsf{DET}}$).  To see that $F$ is surjective, let $C$ be an arbitrary matrix in ${\mathcal{Z}} (n,s)$, so ${\mathsf{Det}}(C)=0$. Let $i\in [n]$ be determined by Fact \[f:detB\] when $B=C$. Let $\vec{r}$ be the sequence of $n^2-1$ elements consisting of the rows of $C$ with $C(i,i)$ deleted.  Then the algorithm for computing $F(n,s,(i,\vec{r}))$ correctly computes the missing element $C(i,i)$ and outputs $C$. 

Edmonds’ polynomials for general bipartite graphs
-------------------------------------------------

For general bipartite graphs, an entry of an Edmonds matrix $A$ might be $0$, so we cannot simply use leading principal submatrices in our construction of the surjection $F$. However given a sequence $\vec{W}_{n\times n}$ making ${\mathsf{Det}}(A(\vec{W}))\not=0$, it follows from [Theorem \[theo:Edmonds\]]{} that we can find a perfect matching $M$ in polytime.  Thus, the nonzero diagonal corresponding to the perfect matching $M$ will play the role of the main diagonal in our construction.  The rest of the proof will proceed similarly.  Thus, we have the following theorem. 

\[theo:SZEd\] (${\textit{VPV}}{\vdash}$) There is a ${\textit{VPV}}$ function $H(n,s,A,\vec{W},\bullet)$ where $A_{n\times n}$ is the Edmonds matrix for an arbitrary bipartite graph and $\vec{W}$ is a sequence of $n^2$ (binary) integers, such that if ${\mathsf{Det}}(A(\vec{W}))\ne 0$ then $H(n,s,A,\vec{W},\bullet)$ maps $[n]\times S^{n^2-1}$ onto ${\{\vec{r}\in S^{n^2}{\,|\,}{\mathsf{Det}}(A(\vec{r}))=0\}}$, where $S=[0,s)$.

In other words, it follows from [Definition \[def:prob\]]{} that the function $H(n,s,A,\vec{W},\bullet)$ in the theorem witnesses that $${\mathsf{Pr}}_{\vec{r}\in S^{n^{2}}}\bigl[{\mathsf{Det}}(A(\vec{r}))=0\bigr] \precsim \frac{n}{s}.$$

Assume ${\mathsf{Det}}(A(\vec{W}))\ne 0$. Then the polytime function described in the proof of [Theorem \[theo:Edmonds\]]{} produces an $n\times n$ permutation matrix $M$ such that for all $i,j\in [n]$, if $M(i,j)=1$ then the element $A(i,j)$ in the Edmonds matrix $A$ is not zero.  We apply the algorithm in the proof of Theorem \[theo:Knn\], except that the sequence of principal submatrices of $B$ used in Fact \[f:detB\] is replaced by the sequence $B_n,B_{n-1},\ldots,B_1$ determined by $M$ as follows.  We let $B_n = B$, and for $i=n,\ldots,2$ we let $B_{i-1} = B_i[i{\,|\,}j_i]$, where the indices $j_i$ are chosen the same way as in the proof of [Theorem \[theo:Edmonds\]]{} when constructing the perfect matching $M$.

We note that the mapping $H(n,s,A,\bullet)$ in this case may not be in ${\mathsf{DET}}$ since the construction of $M$ depends on the sequential polytime algorithm from [Theorem \[theo:Edmonds\]]{} for extracting a perfect matching. 

Formalizing the ${\mathsf{RNC}}^{2}$ algorithm for the bipartite perfect matching decision problem {#s:formBi}
--------------------------------------------------------------------------------------------------

An instance of the *bipartite perfect matching decision* problem is a bipartite graph $G$ encoded by a matrix $E_{n\times n}$, and we are to decide if $G$ has a perfect matching.  Here is an ${\mathsf{RDET}}$ algorithm for the problem.  The algorithm is essentially due to Lovász [@Lov79].  From $E$, construct the Edmonds matrix $A(\vec{X})$ for $G$ and choose a random sequence $\vec{r}_{n\times n}\in [2n]^{n^{2}}$. If ${\mathsf{Det}}(A(\vec{r}))\ne 0$ then we report that $G$ has a perfect matching.  Otherwise, we report $G$ does not have a perfect matching. 

We claim that ${\textit{VPV}}$ proves correctness of this algorithm.  The correctness assertion states that if $G$ has a perfect matching then the algorithm reports NO with probability at most 1/2, and otherwise it certainly reports NO. [ Theorem \[theo:Edmonds\]]{} shows that ${\textit{VPV}}$ proves the latter.  Conversely, if $G$ has a perfect matching given by a permutation matrix $M$ then the function $H(n,2n,A,M,\bullet)$ of [Theorem \[theo:SZEd\]]{} witnesses that the probability of ${\mathsf{Det}}(A(\vec{r}))=0$ is at most $1/2$, according to Definition \[def:prob\], where $A$ is the Edmonds matrix for $G$. Hence ${\textit{VPV}}$ proves the correctness of this case too. 

Since ${\mathsf{RDET}}\subseteq {\mathsf{FRNC}}^{2}$, this algorithm (which solves a decision problem) is also an ${\mathsf{RNC}}^{2}$ algorithm. 

Formalizing the Hungarian algorithm
===================================

The Hungarian algorithm is a combinatorial optimization algorithm which solves the *maximum-weight bipartite matching* problem in polytime and anticipated the later development of the powerful *primal-dual method*.  The algorithm was developed by Kuhn [@Kuh55], who gave the name “Hungarian method” since it was based on the earlier work of two Hungarian mathematicians: D. Kőnig and J. Egerváry.  Munkres later reviewed the algorithm and showed that it is indeed polytime [@Mun57].  Although the Hungarian algorithm is interesting by itself, we formalize the algorithm since we need it in the ${\textit{VPV}}$ proof of the Isolating Lemma for perfect matchings in [Section \[sec:iso\]]{}. 

The Hungarian algorithm finds a maximum-weight matching for any weighted bipartite graph.  The algorithm and its correctness proof are simpler if we make the two following changes.  First, since edges with negative weights can never be in a maximum-weight matching, and thus can be safely deleted, we can assume that every edge has *nonnegative* weight.  Second, by assigning zero weight to every edge not present, we only need to consider weighted *complete* bipartite graphs. 

Let $G=(X \uplus Y, E)$ be a complete bipartite graph, where $X={\{x_{i}{\,|\,}1\le i\le n\}}$ and $Y={\{y_{i} {\,|\,}1\le i\le n\}}$, and let $\vec{w}$ be an integer weight assignment to the edges of $G$, where $w_{i,j}\ge 0$ is the weight of the edge ${\{x_{i},y_{j}\}}\in E$.

A pair of integer sequences $\vec{u}={\left\langle    u_{i} \right\rangle }_{i=1}^{n}$ and $\vec{v}={\left\langle    v_{i} \right\rangle }_{i=1}^{n}$ is called a *weight cover* if $$\begin{aligned}
\forall i,j\in [n],\, w_{i,j}\le u_{i} + v_{j}.  \label{eq:cover}\end{aligned}$$ The *cost* of a cover is ${\mathsf{cost}}(\vec{u},\vec{v}) {:=}\sum_{i=1}^{n} (u_{i} + v_{i})$. We also define $w(M){:=}\sum_{(i,j)\in M} w_{i,j}$. The Hungarian algorithm is based on the following important observation. 

\[lem:hung\] (${\textit{VPV}}{\vdash}$) For any matching $M$ and weight cover $(\vec{u},\vec{v})$, we have $w(M) \le {\mathsf{cost}}(\vec{u},\vec{v}).$

Since the edges in a matching $M$ are disjoint, summing the constraints $w_{i,j}\le 
u_{i} + v_{j}$ over all edges of $M$ yields $w(M)  \le \sum_{(i,j)\in M} (u_{i}+v_{j})$. Since no edge has negative weight, we have $u_{i}+v_{j}\ge 0$ for all $i,j\in [n]$. Thus, $$w(M)  \le \sum_{(i,j)\in M} (u_{i}+v_{j}) \le  {\mathsf{cost}}(\vec{u},\vec{v})$$ for every matching $M$ and every weight cover $(\vec{u},\vec{v})$.

Given a weight cover $(\vec{u},\vec{v})$, the *equality subgraph* $H_{\vec{u},\vec{v}}$ is the subgraph of $G$ whose vertices are $X\uplus Y$ and whose edges are precisely those ${\{x_{i},y_{j}\}}\in E$ satisfying $w_{i,j} = u_{i}+v_{j} $. 

\[theo:hung\] (${\textit{VPV}}{\vdash}$) Let $H =H_{\vec{u},\vec{v}}$ be the equality subgraph, and let $M$ be a maximum cardinality matching of $H$. Then the following three statements are equivalent

1.   $w(M) = {\mathsf{cost}}(\vec{u},\vec{v})$.

2.   $M$ is a maximum-weight matching of $G$ and $(\vec{u},\vec{v})$ is a minimum-weight cover of $G$.

3.   $M$ is a perfect matching of the equality subgraph $H$.

*(cf. [ Appendix \[app:hung\]]{} for the full proof of this theorem.)* 

Below we give a simplified version of the Hungarian algorithm which runs in polynomial time when the edge weights are small (i.e. presented in unary notation).  The correctness of the algorithm easily follows from [Theorem \[theo:hung\]]{}. 

We start with an arbitrary weight cover $(\vec{u},\vec{v})$ with small weights: e.g. let $$u_{i} = \max{\{w_{i,j}{\,|\,}1\le j \le n\}}$$ and $v_{i}=0$ for all $i\in[n]$. If the equality subgraph $H_{\vec{u},\vec{v}}$ has a perfect matching $M$, we report $M$ as a maximum-weight matching of $G$. Otherwise, change the weight cover $(\vec{u},\vec{v})$ as follows.  Since the maximum matching $M$ is not a perfect matching of $H$, the Hall’s condition fails for $H$. Thus it is not hard (cf. [ Corollary \[cor:hall\]]{} from [Appendix \[app:hall\]]{}) to construct in polytime a subset $S \subseteq X$ satisfying $|N(S)|<|S|$, where $N(S)$ denotes the neighborhood of $S$. Hence we can calculate the quantity $$\delta = \min{\bigl\{u_{i}+v_{j} - w_{i,j}{\,|\,}x_{i}\in S \;\wedge\; y_{j}\not\in N(S) \bigr\}},$$ and decrease $u_{i}$ by $\delta$ for all $x_{i}\in S$ and increase $v_{j}$ by $\delta$ for all $y_{j}\in 
N(S)$ without violating the weight cover property .  This strictly decreases the sum $ \sum_{i=1}^{n} (u_{i} + v_{i})$. Thus this process can only repeat at most as many time as the initial cost of the cover $(\vec{u},\vec{v})$. Assuming that all edge weights are small (i.e. presented in unary), the algorithm terminates in polynomial time.  Finally we get an equality subgraph $H_{\vec{u},\vec{v}}$ containing a perfect matching $M$, which by [Theorem \[theo:hung\]]{} is also a maximum-weight matching of $G$.\

When formalizing the Isolating Lemma for bipartite matchings, we need a ${\textit{VPV}}$ function ${\mathsf{Mwpm}}$ that takes as inputs an edge relation $E_{n\times n}$ of a bipartite graph $G$ and a nonnegative weight assignment $\vec{w}$ to the edges in $E$, and outputs a minimum-weight perfect matching if such a matching exists, or outputs ${\varnothing}$ to indicate that no perfect matching exists.  Recall that the Hungarian algorithm returns a maximum-weight matching, and not a *minimum*-weight *perfect* matching.  However we can use the Hungarian algorithm to compute ${\mathsf{Mwpm}}(n,E,\vec{w})$ as follows. 

\[alg:mwp\] $\;$

Let $c = n\cdot\max{\bigl\{w_{i,j} {\,|\,}(i,j)\in E\bigr\}} + 1$ Construct the sequence $\vec{w}'$ as follows $$w'_{i,j} = \begin{cases}
c-w_{i,j}   & \text{if } (i,j)\in E\\
0   & \text{otherwise.} 
\end{cases}$$ Run the Hungarian algorithm on the complete bipartite graph $K_{n,n}$ with weight assignment $\vec{w}'$ to get a maximum-weight matching $M$. return the empty matching ${\varnothing}$ return $M$

Note that since we assign zero weights to the edges not present and very large weights to other edges, the Hungarian algorithm will always prefer the edges that are present in the original bipartite graph.  More formally for any perfect matching $M$ and non-perfect matching $N$ we have $$\begin{aligned}
w'(M) 
&\ge nc - n\cdot \max {\bigl\{w_{i,j} {\,|\,}(i,j)\in E\bigr\}}\\
&= (n-1)c + \left(c - n\cdot \max {\bigl\{w_{i,j} {\,|\,}(i,j)\in E\bigr\}}\right)\\
&= (n-1)c + 1\\
&> (n-1)c\\
&\ge w'(N) \end{aligned}$$ The last inequality follows from the fact that $w'_{i,j} \le c$ for all $(i,j)\in N$. Thus, if the Hungarian algorithm returns a matching $M$ with at least one edge not in $E$, then the original graph cannot have a perfect matching.  Also from the way the weight assignment $\vec{w}'$ was defined, every maximum-weight perfect matching of $K_{n,n}$ with weight assignment $\vec{w}'$ is a minimum-weight matching of the original bipartite graph. 

It is straightforward to check that the above argument can be formalized in [*VPV*]{}, so [*VPV*]{} proves the correctness of Algorithm \[alg:mwp\] for computing the function ${\mathsf{Mwpm}}$.

${\mathsf{FRNC}}^{2}$ algorithm for finding a bipartite perfect matching
========================================================================

Below we recall the elegant ${\mathsf{FRNC}}^{2}$ (or more precisely ${\mathsf{RDET}}$) algorithm due to Mulmuley, Vazirani and Vazirani [@MVV87] for finding a bipartite perfect matching.  Although the original algorithm works for general undirected graphs, we will only focus on bipartite graphs in this paper. 

Let $G$ be a bipartite graph with two disjoint sets of vertices $U={\{u_1,\ldots,u_n\}}$ and $V={\{v_1,\ldots,v_n\}}$. We first consider the *minimum-weight bipartite perfect matching problem*, where each edge $ (i,j)\in E$ is assigned an integer weight $w_{i,j}\ge 0$, and we want to a find a minimum-weight perfect matching of $G$. It turns out there is a ${\mathsf{DET}}$ algorithm for this problem under two assumptions: the weights must be polynomial in $n$, and the minimum-weight perfect matching must be *unique*.  We let $A(\vec{X})$ be an Edmonds matrix of the bipartite graph.  Replace $X_{i,j}$ with $W_{i,j}=2^{w_{i,j}}$ (this is where we need the weights to be small).  We then compute ${\mathsf{Det}}(A(\vec{W}))$ using Berkowitz’s ${\mathsf{FNC}}^2$ algorithm.  Assume that there exists exactly one (unknown) minimum-weight perfect matching $M$. We will show in [Theorem \[theo:Bin2\]]{} that $w(M)$ is exactly the position of the least significant $1$-bit, i.e., the number of trailing zeros, in the binary expansion of ${\mathsf{Det}}(A(\vec{W}))$. Once having $w(M)$, we can test if an edge $(i,j)\in E$ belongs to the unique minimum-weight perfect matching $M$ as follows.  Let $w'$ be the position of the least significant $1$-bit of ${\mathsf{Det}}(A[i{\,|\,}j](\vec{W}))$. We will show in [Theorem \[theo:Bin3\]]{} that the edge $(i,j)$ is in the perfect matching if and only if $w'$ is precisely $w(M) - w_{i,j}$. Thus, we can test all edges in parallel.  Note that up to this point, everything can be done in ${\mathsf{DET}}\subseteq {\mathsf{FNC}}^2$ since the most expensive operation is the ${\mathsf{Det}}$ function, which is complete for ${\mathsf{DET}}$.

What we have so far is that, assuming that the minimum-weight perfect matching exists and is unique, there is a ${\mathsf{DET}}$ algorithm for finding this minimum-weight perfect matching.  But how do we guarantee that if a minimum-weight perfect matching exists, then it is unique?  It turns out that we can assign every edge $ (u_i,v_j)\in E$ a random weight $w_{i,j}\in [2m]$, where $m = |E|$, and use the Isolating Lemma [@MVV87] to ensure that the graph has a *unique* minimum-weight perfect matching with probability at least $1/2$.

The ${\mathsf{RDET}}\subseteq {\mathsf{FRNC}}^{2}$ algorithm for finding a perfect matching is now complete: assign random weights to the edges, and run the ${\mathsf{DET}}$ algorithm for the unique minimum-weight perfect matching problem.  If a perfect matching exists, with probability at least $1/2$, this algorithm returns a perfect matching. 

Isolating a perfect matching \[sec:iso\]
----------------------------------------

We will recall the Isolating Lemma [@MVV87], the key ingredient of Mulmuley-Vazirani-Vazirani ${\mathsf{FRNC}}^2$ algorithm for finding a perfect matching.  Let $X$ be a set with $m$ elements ${\{a_{1},\ldots,a_{m}\}}$ and let ${\mathcal{F}}$ be a family of subsets of $X$. We assign a weight $w_{i}$ to each element $a_{i}\in X$, and define the weight of a set $Y \in {\mathcal{F}}$ to be $w(Y){:=}\sum_{a_{i}\in Y}w_{i}$. Let *minimum-weight* be the minimum of the weights of all the sets in ${\mathcal{F}}$. Note that several sets of ${\mathcal{F}}$ might achieve minimum-weight.  However, if minimum-weight is achieved by a unique $Y\in {\mathcal{F}}$, then we say that the weight assignment $\vec{w}={\left\langle    w_{i} \right\rangle }_{i=1}^{m}$ is *isolating* for ${\mathcal{F}}$. (Every weight assignment is isolating if $|{\mathcal{F}}|\le 1$.)

Let ${\mathcal{F}}$ be a family of subsets of an $n$-element set $X={\{a_{1},\ldots,a_{m}\}}$. Let $\vec{w}={\left\langle    w_{i} \right\rangle }_{i=1}^{m}$ be a random weight assignment to the elements in $X$. Then $${\mathsf{Pr}}_{\vec{w}\in [k]^{m}} [\text{$\vec{w}$ is not isolating for ${\mathcal{F}}$}] \le \frac{m}{k}.$$

To formalize the Isolating Lemma in ${\textit{VPV}}$ it seems natural to present the family ${\mathcal{F}}$ by a polytime algorithm.  This is difficult to do in general (see Remark \[r:gen\] below), so we will formalize a special case which suffices to formalize the ${\mathsf{FRNC}}^{2}$ algorithm for finding a bipartite perfect matching.  Thus we are given a bipartite graph $G$, and the family ${\mathcal{F}}$ is the set of perfect matchings of $G$. We want to show that if we assign random weights to the edges, then the probability that this weight assignment does not isolate a perfect matching is small.  Note that although the family ${\mathcal{F}}$ here might be exponentially large, ${\mathcal{F}}$ is polytime definable, since recognizing a perfect matching is easy. 

\[theo:iso\] (${\textit{VPV}}{\vdash}$) Let ${\mathcal{F}}$ be the family of perfect matchings of a bipartite graph $G$ with edges $E={\{e_1,\ldots,e_m\}}$. Let $\vec{w}$ be a random weight assignment to the edges in $E$. Then $${\mathsf{Pr}}_{\vec{w} \in [k]^{m}} \bigl[\text{$\vec{w}$ is not isolating 
for ${\mathcal{F}}$}\bigr] \precsim m/k.$$

For brevity, we will call a weight assignment $\vec{w}$ “bad” if $\vec{w}$ is not isolating for ${\mathcal{F}}$. Let $$\Phi:={\bigl\{\vec{w}\in [k]^m{\,|\,}\vec{w} \text{ is bad for }{\mathcal{F}}\bigr\}}.$$ Then to prove [Theorem \[theo:iso\]]{}, it suffices to construct a ${\textit{VPV}}$ function mapping $[m]\times [k]^ {m-1}$ onto $\Phi$. Note that the upper bound $m/k$ is independent of the size $n$ of the two vertex sets.  The set $\Phi$ is polytime definable since $\vec{w} \in \Phi$ iff $$\begin{aligned}
\exists i,j \in [n]\left(\begin{array}{c}
\text{$E(i,j)$ and  $M(i,j)$ and  $\neg M'(i,j)$ and $M,M'$}\\
\text{encode two perfect matchings with the same weight}
\end{array}\right),\end{aligned}$$ where $M$ denotes the output produced by applying the ${\mathsf{Mwpm}}$ function (Algorithm \[alg:mwp\]) on $G$, and $M'$ denotes the output produced by applying ${\mathsf{Mwpm}}$ on the graph obtained from $G$ by deleting the edge $(i,j)$.

By [Definition \[def:prob\]]{} we may assume that $\Phi$ is nonempty, so there is an element $\delta \in \Phi$. (We will use $\delta$ as a “dummy” element.)  It suffices for us to construct explicitly a ${\textit{VPV}}$ function $\varphi$ mapping $[m]\times [k]^{m-1}$ onto $ \Phi$. For each $i\in [k]$ we interpret the set ${\{i\}}\times [k]^{m-1}$ as the set of all possible weight assignments to the $m-1$ edges $E\setminus{\{e_i\}}$. Our function $\varphi$ will map each set ${\{i\}}\times [k]^ {m-1}$ onto the set of those bad weight assignments $\vec{w}$ such that the graph $G$ contains two *distinct* minimum-weight perfect matchings $M$ and $M'$ with $e_i\in M\setminus M'$.

The function $\varphi$ takes as input a sequence $${\left\langle    i,w_1, \ldots,w_{i-1},w_{i+1},\ldots, w_m \right\rangle }$$ from $[m]\times [k]^{m-1}$ and does the following.  Use the function ${\mathsf{Mwpm}}$ (defined by [Algorithm \[alg:mwp\]]{}) to find a minimum-weight perfect matching $M'$ of $G$ with the edge $e_i$ deleted.  Use ${\mathsf{Mwpm}}$ to find a minimum-weight perfect matching $M_{1}$ of the subgraph $G\setminus{\{u_{j},v_{\ell}\}}$, where $u_{j}$ and $v_{\ell}$ are the two endpoints of $e_i$. If both perfect matchings $M'$ and $M_{1}$ exist and satisfy $w(M')-w(M_{1})\in [k]$, then $\varphi$ outputs the sequence $$\label{e:badOut}
{\left\langle    w_1, \ldots,w_{i-1},w(M')-w(M_{1}),w_{i+1},\ldots, w_m \right\rangle }.$$ Otherwise $\varphi$ outputs the dummy element $\delta$ of $\Phi$.

Note that if both $M'$ and $M_{1}$ exist, then (\[e:badOut\]) is a bad weight assignment, since $M'$ and $M = M_{1} \cup \{e_i\}$ are distinct minimum-weight perfect matchings of $G$ under this assignment. 

To show that $\varphi$ is surjective, consider an arbitrary bad weight assignment $\vec{w}={\left\langle    w_i \right\rangle }_{i=1}^{m}\in \Phi$. Since $\vec{w}$ is bad, there are two distinct minimum-weight perfect matchings $M$ and $M'$ and some edge $e_i\in M\setminus M'$. Thus from how $ \varphi$ was defined, $${\left\langle    i,w_1,\ldots,w_{i-1},w_{i+1},\ldots,w_m \right\rangle }\in [m]\times [k]^{m-1}$$ is an element that gets mapped to the bad weight assignment $\vec{w}$.

\[r:gen\] The above proof uses the fact that there is a polytime algorithm for finding a minimum-weight perfect matching (when one exists) in an edge-weighted bipartite graph.  This suggests limitations on formalizing a more general version of Theorem \[theo:iso\] in ${\textit{VPV}}$. For example, if ${\mathcal{F}}$ is the set of Hamiltonian cycles in a complete graph, then finding a minimum weight member of ${\mathcal{F}}$ is ${\mathsf{NP}}$ hard. 

Extracting the unique minimum-weight perfect matching
-----------------------------------------------------

Let $G$ be a bipartite graph and assume that $G$ has a perfect matching.  Then in [Section \[sec:iso\]]{} we formalized a version of the Isolating Lemma, which with high probability gives us a weight assignment $\vec{w}$ for which $G$ has a unique minimum-weight perfect matching.  This is the first step of the Mulmuley-Vazirani-Vazirani algorithm.  Now we proceed with the second step, where we need to output this minimum-weight perfect matching using a ${\mathsf{DET}}$ function. 

Let $B$ be the matrix we get by substituting $W_{i,j} = 2^{w_{i,j}}$ for each nonzero entry $(i,j)$ of the Edmonds matrix $A$ of $G$. We want to show that if $M$ is the unique minimum weight perfect matching of $G$ with respect to $\vec{w}$, then the weight $w(M)$ is exactly the position of the least significant $1$-bit in the binary expansion of ${\mathsf{Det}}(B)$. The usual proof of this fact is not hard, but it uses properties of the Lagrange expansion for the determinant, which has exponentially many terms and hence cannot be formalized in ${\textit{VPV}}$. Our proof avoids using the Lagrange expansion, and utilizes properties of the cofactor expansion instead. 

(${\textit{VPV}}{\vdash}$)\[lem:Bin1\] There is a ${\textit{VPV}}$ function that takes as inputs an $n\times n$ Edmonds’ matrix $A$ and a weight sequence $$\vec{W}={\left\langle    W_{i,j} = 2^{w_{i,j}}{\,|\,}1\le i,j\le n \right\rangle }.$$ And if $B=A(\vec{W})$ satisfies ${\mathsf{Det}}(B)\not=0$ and $p$ is the position of the least significant $1$-bit of ${\mathsf{Det}}(B)$, then the ${\textit{VPV}}$ function outputs a perfect matching $M$ of weight at most $p$.

It is worth noting that the lemma holds regardless of whether or not the bipartite graph corresponding to $A$ and weight assignment $\vec{W}$ has a unique minimum-weight perfect matching. 

The proof of [Lemma \[lem:Bin1\]]{} is very similar to that of [Theorem \[theo:Edmonds\]]{}.  Recall that in [Theorem \[theo:Edmonds\]]{}, given a matrix $B$ satisfying ${\mathsf{Det}}(B)\not=0$, we want to extract a nonzero diagonal of $B$. In this lemma, we are given the position $p$ of the least significant $1$-bit of ${\mathsf{Det}}(B)$, and we want to get a nonzero diagonal of $B$ whose product has the least significant $1$-bit at position at most $p$. For this, we can use the same method of extracting the nonzero diagonal from [Theorem \[theo:Edmonds\]]{} with the following modification.  When choosing a term of the Lagrange expansion on the recursive step, we will also need to make sure the chosen term produces a nonzero sub-diagonal of $B$ that will not contribute too much weight to the diagonal we are trying to extract.  This ensures that the least significant $1$-bit of the weight of the chosen diagonal is at most $p$.

For the rest of this section, we define ${\mathsf{numz}}(Y)$ to be the position of the least significant 1-bit of the binary string $Y$. Thus if ${\mathsf{numz}}(Y) = q$ then $Y = \pm 2^qZ$ for some positive odd integer $Z$.

We construct a sequence of matrices $$B_{n},B_{n-1},\ldots, B_{1}$$ where $B_{n}=B$ and $B_{i-1} = B_{i}[i {\,|\,}j_{i}]$ for $i=n\ldots, 2$ where the index $j_{i}$ is chosen as follows.  Define $$T_{i} := \left(\prod_{\ell = i+1}^{n} B_{\ell}(\ell,j_{\ell})\right){\mathsf{Det}}(B_{i}).$$ Assume we are given $j_{n},\ldots,j_{i+1}$ such that ${\mathsf{numz}}(T_{i})\le p$. We want to choose $j_{i}$ such that ${\mathsf{numz}}(T_{i-1})\le p$, where by definition $$T_{i-1}= \left(\prod_{\ell = i}^{n} B_{\ell}(\ell,j_{\ell})\right){\mathsf{Det}}(B_{i-1}) = 
\left(\prod_{\ell = i}^{n} B_{\ell}(\ell,j_{\ell})\right){\mathsf{Det}}( B_{i}[i {\,|\,}j_{i}]).$$ This can be done as follows.  From the cofactor expansion of ${\mathsf{Det}}(B_i)$, we have $$\begin{aligned}
T_{i}
 = {\sum_{j=1}^{i} (-1)^{i+j}  \left(\prod_{\ell = i+1}^{n} B_{\ell}(\ell,j_{\ell})\right) B_{i}(i,j) {\mathsf{Det}}(B_{i}[ i {\,|\,}j]).}\end{aligned}$$ Since ${\mathsf{numz}}(T_{i})\le p$, at least one of the terms in the sum must have its least significant $1$-bit at position at most $p$. Thus, we can choose $j_i$ such that $${\mathsf{numz}}\left( \left(\prod_{\ell = i+1}^{n} B_{\ell}(\ell,j_{\ell})\right)
B_{i}(i,j_{i}) {\mathsf{Det}}(B_{i}[ i {\,|\,}j_{i}])\right) = {\mathsf{numz}}(T_{i-1})$$ is minimized, which guarantees that ${\mathsf{numz}}(T_{i-1}) \le p$.

Since by assumption ${\mathsf{numz}}(T_n) = {\mathsf{numz}}({\mathsf{Det}}(B_n)) = p$, ${\textit{VPV}}$ proves by $\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})$ induction on $i=n,\ldots,1$ that $${\mathsf{numz}}(T_{i})\le p.$$ If we define $j_1 =1$, then when $i=1$ we have $$T_{1} =\left(\prod_{\ell = 2}^{n} B_{\ell}(\ell,j_{\ell})\right){\mathsf{Det}}(B_{1}) = \prod_{\ell = 1}^{n} B_{\ell}(\ell,j_{\ell}).$$ Thus it follows that ${\mathsf{numz}}(T_{1}) = {\mathsf{numz}}\left(\prod_{\ell = 1}^{n} B_{\ell}(\ell,j_{\ell})\right)\le p$.

Similarly to the proof of [Theorem \[theo:Edmonds\]]{}, we can extract a perfect matching with weight at most $p$ by letting $Q$ be a matrix, where $Q(i,j) = j$ for all $i,j\in [n]$. Then we compute another sequence of matrices $$Q_{n},Q_{n-1},\ldots, Q_{1},$$ where $Q_{n}=Q$ and $Q_{i-1}=Q_{i}[i{\,|\,}j_{i}]$, i.e., we delete from $Q_{i}$ exactly the row and column we deleted from $B_{i}$.

To prove that $M={\{(\ell,Q_{\ell}(\ell,j_{\ell})){\,|\,}1\le \ell\le n\}}$ is a perfect matching, we note that whenever a pair $(i,k)$ is added to the matching $M$, we delete the row $i$ and column $j_{i}
$, where $j_{i}$ is the index satisfying $Q_{i}(i,j_{i}) = k$. So we can never match any other vertex to $k$ again. 

It remains to show that $w(M)\le p$. Since $$\prod_{\ell = 1}^{n} B_{\ell}(\ell,j_{\ell})=2^{w(M)},$$ the binary expansion of $\prod_{\ell = 1}^{n} B_{\ell}(\ell,j_{\ell})$ has a unique one at position $w(M)$ and zeros elsewhere.  Thus it follows from how the matching $M$ was constructed that $w(M)\le p$.

The next two theorems complete our description and justification of our ${\mathsf{RDET}}$ algorithm for finding a perfect matching.  For these theorems we are given a bipartite graph $G=(U\uplus V,E)$, where we have $U={\{u_1,\ldots,u_n\}}$ and $V={\{v_1,\ldots,v_n\}}$, and each edge $(i,j)\in E$ is assigned a weight $w_{i,j}$ such that $G$ has a *unique* minimum-weight perfect matching (see Theorem \[theo:iso\]).  Let $\vec{W}_{n\times n}$ be a sequence satisfying $W_{i,j} = 2^{w_{i,j}}$ for all $(i,j)\in E$. Let $A$ be the Edmonds matrix of $G$, and let $B=A(\vec{W})$. Let $M$ denote the unique minimum weight perfect matching of $G$.

(${\textit{VPV}}{\vdash}$) \[theo:Bin2\] The weight $p=w(M)$ is exactly ${\mathsf{numz}}({\mathsf{Det}}(B))$.

If in [Lemma \[lem:Bin1\]]{} we tried to extract an appropriate nonzero diagonal of $B$ using the determinant and minors of $B$ as our guide, then in the proof of this theorem we do the reverse.  From a minimum-weight perfect matching $M$ of $G$, we want to rebuild in polynomially many steps suitable minors of $B$ until we fully recover the determinant of $B$. We can then prove by $\Sigma_{0}^{B}({{\mathcal{L}}_{{\mathsf{FP}}}})$ induction that in every step of this process, each “partial determinant” of $B$ has the least significant 1-bit at position $p$. Note that the technique we used to prove this theorem does have some similarity to that of [Lemma \[lem:permatrix\]]{}, even though the proof of this theorem is more complicated. 

Let $Q$ be a matrix, where $Q(i,j) = j$ for all $i,j\in [n]$. For $1\le i\le n$ let $B_i$ be the result of deleting rows $i+1,\ldots,n$ and columns $M(i+1),\ldots,M(n)$ from $B$ and let $Q_i$ be $Q$ with the same rows and columns deleted.  We can construct these matrices inductively in the form of two matrix sequences $$\begin{aligned}
&B_{n},B_{n-1},\ldots, B_{1}        &&Q_{n},Q_{n-1},\ldots, Q_{1}\end{aligned}$$ where

-   we let $B_{n}=B$ and $Q_{n}=Q$, and

-   for $i=n,n-1,\ldots,2$, define $j_{i}$ to be the unique index satisfying $$M(i) = Q_{i}(i,j_{i}),$$ and then let $B_{i-1} = B_{i}[i{\,|\,}j_{i}]$ and $Q_{i-1} =Q_{i}[i{\,|\,}j_{i}]$.

Then (setting $j_1=1$) $$\label{e:Bident}
   B_i(i,j_i) = B(i,M(i)) = 2^{w_{i,M(i)}}, \ 1\le i \le n$$

${\mathsf{numz}}({\mathsf{Det}}(B_i)) = \sum_{\ell = 1}^i w_{\ell,M(\ell)}$ for all $i\in [n]$.

The theorem follows from this by setting $i=n$. We will prove the claim by induction on $i$. The base case $i=1$ follows from (\[e:Bident\]). 

For the induction step, it suffices to show $${\mathsf{numz}}({\mathsf{Det}}(B_{i+1})) = {\mathsf{numz}}({\mathsf{Det}}(B_i)) + w_{i+1,M(i+1)}$$

From the cofactor expansion formula we have $$\begin{aligned}
{\mathsf{Det}}(B_{i+1}) 
= \sum_{j=1}^{i+1}  (-1)^{(i+1)+j} B_{i+1}(i+1,j){\mathsf{Det}}(B_{i+1}[ i+1 {\,|\,}j])\end{aligned}$$ Since $B_{i+1}(i+1,j_{i+1}) = 2^{w_{i+1,M(i+1)}}$ by (\[e:Bident\]), and ${\mathsf{Det}}(B_{i+1}[ i+1 {\,|\,}j_{i+1}]) = {\mathsf{Det}}(B_i)$, it suffices to show that if $$R:=B_{i+1}(i+1,j_{i+1}){\mathsf{Det}}(B_{i+1}[ i+1 {\,|\,}j_{i+1}])$$ then $${\mathsf{numz}}(R) < {\mathsf{numz}}\bigl(B_{i+1}(i+1,j){\mathsf{Det}}(B_{i+1}[ i+1 {\,|\,}j])\bigr)$$ for all $j\not=j_{i+1}$.

Suppose for a contradiction that there is some $j'\not=j_{\ell}$ such that $${\mathsf{numz}}\bigl(B_{i+1}(i+1,j'){\mathsf{Det}}(B_{i+1}[ i+1 {\,|\,}j'])\bigr) \le {\mathsf{numz}}(R).$$ Then, we can extend the set of edges $${\bigl\{(n,M(n)),\ldots, (i+2,M(i+2)),(i+1,j')\bigr\}}$$ with $i$ edges extracted from $B_{i+1}[ i+1 {\,|\,}j']$ (using the method from [Lemma \[lem:Bin1\]]{}) to get a perfect matching of $G$ with weight at most $p$, which contradicts that $M$ is the unique minimum-weight perfect matching of $G$.

To extract the edges of $M$ in ${\mathsf{DET}}$, we need to decide if an edge $(i,j)$ belongs to the unique minimum-weight perfect matching $M$ without knowledge of other edges in $M$. The next theorem, whose proof follows directly from [Lemma \[lem:Bin1\]]{} and [Theorem \[theo:Bin2\]]{}, gives us that method. 

(${\textit{VPV}}{\vdash}$)\[theo:Bin3\] For every edge $(i,j)\in E$, we have $(i,j)\in M$ if and only if $$w (M)-w_{i,j}={\mathsf{numz}}\bigl({\mathsf{Det}}(B[i{\,|\,}j])\bigr).$$

($\Rightarrow$): Assume $(i,j)\in M$. Then the bipartite graph $G' = G\setminus{\{u_{i},v_{j}\}}$ must have a unique minimum-weight perfect matching of weight $w(M)-w_{i,j}$. Thus from [Theorem \[theo:Bin2\]]{}, $${\mathsf{numz}}\bigl({\mathsf{Det}}(B[i{\,|\,}j])\bigr)=w(M)-w_{i,j}.$$

($\Leftarrow$): We prove the contrapositive.  Assume $(i,j)\not\in M$. Suppose for a contradiction that $$w (M)-w_{i,j}={\mathsf{numz}}\bigl({\mathsf{Det}}(B[i{\,|\,}j])\bigr).$$ Then by [Lemma \[lem:Bin1\]]{} we can extract from the submatrix $B[i{\,|\,}j]$ a perfect matching $Q$ of the bipartite graph $G' = G\setminus{\{u_{i},v_{j}\}}$ with weight at most $w(M)-w_{i,j}$. But then $M' = Q\cup {\{(i,j)\}}$ is another perfect matching of $G$ with $w(M')\le w(M)$, a contradiction. 

Theorems \[theo:iso\], \[theo:Bin2\], and \[theo:Bin3\] complete the description and justification of our ${\mathsf{RDET}}$ algorithm for finding a perfect matching in a bipartite graph.  Since these are theorems of ${\textit{VPV}}$, it follows that ${\textit{VPV}}$ proves the correctness of the algorithm. 

Related bipartite matching problems
-----------------------------------

The correctness of the Mulmuley-Vazirani-Vazirani algorithm can easily be used to establish the correctness of ${\mathsf{RDET}}$ algorithms for related matching problems, for example, the maximum (cardinality) bipartite matching problem and the minimum-weight bipartite perfect matching problem, where the weights assigned to the edges are small.  We refer to [@MVV87] for more details on these reductions. 

Conclusion and Future Work
==========================

We have only considered randomized matching algorithms for [*bipartite*]{} graphs.  For general undirected graphs, we need Tutte’s matrix (cf. [ @MVV87]), a generalization of Edmonds’ matrix.  Since every Tutte matrix is a skew symmetric matrix where each variable appears exactly twice, we cannot directly apply our technique for Edmonds’ matrices, where each variable appears at most once.  However, by using the recursive definition of the Pfaffian instead of the cofactor expansion, we believe that it is also possible to generalize our results to general undirected graphs.  We also note that the Hungarian algorithm only works for weighted bipartite graphs.  To find a maximum-weight matching of a weighted undirected graph, we need to formalize Edmonds’ *blossom algorithm* (cf. [ @KV08]).  Once we have the correctness of the blossom algorithm, the proof of the Isolating Lemma for undirected graph perfect matchings will be the same as that of [Theorem \[theo:iso\]]{}.  We leave the detailed proofs for the general undirected graph case for future work. 

It is worth noticing that symbolic determinants of Edmonds’ matrices result in very special polynomials, whose structures can be used to define the ${\textit{VPV}}$ surjections witnessing the probability bound in the Schwartz-Zippel Lemma as demonstrated in this paper.  It remains an open problem whether we can prove the full version of the Schwartz-Zippel Lemma using Jeřábek’s method within the theory ${\textit{VPV}}$.

We have shown that the correctness proofs for several randomized algorithms can be formalized in the theory ${\textit{VPV}}$ for polynomial time reasoning.  But some of the algorithms involved are in the subclass ${\mathsf{DET}}$ of polynomial time, where ${\mathsf{DET}}$ is the closure of $\#L$ (and also of the integer determinant function ${\mathsf{Det}}$) under ${\mathsf{AC}}^0$ reductions.  As mentioned in Section \[s:basicBA\] the subtheory $\overline{{\mathit{V\#L}}}$ of ${\textit{VPV}}$ can define all functions in ${\mathsf{DET}}$, but it is open whether $\overline{{\mathit{V\#L}}}$ can prove properties of ${\mathsf{Det}}$ such as the expansion by minors.  However the theory $\overline{{\mathit{V\#L}}} + {\mathit{CH}}$ can prove such properties, where ${\mathit{CH}}$ is an axiom stating the Cayley-Hamilton Theorem.  Thus in the statements of Lemma \[lem:permatrix\] and Theorem \[theo:Knn\] we could have replaced $({\textit{VPV}}{\vdash})$ by $({\mathit{V\#L}}+ {\mathit{CH}}{\vdash})$. We could have done the same for Theorem \[theo:SZEd\] if we changed the argument $\vec{W}$ of the function $H$ to $M$, where $M$ is a permutation matrix encoding a perfect matching for the underlying bipartite graph.  This modified statement of the theorem still proves the interesting direction of the correctness of the bipartite perfect matching algorithm in Section \[s:formBi\], since the function $H$ is used only to bound the error assuming that $G$ does have a perfect matching. 

We leave open the question of whether any of the other correctness proofs can be formalized in $\overline{{\mathit{V\#L}}} + {\mathit{CH}}$.

We believe that Jeřábek’s framework deserves to be studied in greater depth since it helps us to understand better the connection between probabilistic reasoning and weak systems of bounded arithmetic.  We are working on using Jeřábek’s ideas to formalize constructive aspects of fundamental theorems in finite probability in the spirit of the recent beautiful work by Moser and Tardos [@MT10], Impagliazzo and Kabanets [@IK10], etc. 

Formalizing the Hungarian algorithm
===================================

Before proceeding with the Hungarian algorithm, we need to formalize the two most fundamental theorems for bipartite matching: Berge’s Theorem and Hall’s Theorem. 

Formalizing Berge’s Theorem and the augmenting-path algorithm\[app:Berge\]
--------------------------------------------------------------------------

Let $G=(X \uplus Y, E)$ be a bipartite graph, where $X={\{x_{i}{\,|\,}1\le i\le n\}}$ and $Y={\{y_{i}
{\,|\,}1\le i\le n\}}$. Formally to make sure that $X$ and $Y$ are disjoint, we can let $x_{i}:=i$ and $y_
{i}:=n+i$. We encode the edge relation $E$ of $G$ by a matrix $E_{n\times n}$, where $E(i,j)
=1$ iff $x_{i}$ is adjacent to $y_{j}$. Note that we often abuse notation and write ${\{u,v\}}\in E$ to denote that $u$ and $v$ are adjacent in $G$, which formally means either $$\begin{aligned}
&u\in X\;\wedge\; v\in Y \wedge E(u, v-n), \text{ or} \\
&v\in X\;\wedge\; u\in Y \wedge E(v, u-n).  \end{aligned}$$ This complication is due to the usual convention of using an $n\times n$ matrix to encode the edge relation of a bipartite graph with $2n$ vertices. 

An $n\times n$ matrix $M$ encodes a matching of $G$ iff $M$ is a permutation matrix satisfying $$\forall i,j\in [n], M(i,j)\rightarrow E(i,j).$$

We represent a path by a sequence of vertices ${\left\langle    v_1,\ldots,v_k \right\rangle }$ with ${\{v_i,v_{i+1}\}}\in E$ for all $i \in [k]$.

Given a matching $M$, a vertex $v$ is $M$-*saturated* if $v$ is incident with an edge in $M$. We will say $v$ is $M$-*unsaturated* if it is not $M$-saturated.  A path $P={\left\langle    v_1,\ldots,v_k \right\rangle }$ is an $M$-*alternating path* if $P$ alternates between edges in $M$ and edges in $E\setminus M$. More formally, $P$ is an $M$-alternating path if either of the following two conditions holds:

-   For every $i\in {\{1,\ldots, k-1\}}$, ${\{v_i,v_{i+1}\}}\in E\setminus M$ if $i$ is odd, and ${\{v_i,v_{i+1}\}}\in M$ if $i$ is even. 

-   For every $i\in {\{1,\ldots, k-1\}}$, ${\{v_i,v_{i+1}\}}\in E\setminus M$ if $i$ is even, and ${\{v_i,v_{i+1}\}}\in M$ if $i$ is odd. 

An $M$-alternating path ${\left\langle    v_1,\ldots,v_k \right\rangle }$ is an $M$-*augmenting path* if the vertices $v_{1}$ and $v_{k}$ are $M$-unsaturated. 

\[theo:aug\] (${\textit{VPV}}{\vdash}$) Let $G=(X \uplus Y, E)$ be a bipartite graph.  A matching $M$ is maximum iff there is no $M$-augmenting path in $G$.

($\Rightarrow$): Assume that all matchings $N$ of $E$ satisfy $|N|\le |M|$. Suppose for a contradiction that there is an $M$-augmenting path $P$. Let $M \oplus P$ denote the symmetric difference of two sets of edges $M$ and $P$. Then $M'= M \oplus P$ is a matching greater than $M$, a contradiction. 

($\Leftarrow$): We will prove the contrapositive.  Assume there is another matching $M'$ satisfying $|M'|> |M|$. We want to construct an $M$-augmenting path in $G$.

Consider $Q = M' \oplus M$. Since $|M'|> |M|$, it follows that $|M' \setminus M| > |M\setminus M'|$, and thus $$\begin{aligned}
|Q\cap M'|>|Q\cap M|    \label{eq:aug.1}\end{aligned}$$ Note that we can compute cardinalities of the sets directly here since all the sets we are considering here are small.  Now let $H$ be the graph whose edge relation is $Q$ and whose vertices are simply the vertices of $G$. We then observe the following properties of $H$:

-   Since $Q$ is constructed from two matchings $M$ and $M'$, every vertex of $H$ can only be incident with at most two edges: one from $M$ and another from $M'$. So every vertex of $H$ has degree at most $2$.

-   Any path of $H$ must alternate between the edges of $M$ and $M'$.

We will provide a polytime algorithm to extract from the graph $H$ an augmenting path with respect to $M$, which gives us the contradiction. 

Initialize $K= H$ and $i= 1$ Pick the least vertex $v\in K$ Compute the connected component $C_{i}$ containing $v$ return $C_{i}$ and halt.  Update $K = K \setminus C_{i}$ and $i= i+1$.

Note that since $H$ has $n$ vertices, the while loop can only iterate at most $n$ times.  It only remains to show the following. 

The algorithm returns an $M$-augmenting path assuming $|M'| > |M|$.

Suppose for a contradiction that the algorithm would never produce any $M$-augmenting path.  Since $H$ has degree at most two, in every iteration of the while loop, we know that the connected component $C_{i}$ is

-   either a cycle, which means $|C_{i}\cap M| = |C_{i}\cap M'|$, or

-   a path but not an $M$-augmenting path, which implies that $|C_{i}\cap M| \ge  |C_{i}\cap M'|$.

Since $Q=M' \oplus M = \bigcup_{i} C_{i}$ and all $C_{i}$ are disjoint, we have $$|Q\cap M| = |\bigcup_{i} (C_{i} \cap M)| \ge |\bigcup_{i} (C_{i} \cap M')| = |Q\cap M'|.$$ But this contradicts . 

As a corollary of Berge’s Theorem, we have the following simple algorithm for finding a maximum matching of a bipartite graph $G$. We start from any matching $M$ of $G$, say empty matching.  Repeatedly locate an $M$-augmenting path $P$ and augment $M$ along $P$ and replace $M$ by the resulting matching.  Stop when there is no $M
$-augmenting path.  Then we know that $M$ is maximum.  Thus, it remains to show how to search for an $M$-augmenting path given a matching $M$ of $G$.

\[alg:MWP\] First, from $G$ and $M$ we construct a directed graph $H$, where the vertices $V_{H}$ of $H$ are exactly the vertices $X\uplus Y$ of $G$, and the edge relation $E_{H}$ of $H$ is a $2n\times 2n$ matrix defined as follows: $$\begin{aligned}
E_{H} := {\bigl\{(x,y)\in X\times Y {\,|\,}{\{x,y\}}\in E\setminus M\bigr\}} 
        \cup {\bigl\{(y,x)\in Y\times X{\,|\,}{\{y,x\}}\in M\bigr\}}.\end{aligned}$$ The key observation is that $t$ is reachable from $s$ by an $M$-alternating path in the bipartite graph $G$ iff $t$ is reachable from $s$ in the directed graph $H$.

After constructing the graph $H$, we can search for an $M$-augmenting path using the *breadth first search* algorithm as follows.  Let $s$ be an $M$-unsaturated vertex in $X$. We construct two $2n\times 2n$ matrices $S$ and $T$ as follows. 

The row ${\mathsf{Row}}(1,S)$ of $S$ encodes the set ${\{s\}}$, the starting point of our search.  From ${\mathsf{Row}}(i,S)$, the set ${\mathsf{Row}}(i+1,S)$ is defined as follows: $j\in {\mathsf{Row}}(i+1,S) \leftrightarrow$ there exists some $k\in [n]$, $${\mathsf{Row}}(i,S)(k) \;\wedge\; E_{H}(k,j) \;
\wedge \forall \ell\in [i], \neg {\mathsf{Row}}(\ell,S)(k).$$ After finish constructing ${\mathsf{Row}}(i+1,S)$, we can update $T$ by setting $T(j,k)$ to $1$ for every $k\in 
{\mathsf{Row}}(i,S)$ and $j\in {\mathsf{Row}}(i+1,S)$ satisfying $E_{H}(k,j)$.\

Intuitively, ${\mathsf{Row}}(i,S)$ encodes the set of vertices that are of distance $i-1$ from $s$, and $T$ is the auxiliary matrix that can be used to recover a path from $s$ to any vertex $j\in {\mathsf{Row}}(i,S)$ for all $i\in 
[2n]$.

Let $R=\bigcup_{i=2}^{n}{\mathsf{Row}}(i,S)$, then $R$ the set of vertices reachable from $s$ by an $M$-alternating path.  This follows from the fact that our construction mimics the construction of the formula $\delta_{\textsf{CONN}}$, which was used to define the theory ${\textit{VNL}}$ for ${\mathsf{NL}}$ in [@CN10 Chapter 9].  The matrix $T$ is constructed to help us trace a path for every vertex $v\in 
R$ to $s$.

By induction on $i$, we can prove that ${\mathsf{Row}}(i,S)\subseteq X$ for every odd $i\in [2n]$, and ${\mathsf{Row}}(i,S)
\subseteq Y$ for every even $i\in [2n]$. Thus, after having $S$ and $T$, we choose the largest even $i^{*}$ such that ${\mathsf{Row}}(i^{*},S)\not= {\varnothing}$, and then search the set ${\mathsf{Row}}(i^{*},S)\cap Y$ for an $M$-unsaturated vertex $t$. If such vertex $t$ exists, then we use $T$ to trace back a path to $s$. This path will be our $M$-augmenting path.  If no such vertex $t$ exists, we report that there is no $M$-augmenting path. 

Formalizing Hall’s Theorem \[app:hall\]
---------------------------------------

(${\textit{VPV}}{\vdash}$) Let $G=(X \uplus Y, E)$ be a bipartite graph.  Then $G$ has a perfect matching iff for every subset $S\subseteq X$, $|S|\le |N(S)|$, where $N(S)$ denotes the neighborhood of $S$ in $G$.

The condition $\forall S\subseteq X, |S|\le |N(S)|$, which is necessary and sufficient for a bipartite graph to have a perfect matching, is called Hall’s condition.  We encode a set $S\subseteq X$ in the theorem as a binary string of length $n$, where $S(i) = 1$ iff $x_{i}\in S$. Similarly, we encode the neighborhood $N(S)$ as a binary string of length $n$, and we define $$N(S):= \bigcup{\bigl\{{\mathsf{Row}}(i,E){\,|\,}x_{i}\in S\bigr\}},$$ where the union can be computed by taking the disjunction of all binary vectors in the set $${\bigl\{{\mathsf{Row}}(i,E){\,|\,}x_{i}\in S\bigr\}}$$ componentwise.  Note that we can compute the cardinalities of $S$ and $N(S)$ directly since both of these sets are subsets of small sets $X$ and $Y$.

($\Rightarrow$): Assume $M$ is a perfect matching of $G$. Given a subset $S\subseteq X$, the vertices in $S$ are matched to the vertices in some subset $T\subseteq Y$ by the perfect matching $M$, where $|S|=|T|$. Since $T\subseteq N(S)$, we have $|N(S)|\ge |T|  = |S|$.

($\Leftarrow$): We will prove the contrapositive.  Assume $G$ does not have a perfect matching, we want to construct a subset $S\subseteq X$ such that $|N(S)|< |S|$.

Let $M$ be a maximum but not perfect matching constructed by the augmenting-path algorithm.  Since $M$ is not a perfect matching, there is some $M$-unsaturated vertex $s\in X$. Let $S$ and $T$ be the result of running the “augmenting-path search” algorithm from $s$, then $R := \bigcup_{i=2}^{n}{\mathsf{Row}}(i,S)$ is the set of all vertices reachable from $s$ by an $M$-alternating path.  Since there is no $M$-augmenting path, all the vertices in $R$ are $M$-saturated.  We want to show the following two claims. 

[1]{} The vertices in $R\cap X$ are all matched to the vertices in $R\cap Y$ by $M$, and $$|R\cap X| = |R\cap Y|.$$

Suppose for a contradiction that some vertex $v\in R$ is not matched to any vertex $u\in R$ by $M$. Since we already know that all vertices in $R$ are $M$-saturated, $v$ is matched by some vertex $w\not\in R$ by $M$. But this is a contradiction since $w$ must be reachable from $s$ by an alternating path, and so the augmenting-path search algorithm must already have added $w$ to $R$. Thus, the vertices in $R\cap X$ are all matched to the vertices in $R\cap Y$ by $M$, which implies that $|R\cap X| = |R\cap Y|$.

[2]{} $N(R\cap X) = R\cap Y$.

Since $R\cap X$ are matched to $R\cap Y$, we know $N(R\cap X) \supseteq R\cap Y$. Suppose for a contradiction that $N(R\cap X) \supset R\cap Y$. Let $v\in N(R\cap X) \setminus R\cap Y$, and $u\in R\cap X$ be the vertex adjacent to $v$. Since $u$ is reachable from $s$ by an $M$-alternating path $P$, we can extend $P$ to get an $M$-alternating path from $s$ to $v$, which contradicts that $v$ is not added to $R$.

We note that $N({\{s\}}\cup (R\cap X)) = R\cap Y$. Then $S = {\{s\}}\cup (R\cap X)$ is the desired set since $$|N(S)| = |R\cap Y| =  |R\cap X| < |S|.$$

From the proof of Hall’s Theorem, we have the following corollary saying that if a bipartite graph does not have a perfect matching, then we can find in polytime a subset of vertices violating Hall’s condition. 

(${\textit{VPV}}{\vdash}$) \[cor:hall\] There is a ${\textit{VPV}}$ function that, on input a bipartite graph $G$ that does not have a perfect matching, outputs a subset $S\subseteq X$ such that $|S|> |N(S)|$.

Proof of [Theorem \[theo:hung\]]{} \[app:hung\]
-----------------------------------------------

Let $H =H_{\vec{u},\vec{v}}$ be the equality subgraph for the weight cover $(\vec{u},\vec{v})$, and let $M$ be a maximum cardinality matching of $H$. Recall [Theorem \[theo:hung\]]{} wants us to show that ${\textit{VPV}}$ proves equivalence of the following three statements:

(1) $w(M) = {\mathsf{cost}}(\vec{u},\vec{v}) $

(2) $M$ is a maximum-weight matching and the cover $(\vec{u},\vec{v})$ is a minimum-weight cover of $G$

(3) $M$ is a perfect matching of $H$

(1)$\Rightarrow$(2): Assume that ${\mathsf{cost}}(\vec{u},\vec{v}) = w(M)$. By [Lemma \[lem:hung\]]{}, no matching has weight greater than ${\mathsf{cost}}(\vec{u},\vec{v})$, and no cover with weight less than $w(M)$.

(2)$\Rightarrow$(3): Assume $M$ is a maximum-weight matching and $(\vec{u},\vec{v})$ is a minimum-weight cover of $G$. Suppose for a contradiction that the maximum matching $M$ is not a perfect matching of $H$. We will construct a weight cover whose cost is strictly less than ${\mathsf{cost}}(\vec{u},\vec{v})$, which contradicts that $(\vec{u},\vec{v})$ is a minimum-weight cover. 

Since the maximum matching $M$ is not a perfect matching of $H$, by [Corollary \[cor:hall\]]{}, we can construct in polytime a subset $S\subseteq X$ satisfying $$|N(S)|<|S|.$$ Then we calculate the quantity $$\delta = \min{\{u_{i}+v_{j} - w_{i,j}{\,|\,}x_{i}\in S \;\wedge\; y_{j}\not\in N(S) \}}.$$ Note that $\delta>0$ since $H$ is the equality subgraph.  Next we construct a pair of sequences $\vec{u}'={\left\langle    u'_{i} \right\rangle }_{i=1}^{n}$ and $\vec{v}'={\left\langle    v'_{i} \right\rangle }_{i=1}
^{n}$, as follows: $$\begin{aligned}
 u'_{i} = \begin{cases}
u_{i} -\delta   & \text{ if } x_{i}\in S\\
u_{i}           & \text{ if } x_{i}\not\in S
\end{cases} &&
 v'_{i} = \begin{cases}
v_{j} +\delta   & \text{ if } y_{j}\in N(S)\\
v_{j}           & \text{ if } y_{j}\not\in N(S)
\end{cases}\end{aligned}$$ We claim that $(\vec{u}',\vec{v}')$ is again a weight cover.  The condition $w_{i,j}\le  u'_{i} + v'_{j}$ might only be violated for $x_{i}\in S$ and $y_{i}\not\in N(S)$. But since we chose $\delta \le u_{i}
+v_{j} - w_{i,j}$, it follows that $$w_{i,j}\le (u_{i}-\delta)+v_{j} = u'_{i} + v'_{j}.$$ Since $$\begin{aligned}
{\mathsf{cost}}(\vec{u}',\vec{v}')&={\textstyle  \sum_{i=1}^{n} (u'_{i} + v'_{i})} \\
&=   \underbrace{{\textstyle \sum_{i=1}^{n}} (u_{i} + v_{i})}_{={\mathsf{cost}}(\vec{u},\vec{v})} + \underbrace
{\delta|N(S)| - \delta |S|}_{<0},\end{aligned}$$ it follows that ${\mathsf{cost}}(\vec{u}',\vec{v}')<{\mathsf{cost}}(\vec{u},\vec{v})$.

(3)$\Rightarrow$(1): Suppose $M$ is a perfect matching of $H$. Then $w_{i,j}= u_{i} + v_{j}$ holds for all edges in $M$. Summing equalities $w_{i,j}= u_{i} + v_{j}$ over all edges of $M$ yields the equality ${\mathsf{cost}}(\vec{u},\vec{v}) = w(M)$.

Acknowledgement {#acknowledgement .unnumbered}
===============

We would like to thank Emil Jeřábek for answering our questions regarding his framework.  We also thank the referees and Lila Fontes for their constructive comments.  This work was financially supported by the Ontario Graduate Scholarship and the Natural Sciences and Engineering Research Council of Canada.