\documentclass{article}
\usepackage{amsmath,amssymb}
\input{preamble.tex}

\newcommand{\p}{\mathsf{P}}
\newcommand{\np}{\mathsf{NP}}
\newcommand{\co}{\mathsf{co}}
\newcommand{\bpp}{\mathsf{BPP}}
\newcommand{\pspace}{\mathsf{PSPACE}}
\newcommand{\ph}{\mathsf{PH}}
\newcommand{\sigmap}[1]{\Sigma_{#1}^{\p}}
\newcommand{\pip}[1]{\Pi_{#1}^{\p}}
\newcommand{\poly}{\mathrm{poly}}
\newcommand{\gapp}{\mathsf{GapP}}

\newcommand{\numberp}{{\mathsf{\#}\p}}
\newcommand{\problem}[1]{\ensuremath{\mbox{\textsc{#1}}}}
\newcommand{\eqdef}{~\stackrel{\mbox{\tiny \textnormal{def}}}{=}~}
\newcommand{\ints}{\mathbb{Z}}
\newcommand{\tup}[1]{\langle #1 \rangle}
\newcommand{\pr}[2][{}]{\mathtt{Pr}_{#1}\!\left[ #2 \right]}
\newcommand{\cpr}[2]{\pr{#1 \,|\, #2}}
\newcommand{\expect}[1]{\mathtt{E}\!\left[ #1 \right]}

\renewcommand{\mod}{~\mathrm{mod}~}
\newcommand{\numberc}{{\rm \#C}}
\newcommand{\fp}{{\rm FP}}
\newcommand{\rp}{{\rm RP}}
\newcommand{\bp}{{\mathsf{BP}}}
\newcommand{\C}{{\cal C}}
\newcommand{\true}{\mathsf{true}}
\begin{document}

\lecture{9}{8 March 2001}{Dan Spielman}{David Liben-Nowell}

Today, we will explore the class $\numberp$, as part of an
investigation of classes that fall between $\ph$ and $\pspace$.  We
will also outline the proof of Toda's Theorem, skipping over some of
the details, showing that $\ph \subseteq \p^{\numberp}$.

\section{Counting Classes}

The class $\numberp$ [Valiant c.~1979] (say ``sharp $\p$'' or ``number
$\p$'') is a class of functions counting the number of accepting
computations in a Turing machine:
\[ 
\begin{array}{l}
  \numberp \eqdef \big\{f:\{0,1\}^* \longrightarrow \ints ~|~
  \exists~\mbox{a nondeterministic polynomial time Turing machine $M$
    s.t.} \\
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~f(x) = \mbox{the number of accepting paths of $M$ on input $x$}\big\}.
\end{array}
\]
Note there is also a class $\gapp$, in which we count the difference
between the number of accepting computations and the number of
rejecting computations.  Sometimes it's easier to work with $\gapp$
than $\numberp$.  (In $\numberp$, e.g., we can only map inputs into
the non-negative integers.)

Note that $\np \subseteq \numberp$ (``is there some accepting path?'')
and $\co\np \subseteq \numberp$ (``are all paths accepting?'').  Today
we'll also sketch Toda's theorem:
\begin{theorem}[Toda]
  $\ph \subseteq \p^{\numberp}$.
\end{theorem}
First, though, some more about $\numberp$.  A function $f$ is
\emph{$\numberp$-Complete} if
\begin{enumerate}
\item[\textit{(i)}] $f \in \numberp$,
\item[\textit{(ii)}] For all $g \in \numberp$, there exists a
  polynomial time oracle Turing machine $M^?$ such that $M^F(x)$
  outputs $g(x)$.
\end{enumerate}
Interestingly, $\numberp$-Complete problems do not necessarily
correspond to hard decision problems.

For a circuit $C$, define $\problem{circuitsat}(C)$ to be the number
of input setting that satify the circuit:
\[
\#\problem{circuitsat}(C) \eqdef \left|\left\{x : C(x) =1 \right\}\right|.
\]
$\#\problem{circuitsat}$ is $\numberp$-Complete.

A \emph{matching} is a graph is a subset of the edges using each node
exactly once.  (The number of matchings is the permanent of the
adjacency matrix, where $\mathsf{perm}(M) = \sum_\pi \prod_{i=1}^n
m_{i,\pi(i)}$.  Despite its superficial similarity to the determinant
$\mathsf{det}(M) = \sum_\pi \prod_{i=1}^n (-1)^{\mathrm{sign}(\pi)}
m_{i,\pi(i)}$, it is much harder to compute.)  Valiant proved that
counting the number of matchings in a graph is $\numberp$-Complete.
Finding a single matching is easy (unlike $\#\problem{circuitsat}$,
where finding one is $\np$-hard).

See Papadimitriou for more details, and Jerrum, Sinclar, and Vigoda
[ECCC/STOC'01] for a randomized PTAS for approximately counting the
number of matchings.

\section{Toda's Theorem}

For the rest of the lecture, we will discuss some of the ideas behind
Toda's Theorem.  

To get an intuition for Toda's theorem, we need to define some new
complexity classes.  For class $\C$, we will define four class
operators.  We can use these to get all kinds of new classes.

\begin{definition}
For a complexity class $\C$, 
\begin{eqnarray*}
% ----- %
  \Sigma \cdot \C &\eqdef&
  \{L: \exists ~\mathrm{polynomial}~ p ~~\exists A\in\C\\
  && ~~~~~~~~~~~~~~~~ x\in L \iff
  \exists y\in\{0,1\}^{p(|x|)} \tup{x,y}\in A\} \\
% ----- %
  \Pi \cdot \C &\eqdef&
  \{L: \exists ~\mathrm{polynomial}~ p ~~\exists A\in\C\\
  && ~~~~~~~~~~~~~~~~ x\in L \iff
  \forall y\in\{0,1\}^{p(|x|)} \tup{x,y}\in A\} \\
% ----- %
  \oplus \cdot \C &\eqdef&
  \Bigg\{L: \exists ~\mathrm{polynomial}~ p ~~\exists A\in\C\\
  && ~~~~~~~~~~~~~~~~ x\in L \iff
  \bigg| \left\{ y\in\{0,1\}^{p(|x|)}: \tup{x,y}\in A\right\} \bigg|
  \mathrm{~is~odd} \Bigg\} \\
% ----- %
  \bp \cdot \C &\eqdef&
  \Bigg\{L: \exists ~\mathrm{polynomial}~ p ~~\exists A\in\C\\
  && ~~~~~~~~~~~~~~~~ x\in L ~\Longrightarrow \Pr_{|y|=p(|x|)}
                \limits [\tup{x,y} \in A] > 2/3 \\
  && ~~~~~~~~~~~~~~~~ x\notin L ~\Longrightarrow \Pr_{|y|=p(|x|)}
                \limits [\tup{x,y} \in A] < 1/3\Bigg\}. \\
% ----- %
\end{eqnarray*}
\end{definition}
(Read $\oplus\cdot\C$ as ``parity $\C$''.)


Using these class operators, we can state the key elements of Toda's
theorem.
\begin{claim}
  $\np \subseteq \bp \cdot \oplus \cdot \p,$ and more generally,
  $\Sigma_k^P \subseteq (\bp \cdot \oplus)^k \cdot \p$.
\end{claim}
\begin{claim}
  For any ``reasonable class'' $\C$,
  \begin{eqnarray*}
    \oplus \cdot \bp \cdot \C &\subseteq& \bp \cdot \oplus \cdot \C\\
    \oplus \cdot \oplus \cdot \C &=& \oplus \cdot \C\\
    \bp \cdot \bp \cdot \C &=& \bp \cdot \C.
  \end{eqnarray*}
\end{claim}
So $\sigmap{k} \subseteq \bp \cdot \oplus \cdot \p$.
\begin{claim}
  $\bp \cdot \oplus \cdot \p \subseteq \p^\numberp$.
\end{claim}
Toda's theorem then follows from these claims.  We will give the main
ideas of these proofs today, skipping over the hairy details which, we
are assured, are hairy.

\begin{lemma}
  $\np \subseteq \bp \cdot \oplus \cdot \p$.
\end{lemma}
\begin{proof}
  We show that the $\np$-Complete problem $\problem{circuitsat} \in
  \bp \cdot \oplus \cdot \p$.
  
  Recall the theorem of Valiant and Vazirani from last lecture: there
  exists a random polynomial time procedure that takes a circuit $C$
  and returns $n+1$ circuits $C_1, ..., C_{n+1}$ such that if $C$ is
  satistfiable, 
  \[
  \pr{\exists i ~ C_i \text{ has exactly one satisfying assignment}}
  ~~>~~ 1/8,
  \]
  and otherwise no $C_i$ has a satisfying assignment.  $\bp$ allows us
  to get random bits; when there is only zero or one satisfying
  assignment, $\oplus$ lets us determine which is the case.
  
  Two things are not so good about this.  First, the $1/8$ should be a
  $2/3$.  Second, we have $n+1$ circuits and we want to have 1.
  
  To handle the first problem, we amplify the probability by
  repetition.  Say we output $C_1^i, ..., C_{n+1}^i$ for $i = 1, 2,
  ..., 20$.  Then
  \[
  \pr{\exists i, j~ C_j^i \text{ has exactly one satisfying
      assignment}} ~~>~~ 1 - (7/8)^{20} ~~\approx~~ 0.930 ~~>~~ 2/3.
  \]
  How can we handle the second problem?  We do something like ``AND
  them all togther'' --- but not quite, because that doesn't work.
  Write $\#C$ for the number of satisfying assignments for a circuit
  $C$.  We want to build a circuit $C'$ so that: (1) $\#C'$ is odd if
  any $\#C_i$ is odd, $\#C'$ is even if all $\#C_i$s are even.
  
  The function $\#C' = 1 + \prod_{i=1}^m (\#C_i + 1)$ yields the
  desired properties.  But how do be build the circuit $C'$?  Toda's
  insight was that we can play arithmetic games with the number of
  satisfying assignments.
  
  Given two circuits $C_1(x)$ and $C_2(y)$, we can build a circuit
  $C'$ with $\#C' = \#C_1 + \#C_2$, as follows.  Add a new input $t$,
  and let the circuit be $C'(x,y) = (C_1(x) \wedge t) \vee (C_2(y)
  \wedge \neg t)$.  Similarly, we can build a circuit $C'$ with $\#C'
  = \#C_1 \#C_2$: $C'(x,y) = C_1(x) \wedge C_2(y)$.  It is easy to
  build a circuit with any constant number of satisfying assignments
  (e.g., 1).
  
  Thus we can build $C'$ so that $\#C' = 1 + \prod_{i=1}^m (\#C_i +
  1)$.  So we have a randomized polynomial time procedure which works
  as follows: (1) apply Valiant/Vazirani and amplify; (2) with
  probability at least $9/10$, we have one $C_i$ with an odd number of
  satisfying assignments if $C$ is satisfiable, and with probability
  zero if not; (3) $\#C'$ is odd iff $C$ is satisfiable, with good
  probability.
\end{proof}

\begin{lemma}
  $\bp \cdot \oplus \cdot \p \subseteq \p^\numberp$.
\end{lemma}
\begin{proof}
  Consider a language $L \in \bp \cdot \oplus \cdot \p$.  That is,
  unwinding the definition, there exists a polynomial time Turing
  machine $M$ so that $M(w)$ outputs a circuit $C_w$ so that
  \begin{enumerate}
  \item[\textit{(i)}] if $w \in L$, then $\pr[x]{|\{y:C_w(x,y)=1\}|
      \mathrm{~is~odd}} > 2/3$.
  \item[\textit{(ii)}] if $w \notin L$, then
    $\pr[x]{|\{y:C_w(x,y)=1\}| \mathrm{~is~odd}} < 1/3$.
  \end{enumerate}
  So deciding whether $w \in L$ is equivalent to differentiating
  whether $\pr[x]{|\{y:C_w(x,y)=1\}| \mathrm{~is~odd}}$ is more than
  $2/3$ or less than $1/3$.
  
  We need to show how to do this differentiation in $\p^\numberp$.
  Idea \#1: try $\sum_x \sum_y \#C_w(x,y)$.  But the sum of two odds
  is even, so this doesn't help.  But: if we're given $y_1, \ldots,
  y_N \in \{0,1\} \mod 4N$, then summing them $\mod 4N$ tells us how
  many are odd.
  \begin{eqnarray*}
    h(a) &\eqdef& 4a^3 + 3a^4 \\
    h^{(1)}(a) &\eqdef& h(a) \\
    h^{(c)}(a) &\eqdef& h(h^{(c-1)}(a)).
  \end{eqnarray*}
  If $a\equiv0 \mod 2$ then $h^{(c)}(a) \equiv 0 \mod 2^{2^c}$.  If
  $a\equiv1 \mod 2$ then $h^{(c)}(a) \equiv -1 \mod 2^{2^c}$.  (To
  prove this, show that if $a\equiv0 \mod 2^c$ then $h(a) \equiv 0
  \mod 2^{2c}$ and if $a\equiv1 \mod 2^c$ then $h(a) \equiv -1 \mod
  2^{2c}$, and then use induction.)
  
  Instead of $\sum_x \sum_y \#C(x,y)$, we compute $\sum_x
  h^{(c)}\left(\sum_y \#C(x,y)\right)$.  For a fixed $x$, the value
  $h^{(c)}\left(\sum_y \#C(x,y)\right)$ is either $0$ or $-1 \mod
  2^{2^c}$.  We choose $c=\log m$, so $2^{2^c}$ is large enough that
  we can count the number of $x$ so for which this value is $-1$.  Now
  we can check whether $\pr[x]{|\{y:C_w(x,y)\}| \equiv -1 \mod
    2^{2^c}}$ is more than $2/3$ or less than $1/3$ by
  nondeterministically choosing $x$.  $h^{(c)}$ now has degree $4^c$,
  which is polynomial in $m$.
\end{proof}

The rest of Toda's theorem isn't so hard --- this lecture has sketched
almost all of the hard ideas.
\end{document}



