The motivation for this paper is to obtain a better understanding of randomized approximate counting inside #P.
The class #P  is the class of functions that count the number of solutions to problems in NP, e.g. #SAT is the function that on input a formula returns the number of satisfying assignments of
Equivalently, functions in #P count accepting paths of non-deterministic polynomial time Turing machines (NPTMs).
NP-complete problems are hard to count, but it is not the case that problems in P are easy to count as well. When we consider counting, non-trivial facts hold. First of all there exist #P-complete problems, that have decision version in P, e.g. #DNF. Moreover, some of them can be approximated, e.g. the Permanent  and #DNF , while other can not, e.g. #IS .
Regarding approximability, counting versions of NP-complete problems do not admit f.p.r.a.s. unless NP = RP. So we have to concentrate on problems whose decision version is not NP-complete. There are two subclasses of #P that concern our study, because they have easy decision version; TotP and #PE . #PE contains all counting problems in #P with decision version in P, and TotP contains functions that count all paths of NPTMs, and it is also proven to contain all self-reducible problems in #PE .
It is observed that all problems in #P known to admit f.p.r.a.s., belong to TotP. This observation lead to some questions. Which counting problems admit f.p.r.a.s. from a structural complexity perspective? Does FPRAS TotP hold? (In this paper we denote FPRAS the class of problems in #P that admit an f.p.r.a.s.) Is there an alternative characterization of FPRAS, in terms of counting paths of NPTMs, like the respective definitions of #P and TotP?
In this article we introduce two counting classes, #RP1 and #RP2, that can both be considered as counting versions of problems with decision version in RP. We show that FPRAS lies between them. We also show that these two classes are not equal, unless NP=RP.
Moreover we show that if FPRAS TotP, then RP=P. So we don’t resolve the question of FPRAS vs TotP, but it turns out that if the above inclusion holds, then it is more difficult to prove it, than proving RP=P. Note that for the opposite direction, i.e. TotP FPRAS, it is known that it holds iff NP=RP.
We further explore inclusions between all the above mentioned classes, i.e. #P, #PE, #RP1, #RP2, TotP and FPRAS, and we present all possible worlds with respect to NP vs RP, and RP vs P.
We present our results in section 3 and we discuss them in section 5. The rest of the paper is organized as follows. Section 2 contains definitions, lemmas and known results used in our proofs. Section 4 contains our proofs. Section 6 provides briefly some related work, and conclusions are given in section 7.
Let be an NPTM. If returns or we denote (accepting paths of on input ). We denote the polynomial bounding the number of non-deterministic choices made by
 is the class of functions for which there exists a polynomial-time decidable binary relation and a polynomial such that , . Equivalently,
FP is the class of functions in #P computable in polynomial time.
The decision version of a function in #P is the language .
 , where all computation paths of on input .
