# Stockmeyer’s Approximate Counting Method

* On the complexity of counting exactly and approximately *

Larry Stockmeyer was one of the great theorists, who worked on areas as diverse as lower bounds on logical theories, computational complexity, distributed computing, algorithms, and many other areas. He passed away in 2004, and is terribly missed by all who knew him. See Lance Fortnow’s wonderful tribute for many details on Larry’s contributions.

Today I want to talk about one of Larry’s great results: an approximate counting method. I have always loved this result.

Larry was quiet, but beneath his quiet exterior he had a tremendous sense of humor. He was also one of the most powerful problem solvers that I had ever had the pleasure to work with. Larry was also extremely accurate—if Larry said that X was true, you could bet the house that X was true. He was amazing at finding loose ends in an argument, and usually then finding a way to tie them up.

I once proved a result on the complexity of univariate polynomials, and I showed a draft of the paper to Larry. A few hours later he came into my office—I was visiting IBM Yorktown at the time—with my paper all marked up. Larry then started to give me very detailed comments about the substance of the paper. After a while I started to get nervous; I was starting to wonder whether or not the main result of my paper was correct or not. I finally asked Larry directly: “is the theorem correct?” He said,

“oh yes, but here you need to argue that ”

I was quite relieved. Larry and I went on to work together on other results on the complexity of polynomials.

A year later, again at IBM Yorktown, we had two visitors George Sacerdote and Richard Tenney, who came to IBM and gave a very technical talk on their solution to the *Vector Addition System* (VAS) reachability problem. It was a long, almost two hour talk, that was attended by the most of the IBM theory group. The reachability problem had been claimed before, and I had worked hard on the problem in the past—with no success. So I was very interested to see if they had really solved the problem.

When the talk was over, we all started to leave the conference room and head to the IBM cafeteria for lunch. I stood right at the door and did an “exit poll”—as each theorist left the room I asked them what they thought about the proof. Did they believe it? Did it look like it might work? Most said that it sounded plausible. A few were even more positive: one member said that he was convinced that the proof would work. Personally, I thought that I had not heard anything new, but nor had I heard anything wrong. I was on the fence.

I then asked the last to exit the room, Larry, what he thought about the proof. Larry said,

“I did not understand a word that they said.”

Larry was right on the money. The proof was wrong, but it took a lot of work, by many people, to eventually find the holes in their attempted proof. See my post for more about the VAS problem.

Let’s turn to Larry’s result on approximate counting.

** Approximate Counting **

Suppose that is a circuit with inputs of size polynomial in . Then, a natural question is: How many satisfy ? This is well known to be a P complete problem, and computing the exact answer is certainly at least as hard as NP. What Larry looked is how hard is it to approximately determine the number of so that ? Let .

A key observation is that there is an amplifier lurking here: if we can in general determine to within a factor of in polynomial time, then we can determine it to within factor for any constant also in polynomial time. This can be proved by a simple amplification argument. The idea is this: create a new circuit where and are disjoint inputs.

Then, has inputs that it accepts. If you know to a factor of , then you know to a factor of . An -fold version of this will yield a approximation of

I have just discussed amplifiers, and this is a perfect example of the power of even a simple repetition amplifier.

Thus, the key problem is to determine to within a factor of . Larry proves,

Theorem:There is a random algorithm that determines to within a factor of in polynomial time provided it has access to an NP-oracle.

Note, there is no way to remove the need for the oracle, without a breakthrough, since it is easy to construct an NP-hard problem that either has no solutions or many solutions. Thus, determining the answer to within a factor of without the oracle would imply that P=NP.

** Sketch of Larry’s proof **

Larry’s proof uses some ideas that had been used earlier by Mike Sipser, but he added several additional insights. See his paper for the details, but I will give a quick overview of how the counting method works.

Let be the circuit and let be the set of inputs so that . Suppose that our goal is really modest: we want to know if is really large, or really small. Take a random hash function where is much smaller than . Then, check to see if there are two distinct and so that they form a “collision”,

and both are in . If is small then, it is likely that (1) will have no solutions, but if is large, then (1) is likely to have solutions. The key to make this work is careful analysis of the probabilities of collisions for the given hash functions. This can be worked out to prove the theorem. Note, the detection of a collision requires an oracle call: “are there two distinct and such that and both are in ”?

** Counting and Finite Automata **

I love finite state automata (FSA)—as you probably know. The following theorem is not as well known as it should be, in my opinion at least:

Theorem:Suppose that is a -state deterministic finite state automaton. Then, the number of length inputs that are accepted by can be computed exactly in polynomial time in and .

Thus, for FSA, the problem of counting the number of accepting computations is easy.

A proof sketch is the following—unfortunately I cannot find a paper to point to here, any help would be appreciated. Perhaps its a folklore theorem, since I have known it forever. Let be a new automata that simulates on all inputs of length , and has the property that the state diagram is acyclic. Essentially, replaces each state of by the state where . For example, if was a transition on input , then

is a transition for input for all . We have simply unrolled the automaton to avoid any loops: this cannot be done in general, but is fine if we are only concerned with inputs of a fixed length .

The algorithm then inductively labels each state with the number of length- inputs that reach this state. To label a state , we take each state with arcs to , and add the number of *times the number of arcs from to *. The number of accepting computations of length is then the sum of the numbers for with an accepting state of the original .

** Open Problems **

Can we improve the result of Stockmeyer on approximate counting? For specific problems there are better results known of course, but I wonder can we improve his counting argument? Of course if P=NP, then approximate counting would be in polynomial time, but can it be in NP?

Ken Regan, who helped with this post, points out an interesting connection between Larry’s theorem and quantum computation—he promises to post a comment on it.

Another natural question that I think might be worth working on is this: pick a complexity class that could be weaker than polynomial time and see what the cost of approximate counting is for that class. I have given a simple example, above, where exact counting is easy. There is some quite nice work on approximate counting for certain simple classes of circuits—I will leave that for another day.

### Trackbacks

- Math World | Stockmeyer's Approximate Counting Method « Gödel's Lost Letter and …
- Interesting things to read… « Sebastian Pokutta’s Blog
- Aaronson and Arkhipov’s Result on Hierarchy Collapse | Combinatorics and more
- Approximate counting problem capturing BQP | Q&A System
- Grilling Quantum Circuits « Gödel’s Lost Letter and P=NP

For the FSA counting, why not just compute the generating function (in constant time) and then use Taylor series or run the recursion?

An interesting related question is to count the number of inputs of length n that an NFA with m states accepts. This is a #P-hard problem. However, one can obtain a (1+\eps) approximation in n^{O(log n/\eps)} time. This is in a paper of Gore etal which also shows how to count the number of strings of length n accepted by a context free grammar.

ftp://ftp.cis.upenn.edu/pub/kannan/newj.ps.gz

I think it is still an open problem to improve the quasi-polynomial time to a polynomial time.

Thanks. I did not know this result. Thanks again for the pointer. Would be cool to improve the bound.

Here’s the connection in brief. BQP is the feasible quantum computing class analogous to BPP, but unlike BPP it contains (the decision version of) factoring and other interesting stuff. Also unlike BPP, it is not known to be contained in the polynomial hierarchy.

You can reduce a BPP question to approximating a single #P function, but with BQP what you get is the

differenceof two #P functions, call them f and g. Approximating f and g separately does not help you approximate f – g when f – g is near zero!BQP does give you a little help: When the answer to the BQP question on an input x is yes, you get that f(x) – g(x) is close to the square root of 2^m, where the counting predicates defining f and g have m binary variables after you substitute for x. (There are no absolute-value bars; “magically” you always get f(x) > g(x). Under common representations of quantum circuits for BQP, m becomes the number of Hadamard gates.) When the answer is no, the difference is close to 0. Doing Stockmeyer approximation on f and g separately still fails basically because 2^{m/2} is not a polynomial fraction of 2^m. The open question is what other counting and approximation tricks might come into play…

On “counting accepted n-length strings in an m-state DFA is in P”:

Yes, it is folklore.

Even better, the problem is in NC. In the class #L, of functions that report the number of accepting paths of a logspace-bounded machine, and hence expressible as the determinant of a related integer matrix. Why? Unroll the DFA into an acyclic graph on n-length inputs. Each node has out-degree 2. Now let an NLOG machine trace out a path in this graph, choosing an out-edge nondeterministically, and accepting if the final state reached is an accepting state.

I’m not sure what would be a good reference: I believe (courtesy Eric Allender) that the unrolling idea goes back to Neil Jones in the 1970s. Certainly, the idea has been used implicitly or explicitly in almost all papers dealing with #L or GapL.

Related result: instead of counting inputs, what if we just want to test if a particular input is accepted? ie Membership testing. If the NFA is also part of the input, this is NLOG-complete. (As opposed to when the NFA is fixed; this would be NC^1 complete. Also, as opposed to when the NFA is in the input but is in fact a DFA; this would be DLOG-complete.)

And counting accepting paths on one particular input: if the NFA is part of the input, it is #L-complete, if the NFA is fixed, this is computable in #NC^1 and hence in deeterminstic logspace.

Thanks for the post(s). I have known the result for a long time, and cannot remember how first heard it. So thanks for the comments, again.

mistyped URL

About 10 years ago, I found a false proof that P does not equal NP, and it took me a few days to find my bug (I was pretty excited for a while!). Even though I had already found my bug, I showed the false proof, just for fun, to various famous members of our theory community, to see if they could spot the bug (I did tell them that there existed a bug, and that their challenge was to find it). Only two of them were able to find the bug, and they both found it pretty quickly – Larry Stockmeyer and Moshe Vardi. Amusingly enough, the bug was, of all things, a misuse of Fagin’s Theorem! Maybe the other people I showed the proof to just trusted that I surely wouldn’t misuse my own theorem.

hello,

thanks for the great quality of your website, each time i come here, i’m amazed.

I would like to suggest you to discover the real black hattitude.

you’ll find a lot of tricks related to the black hattitude,

You can buy some black hattitude, rent black hattitude, steal black hattitude, or find

the ultimate black hattitude on our sites ofblack hattitude.

regards,

Mike Litoris

black hattitudeyou’ll find here also some good black hattitude