TotP contains all self-reducible problems in #P, with decision version in P.
Intuitively, self-reducibility means that counting the number of solutions to an instance of a problem, can be performed recursively by computing the number of solutions of some other instances of the same problem. For example #SAT is self reducible: the number of satisfying assignments of a formula is equal to the sum of the number of satisfying assignments of and , where is with its first variable fixed to .
The most general notion of self reducibility, that TotP can capture, is given in . The following is known.
(a) FP TotP . The inclusions are proper unless .
(b) TotP is the Karp closure of self-reducible functions.
We consider FPRAS to be the class of functions in #P that admit f.p.r.a.s.
Let . if there exists a randomized algorithm that on input returns a value s.t.
in time poly().
(a) If NPRP then there are functions in TotP, that are not in FPRAS.
(b) If NP=RP then .
Proof. #IS (i.e. given a graph, count all independent sets, of all sizes) belongs to TotP, and does not admit f.p.r.a.s. unless NP=RP . The second assertion derives from a Stockmeyer’s well known theorem , see Appendix for a proof sketch.
Now we introduce two classes, having decision version in RP. For that, we need to define the set of Turing Machines associated to problems in RP.
Let be an NPTM. We denote the polynomial s.t. on inputs of size , makes non-deterministic choices.
NPTM either or
#RP1 = s.t.
For our proofs we will need the following lemma.
Unbiased estimator. Let be two finite sets, and let . Suppose we take samples from uniformly at random, and let a be the number of them that belong to . Then is an unbiased estimator of , and it suffices in order to have
We first present unconditional inclusions between the above mentioned classes. These inclusions together with those already known by theorem 1 can be summarised in the following diagram.
Then we explore more inclusions between these counting classes, with respect to NP vs RP and RP vs P. The results can be summarized in the figures of theorem 5.
The most important corollaries of this investigation are that FPRAS is not all contained in TotP unless RP=P, and #RP1 does not coincide with #RP2 unless NP=RP.
4.1 Unconditional inclusions
Proof. Let . We will show . We will construct an NPTM s.t. on input . Let . computes . Then it computes s.t. . makes non-deterministic choices . Each such determines a path, in particular, corresponds to the path (since is the first path). returns yes iff , so . Since
The other inclusions are immediate by definitions.
Proof. For the first inclusion, let Let . There exists a s.t. Let be the number of non-deterministic choices of Let . We can compute an estimate of by choosing paths uniformly at random. Then we can compute .
If then If , then so by the unbiased estimator lemma 1, satisfies the definition of f.p.r.a.s.
For the second inclusion, let , we will show that the decision version of , i.e. deciding if , is in RP. On input we run the f.p.r.a.s. for with e.g. We return yes iff
If the the f.p.r.a.s. returns
, so we return yes with probability. If , then with probability at least , so we return yes with the same probability.
If then RP=P.
Proof. If FPRAS TotP, then #RP1 TotP, and then for all P. So if then , and thus P. Thus RP=P.
If then NP=RP.
Proof. If then they are both equal to FPRAS, thus TotP FPRAS, thus NP=RP from theorem 2.
4.2 The four possible worlds
Now we will explore further relationships between the above mentioned classes, and we will present all four possible worlds inside #P, with respect to NP vs RP vs P.
The following figures hold.
In the figures, means , means , and means .
Proof. First of all, intersections between any of the above classes are non-empty, because FP is a subclass of all of them. For the rest inclusions, we have the following.
#P#RP2 NP=RP (by definitions).
#RP2 #PE RP=P (by definitions).
#P TotP NP=P (by theorem 1). Also NP=P #SAT TotP, because #SAT is self-reducible, and it would have easy decision. Thus #P TotP, because TotP is the Karp-closure of self reducible problems with easy decision, and #SAT is #P-complete under Karp reductions. So we get #P = #PE = TotP P=NP.
TotP FPRAS NP=RP (by theorem 2).
#RP2 FPRAS TotP FPRAS NP=RP.
#RP2=#RP1 NP=RP (by corollary 2).
#P FPRAS NP=RP (by theorem 2).
#PE FPRAS TotP FPRAS NP=RP.
#PE #RP1 #PE FPRAS NP=RP.
#RP1 #PE RP=P (same proof as corollary 1).
FPRAS #PE #RP1 #PE RP=P.
FPRAS TotP RP=P (corollary 1).
TotP #RP1 TotP FPRAS NP=RP.
#RP1 TotP RP=P (same proof as corollary 1).
#RP1 FP #RP1 TotP RP=P.
TotP FP NP=P (by theorem 1).
5 Discussion and Further Research
Regarding the question of whether FPRAS TotP, Corollary 1 means that it does not hold unless P=RP, and if it holds, then it is more difficult to prove it, than proving RP=P.
Determining if RP=P implies FPRAS TotP, is an open question, interesting on its own. Morover, if it holds, then the (FPRAS TotP?) question would be an equivalent formulation of the RP vs P question. Note that we already know that the (TotP FPRAS?) question is an equivalent formulation of NP vs RP.
Corollary 2 means that although #RP1 and #RP2 are natural counting counterparts of RP, they can’t be equal unless NP=RP. This happens because when we consider functions in #P as functions that count the number of solutions to some decision problem, then in the first class the accepting random choices are in 1-1 correspondence with the solutions we want to count, while in the second class, random choices and solutions do not necessarily coincide.
It is interesting that regarding decision, the two analogue definitions of RP are equivalent, i.e. for every problem in RP, there exists an NPTM in deciding the problem, and vice versa. But for the counting versions, this can’t hold any more, unless NP=RP.
Regarding the possibility of characterizing FPRAS in terms of counting paths of Turing machines, Corollary 2 implies such a characterization, if the two classes coincide. However, in this case, as we saw, FPRAS would also be equal to #P, which of course is a much simpler characterization.
On the other hand, without any assumptions, theorem 4 means that the characterization of FPRAS that we are looking for, is something between the two definitions of #RP1 and #RP2, a relaxation of the first and a restriction of the second. However it might be not very elegant.
It is an open question whether FPRAS is in #RP1. It seems that both a negative and a positive answer are compatible with all four worlds. If the answer is positive, then #RP1 would be an equivalent characterization of FPRAS.
6 Related work
From a unifying point of view, the most important results regarding approximability are the following. Every function in #P either admits a f.p.r.a.s., or is inapproximable to within a polynomial factor . For self-reducible problems in #P, f.p.r.a.s. is equivalent to almost uniform sampling . With respect to approximation preserving reductions, there are three main classes of functions in #P: (a) the class of functions that admit an f.p.r.a.s., (b) the class of fuctions that are interreducible with #SAT under approximation preserving reductions, and (c) the class of problems that are interreducible with #BIS under approximation preserving reductions . Problems in the second class are inapproximable unless NP=RP, while the approximability status of the third class is unknown.
In this paper we refined the picture of counting complexity inside #P, in particular with regard to approximate counting.
We have introduced two subclasses of #P: #RP1 and #RP2, that both can be considered as counting versions of RP. We showed that FPRAS lies between them, and that these classes do not coincide unless NP=RP. With the help of these classes we also proved that FPRAS cannot be contained in TotP, unless RP=P.
Finally we studied the implications of randomized decision complexity, i.e. RP vs NP, and RP vs P, to the relationships between some counting classes inside #P, that have decision version either in P or in RP.
Further research could be the study of the relationships between the new introduced classes with other known subclasses of #P, as mentioned in the related work section 6.
(folklore) If NP=RP then all problems in #P admit an f.p.r.a.s.
Proof. (sketch) In  Stockmeyer has proven that an f.p.r.a.s., with access to a oracle, exists for any problem in #P. If NP=RP then . Finally it is easy to see that an f.p.r.a.s. with access to a BPP oracle, can be replaced by another f.p.r.a.s., that simulates the oracle calls itself.
-  Leslie G. Valiant: The Complexity of Computing the Permanent. Theor. Comput. Sci. 8: 189-201 (1979)
M. Jerrum and A. Sinclair: The Markov chain Monte-Carlo method: an approach to approximate counting and integration. In Approximation Algorithms for NP-hard Problems (Dorit Hochbaum, ed.), PWS, pp. 482– 520 (1996)
-  Richard M. Karp, Michael Luby, Neal Madras: Monte-Carlo Approximation Algorithms for Enumeration Problems. J. Algorithms 10(3): 429-448 (1989)
-  Martin E. Dyer, Alan M. Frieze, Mark Jerrum: On Counting Independent Sets in Sparse Graphs. SIAM J. Comput. 31(5): 1527-1541 (2002)
-  Aggelos Kiayias, Aris Pagourtzis, Kiron Sharma, Stathis Zachos: Acceptor-Definable Counting Classes. Panhellenic Conference on Informatics 2001: 453-463.
-  Aris Pagourtzis, Stathis Zachos: The Complexity of Counting Functions with Easy Decision Version. MFCS 2006: 741-752
-  A. Pagourtzis. On the complexity of hard counting problems with easy decision version. In Proceedings of the 3rd Panhellenic Logic Symposium, Anogia, Crete, 2001.
-  Larry J. Stockmeyer: On Approximation Algorithms for #P. SIAM J. Comput. 14(4): 849-861 (1985)
-  Dror Weitz: Counting independent sets up to the tree threshold. STOC 2006: 140-149
-  Alistair Sinclair, Mark Jerrum: Approximate Counting, Uniform Generation and Rapidly Mixing Markov Chains. Inf. Comput. 82(1): 93-133 (1989)
-  Martin E. Dyer, Leslie Ann Goldberg, Catherine S. Greenhill, Mark Jerrum: The Relative Complexity of Approximate Counting Problems. Algorithmica 38(3): 471-500 (2004)
-  Evangelos Bampas, Andreas-Nikolas Göbel, Aris Pagourtzis, Aris Tentes: On the connection between interval size functions and path counting. Computational Complexity 26(2): 421-467 (2017)
-  Lane A. Hemaspaandra, Christopher M. Homan, Sven Kosub, Klaus W. Wagner: The Complexity of Computing the Size of an Interval. SIAM J. Comput. 36(5): 1264-1300 (2007)
-  Carme Alvarez, Birgit Jenner: A Very Hard log-Space Counting Class. Theor. Comput. Sci. 107(1): 3-30 (1993)
-  Sanjeev Saluja, K. V. Subrahmanyam, Madhukar N. Thakur: Descriptive Complexity of #P Functions. J. Comput. Syst. Sci. 50(3): 493-505 (1995)
-  Andrei A. Bulatov, Víctor Dalmau, Marc Thurley: Descriptive complexity of approximate counting CSPs. CSL 2013: 149-164
-  Marcelo Arenas, Martin Muñoz, Cristian Riveros: Descriptive Complexity for counting complexity classes. LICS 2017: 1-12
-  Víctor Dalmau: Linear datalog and bounded path duality of relational structures. Logical Methods in Computer Science 1(1) (2005)