betaFeedback

WorksMathematics

Exact Sampling of Almost Surely Finite Sequences of Independent Events

Abstract

We consider infinite sequences of independent events whose probabilities are summable, so that almost surely only finitely many of the events occur. We present an algorithm which exactly samples the set of events which occur, using a finite number of steps. The algorithm works by generating proposals from a Poisson process, followed by a rejection step. We illustrate use of the algorithm with the help of three applications: prime factorisation of zeta-distributed random integers, random integer partitions and convex lattice polygonal lines.

Introduction

Consider a sequence of independent Bernoulli random variables (Xn)n∈N(X_n)_{n\in\mathbb{N}}, such that we have P(Xn=1)=1−P(Xn=0)=pnP(X_n=1)=1-P(X_n=0)=p_n for all n∈Nn\in\mathbb{N}. If we assume that ∑n=1∞pn<∞\sum_{n=1}^{\infty}p_n<\infty, the Borel–Cantelli lemma guarantees that, almost surely (a.s.), the events {Xn=1}\{X_n=1\} happen only for finitely many nn. Thus, while there are infinitely many XnX_n in the sequence, an exact representation of a random sample from the sequence can be stored using only a finite amount of computer memory. Here we show that in many cases it is possible to exactly sample random instances of (Xn)n∈N(X_n)_{n\in\mathbb{N}}. The main obstacle to overcome is the fact that the position of the last non-zero XnX_n is determined by the infinite tail of the random sequence.

As a simple example, let pn=1−e−2−np_n=1-\mathrm{e}^{-2^{-n}} for all n∈Nn\in\mathbb{N}. Since pn∼2−np_n\sim2^{-n}, the series ∑npn\sum_n p_n is convergent. In this case, it is easy to compute the distribution of the index of the last non-zero XnX_n. Set M:=max⁡{n∈N∣Xn≠0}M := \max\{n \in\mathbb{N} \mid X_n \ne0\}, then we have

P(M≤m)=∏n=m+1∞(1−pn)=∏n=m+1∞e−2−n=exp⁡(−2−m∑n=1∞2−n)=e−2−m.\begin{aligned} P(M \le m) = \prod_{n=m+1}^{\infty}(1-p_n) = \prod_{n=m+1}^{\infty}e^{-2^{-n}} \\ &= \exp\left(-2^{-m}\sum_{n=1}^{\infty}2^{-n}\right)=e^{-2^{-m}}. \end{aligned}

Note that for m=0m=0 (which means that all XnX_n are zero) this gives a correct answer, P(M=0)=e−1P(M=0)=e^{-1}. More generally, for m≥1m\ge1

P(M=m)=e−2−m−e−2−(m−1)=e−2−m(1−e−2−m).(1)P(M=m)=e^{-2^{-m}}-e^{-2^{-(m-1)}}=e^{-2^{-m}}\left(1-e^{-2^{-m}}\right). \tag*{(1)}

Hence, we can first sample the random number M=mM=m according to its distribution (1) and then sample independent Bernoulli random variables X1,…,Xm−1X_1,\ldots,X_{m-1} (with Xm=1X_m=1 by definition of MM). This gives an exact sampling algorithm, but to generalise it we need to be able to calculate explicitly the infinite products of the form ∏n>m(1−pn)\prod_{n>m}(1-p_n), which is not always possible.

As a pragmatic alternative, we consider a straightforward but approximate algorithm.

Algorithm 0.

  1. Choose NN large.

  2. For n∈{1,…,N}n\in\{1,\ldots,N\}, generate Xn∈{0,1}X_n\in\{0,1\} independently with P(Xn=1)=pnP(X_n=1)=p_n.

  3. Set Xn=0X_n=0 for all n>Nn>N.

In the output of Algorithm 0, the events XnX_n are independent. For n≤Nn\le N we have P(Xn=1)=pnP(X_n=1)=p_n as required, but for n>Nn>N we have P(Xn=1)=0P(X_n=1)=0. If we choose NN large enough that pnp_n is ‘small’ for all n>Nn>N, we can use Algorithm 0 as an approximate solution to our problem. Our aim is to present an algorithm (using only finitely many steps) which can exactly sample from the full sequence of events, corresponding to the case N=∞N=\infty in Algorithm 0.

Sequences of this kind appear in the study of random combinatorial structures. An integer partition can be described by the numbers of parts of each size and, for suitable probability measures on the set of all partitions, these numbers are independent random variables of which only finitely many are non-zero [14, 23, 7]. Convex lattice polygonal lines can be described in the same way, using the multiplicities of the sides in each possible direction [22, 9]. A further example is the occupancy problem with infinitely many boxes, where a Poisson distributed number of balls makes the numbers of balls in different boxes independent [15, 8]. Our algorithm is based on this last observation.

For combinatorial structures, exact sampling is often considered in the framework of Boltzmann samplers, introduced by Duchon et al. [12]. Such a sampler generates an object of random size, in such a way that all objects of the same size are equally likely. Flajolet et al. [13] extend the framework to unlabelled structures, including multisets and powersets; their samplers assume that an oracle for the values of the generating functions is available. If an object of a given size is required, the output of the sampler can be rejected until the size is correct, and Arratia and DeSalvo [3] and DeSalvo [10] show how the cost of this rejection step can be reduced. Our method uses two older ideas. The first idea is the thinning method of Lewis and Shedler [19], which simulates a Poisson process by generating the points of a process with larger intensity and then deleting some of these points at random. The second idea is retrospective sampling, which Beskos et al. [5] use for the exact simulation of a class of diffusions: there, an infinite-dimensional object is simulated exactly by generating only the finitely many random variables which are needed to determine the output.

A related construction appears in parallel work by Peyen [20], who considers the probabilities zn/(1+zn)z^n/(1+z^n), with several independent events for each nn, in order to obtain Boltzmann samplers for powersets. There, the independence of the events is derived from an occupancy model with a Poisson distributed number of balls, and the rejection step is justified using the thinning method for Poisson processes. Peyen [20] also shows that, in such an occupancy model with infinitely many boxes, the Poisson distribution is the only distribution for the number of balls which makes the events uncorrelated. The focus of the present article is different: we state the method for arbitrary summable probabilities pnp_n, give a self-contained proof based on Poisson processes, and consider examples outside the setting of Boltzmann samplers.

Section 2 introduces the main results of the article, namely Algorithm 1, the correctness proof in Lemma 1 and the efficiency analysis in Lemma 2. In section 3 we apply the method to three examples: the prime factorisation of zeta-distributed random integers, random integer partitions and convex lattice polygonal lines. In the first of these examples the probabilities pnp_n decay so slowly that Algorithm 0 is not feasible when the parameter of the distribution is close to 1, whereas the expected cost of the exact algorithm is polynomial. To our knowledge, this gives the first exact sampler for factored, zeta-distributed integers.

Exact Sampling

The following algorithm gives an exact solution for the sampling problem described in the introduction.

The Algorithm

Algorithm 1. Choose probability weights (πn)n∈N(\pi_n)_{n\in\mathbb{N}} such that πn>0\pi_n>0 for all n∈Nn\in\mathbb{N} and such that there exists an a∈Ra\in\mathbb{R} with an:=−log⁡(1−pn)/πn≤aa_n := -\log(1-p_n)/\pi_n\leq a for all n∈Nn\in\mathbb{N}. Then perform the following steps:

  1. Generate K∼Poiss⁡(a)K\sim\operatorname{Poiss}(a).

  2. Generate N1,…,NK∈NN_1,\ldots,N_K\in\mathbb{N}, independently, such that P(Nk=n)=πnP(N_k=n)=\pi_n for all n∈Nn\in\mathbb{N} and all k∈{1,…,K}k\in\{1,\ldots,K\}.

  3. Generate U1,…,UK∈[0,a]U_1,\ldots,U_K\in[0,a], independently, uniformly distributed.

  4. For all n∈Nn\in\mathbb{N}, set Xn=1X_n=1 if there is a k∈{1,…,K}k\in\{1,\ldots,K\} with Nk=nN_k=n and Uk≤anU_k\leq a_n, and set Xn=0X_n=0 otherwise.

Figure 1 illustrates the algorithm. Steps 1 to 3 generate random points (Nk,Uk)(N_k,U_k) in the strip N×[0,a]\mathbb{N}\times[0,a], and step 4 accepts the points which satisfy Uk≤aNkU_k\leq a_{N_k}. We have Xn=1X_n=1 if and only if at least one of the accepted points has first coordinate nn.

Figure 1. One run of Algorithm 1 for pn=znp_n=z^n and πn=zn−1(1−z)\pi_n=z^{n-1}(1-z) with z=0.9z=0.9, as in Example 2. Each point (Nk,Uk)(N_k,U_k) is shown as a circle at height UkU_k in column NkN_k. The circle is filled if Uk≤aNkU_k \le a_{N_k}, and we have Xn=1X_n=1 if and only if column nn contains at least one filled circle.

To use the algorithm, we need to choose probability weights π=(πn)n∈N\pi=(\pi_n)_{n\in\mathbb{N}} which satisfy the assumptions stated at the start of the algorithm. Under the assumptions pn∈[0,1)p_n\in[0,1) and ∑n∈Npn<∞\sum_{n\in\mathbb{N}}p_n<\infty, a suitable distribution π\pi always exists. For example, it is easy to show that

a∗:=−∑n∈Nlog⁡(1−pn)<∞a^* := -\sum_{n\in\mathbb{N}}\log(1-p_n)<\infty

and thus πn=−log⁡(1−pn)/a∗\pi_n=-\log(1-p_n)/a^* is a valid choice. The following lemma shows that the algorithm works as intended.

Lemma 1. Given (pn)n∈N(p_n)_{n\in\mathbb{N}} with pn∈[0,1)p_n\in[0,1) for all n∈Nn\in\mathbb{N} and ∑n∈Npn<∞\sum_{n\in\mathbb{N}}p_n<\infty, let (Xn)n∈N(X_n)_{n\in\mathbb{N}} be the sequence of random variables constructed by Algorithm 1. Then the XnX_n are independent, with P(Xn=1)=pnP(X_n=1)=p_n for all n∈Nn\in\mathbb{N}.

The proof, loosely inspired by Beskos et al. [5], is a nice application of Poisson processes. For reference we summarise the required results here, leaving measurability considerations aside. Full details can be found, for example, in the monograph by Kingman [18]. In the following, #M\#M denotes the number of elements in a finite or countable set MM.

Definition 1. Let SS be a set and Λ\Lambda a measure on SS such that Λ({x})=0\Lambda(\{x\})=0 for all x∈Sx\in S. A Poisson process on SS with intensity measure Λ\Lambda is a random subset Π\Pi of SS such that

  1. for each m∈Nm\in\mathbb{N} and any disjoint sets A1,…,Am⊆SA_1,\ldots,A_m\subseteq S, the random variables #(A1∩Π),…,#(Am∩Π)\#(A_1\cap\Pi),\ldots,\#(A_m\cap\Pi) are independent, and

  1. for every A⊆SA\subseteq S, the random variable #(A∩Π)\#(A\cap\Pi) is Poisson distributed with parameter Λ(A)\Lambda(A).

In the proof of Lemma 1, below, we will use the fact that the Zk:=(Nk,Uk)Z_k:=(N_k,U_k) constructed in the algorithm form a Poisson process. This follows from the same argument as is used in the existence proof of Poisson processes: Assume that μ:=Λ(S)<∞\mu:=\Lambda(S)<\infty and that K,Z1,Z2,…K,Z_1,Z_2,\ldots are independent random variables such that K∼Poiss⁡(μ)K\sim\operatorname{Poiss}(\mu) and

P(Zk∈A)=Λ(A)Λ(S)P(Z_k\in A)=\frac{\Lambda(A)}{\Lambda(S)}

for all A⊆SA \subseteq S. Define Π:={Zk∣k=1,…,K}\Pi:= \{Z_k \mid k = 1,\ldots,K\}. Let A1,…,Am⊆SA_1,\ldots,A_m \subseteq S be disjoint. Then

P(#(Π∩A1)=k1,…,#(Π∩Am)=km)=∑k=∑ki∞P(#(Π∩A1)=k1,…,#(Π∩Am)=km∣K=k)⋅P(K=k)=⋯=∏i=1me−Λ(Ai)Λ(Ai)kiki!.\begin{aligned} P(\#(\Pi\cap A_1) = k_1,\ldots,\#(\Pi\cap A_m) = k_m) &= \sum_{k=\sum k_i}^{\infty} P(\#(\Pi\cap A_1) = k_1,\ldots,\#(\Pi\cap A_m) = k_m \mid K = k) \cdot P(K = k) \\ &= \cdots\\ &= \prod_{i=1}^{m} e^{-\Lambda(A_i)} \frac{\Lambda(A_i)^{k_i}}{k_i!}. \end{aligned}

(We leave some of the steps as an exercise to the reader.) This shows that the #(Π∩Ai)\#(\Pi\cap A_i) are independent and Poisson distributed, and thus that Π\Pi is indeed a Poisson process.

Proof of Lemma 1. Let S:=N×[0,a]S := \mathbb{N} \times[0,a] and consider the product measure Λ=π×Leb⁡\Lambda= \pi\times\operatorname{Leb} on SS, where Leb⁡\operatorname{Leb} denotes the Lebesgue measure on [0,a][0,a]. Then we have Λ(S)=a<∞\Lambda(S) = a < \infty and Λ\Lambda has no atoms. For the purpose of the proof we extend the UiU_i and NiN_i from the algorithm to infinite sequences (Ui)i∈N(U_i)_{i \in\mathbb{N}} and (Ni)i∈N(N_i)_{i \in\mathbb{N}}, where all NiN_i, UiU_i are independent of each other and of KK. From the algorithm we recall that P(Ni=n)=πnP(N_i = n) = \pi_n and that the UiU_i are uniformly distributed on [0,a][0,a]. Since

P((Ni,Ui)∈A)=∑n=1∞πnLeb⁡({u∣(n,u)∈A})a=Λ(A)Λ(S)P((N_i,U_i) \in A) = \sum_{n=1}^{\infty} \pi_n \frac{\operatorname{Leb}(\{u \mid(n,u) \in A\})}{a} = \frac{\Lambda(A)}{\Lambda(S)}

for all i∈Ni \in\mathbb{N} and all A⊆SA \subseteq S, the construction preceding this proof shows that the random set

Π:=⋃k=1K{(Nk,Uk)}⊂S\Pi:= \bigcup_{k=1}^{K} \{(N_k,U_k)\} \subset S

is a Poisson process with intensity measure Λ\Lambda on SS.

By definition of ana_n we have an=−log⁡(1−pn)/πna_n = -\log(1-p_n)/\pi_n. Consider the sets

Sn:={(n,u)∣u≤an}⊆SS_n := \{(n,u) \mid u \leq a_n\} \subseteq S

for all n∈Nn \in\mathbb{N}. In Figure 1, these sets SnS_n form the shaded parts of the columns. By step 4 of the algorithm we have

{Xn=1}={Π∩Sn≠∅}.\{X_n = 1\} = \{\Pi\cap S_n \ne\varnothing\}.

Since Π\Pi is a Poisson process and since the sets SnS_n are disjoint, it follows that the random variables XnX_n are independent.

To show that the XnX_n have the correct distribution, we first write

λn:=Λ(Sn)=πn⋅Leb⁡([0,an])=πnan=−log⁡(1−pn).\lambda_n := \Lambda(S_n) = \pi_n \cdot\operatorname{Leb}([0,a_n]) = \pi_n a_n = -\log(1-p_n).

Using the properties of a Poisson process again we get

#(Π∩Sn)∼Poiss⁡(Λ(Sn))=Poiss⁡(λn)\#(\Pi\cap S_n) \sim\operatorname{Poiss}(\Lambda(S_n)) = \operatorname{Poiss}(\lambda_n)

and thus

P(Xn=1)=P(Π∩Sn≠∅)=1−P(#(Π∩Sn)=0)=1−exp⁡(−λn)=pn,\begin{aligned} P(X_n = 1) &= P(\Pi\cap S_n \ne\varnothing) \\ &= 1 - P(\#(\Pi\cap S_n) = 0) \\ &= 1 - \exp(-\lambda_n) \\ &= p_n, \end{aligned}

as required. This completes the proof.

The following two examples illustrate the algorithm. In the first example every point is accepted, while in the second example some of the points are rejected.

Example 1. In the introduction we considered the case pn=1−e−2−np_n=1-e^{-2^{-n}} for all n∈Nn\in\mathbb{N}. Here we have −log⁡(1−pn)=2−n-\log(1-p_n)=2^{-n} and thus a∗=1a^*=1. We choose πn=−log⁡(1−pn)/a∗=2−n\pi_n=-\log(1-p_n)/a^*=2^{-n}, so that π\pi is the geometric distribution with parameter 1/21/2. This gives an=1a_n=1 for all n∈Nn\in\mathbb{N}, and we can choose a=1a=1. Since the condition Uk≤aNkU_k\le a_{N_k} in step 4 is then always satisfied, the UkU_k are not needed and the algorithm takes the following form: we generate K∼Poiss⁡(1)K\sim\operatorname{Poiss}(1), then we generate N1,…,NKN_1,\ldots,N_K independently from the geometric distribution π\pi, and finally we set Xn=1X_n=1 if and only if n∈{N1,…,NK}n\in\{N_1,\ldots,N_K\}.

Example 2. Let z∈(0,1)z\in(0,1) and pn=znp_n=z^n. Then we have ∑n∈Npn=z/(1−z)<∞\sum_{n\in\mathbb{N}}p_n=z/(1-z)<\infty, so the method can be applied. Choose π\pi to be the geometric distribution with parameter 1−z1-z, that is, πn=zn−1(1−z)\pi_n=z^{n-1}(1-z) for all n∈Nn\in\mathbb{N}. Then we have

an=−log⁡(1−pn)πn=−log⁡(1−zn)zn−1(1−z)=z1−zf(zn).a_n=-\frac{\log(1-p_n)}{\pi_n}=-\frac{\log(1-z^n)}{z^{n-1}(1-z)}=\frac{z}{1-z}f(z^n).

where f(y)=−log⁡(1−y)/yf(y)=-\log(1-y)/y for all y∈(0,1)y\in(0,1). Since f(y)=∑j=0∞yj/(j+1)f(y)=\sum_{j=0}^{\infty}y^j/(j+1), the function ff is monotonically increasing. Thus, the sequence (an)n∈N(a_n)_{n\in\mathbb{N}} is monotonically decreasing and we can choose

a:=a1=−log⁡(1−z)1−z.(2)a:=a_1=-\frac{\log(1-z)}{1-z}. \tag*{(2)}

Using this value of aa, it is easy to implement the method on a computer. One run of the method, for z=0.9z=0.9, is shown in Figure 1.

Efficiency

When implementing the algorithm on a computer, the proposal distribution π\pi should be chosen so that the samples N1,…,NK∼πN_1,\ldots,N_K\sim\pi in step 2 can be generated efficiently.

Lemma 2. A run of Algorithm 1 consumes 2K+12K+1 random numbers, where K∼Poiss⁡(a)K\sim\operatorname{Poiss}(a). In particular, the expected number of random numbers consumed is 2a+12a+1.

Proof. Step 1 of the algorithm consumes one random number, namely KK, and steps 2 and 3 consume KK random numbers each. Step 4 consumes no random numbers. Finally, we have E(K)=aE(K)=a. This completes the proof. □

If each of the random numbers can be generated in a bounded amount of time, and if the same holds for the evaluation of ana_n, the lemma shows that the expected running time and the expected memory use of Algorithm 1 are bounded by a constant times 1+a1+a. The algorithm works for any value of the upper bound aa, but in the light of Lemma 2 the bound aa should be chosen as small as possible.

The constant a∗a^*, defined before Lemma 1, is a lower bound for aa. Since πnan=−log⁡(1−pn)\pi_n a_n=-\log(1-p_n) and an≤aa_n\le a for all n∈Nn\in\mathbb{N}, we have

a∗=∑n∈Nπnan≤a∑n∈Nπn=aa^*=\sum_{n\in\mathbb{N}}\pi_n a_n\le a\sum_{n\in\mathbb{N}}\pi_n=a

for every choice of π\pi and aa which satisfies the conditions of Algorithm 1. Equality holds if and only if an=aa_n=a for all n∈Nn\in\mathbb{N}, and this is the case only for the choice πn=−log⁡(1−pn)/a∗\pi_n=-\log(1-p_n)/a^*. In the general case we have

P(Uk≤aNk)=∑n∈Nπnana=a∗aP(U_k\leq aN_k)=\sum_{n\in\mathbb{N}}\pi_n\frac{a_n}{a}=\frac{a^*}{a}

for every kk, and thus the ratio a∗/aa^*/a is the probability that a point is accepted. Thus, the expected number of accepted points is E(K)a∗/a=a∗E(K)a^*/a=a^*. The algorithm thus generates aa points on average in order to obtain a∗a^* accepted points.

The choice πn=−log⁡(1−pn)/a∗\pi_n=-\log(1-p_n)/a^* minimises the cost, but it can only be used when samples from this distribution can be generated efficiently. This is the case in Example 1, where we have a=a∗=1a=a^*=1 and every point is accepted. In the other examples in this article we choose a distribution π\pi which is easy to sample from, and we then have a>a∗a>a^*.

Example 3. To compare efficiency of the algorithms 0 and 1, we use the number of random samples consumed as a measure for the resource cost of the methods here. Clearly, Algorithm 0 consumes exactly NN random variables, and the value NN increases as the probability of missing one or more events decreases. From Lemma 2 we know that Algorithm 1 uses 2K+12K+1 samples where E(K)=aE(K)=a, so the expected number of random variables used by Algorithm 1 is 2a+12a+1. Algorithm 1 is exact.

For the situation of Example 2, with z=0.9z=0.9, equation (2) gives a=23.026a=23.026 and we get the numerical values

methodcostP(error)P(\mathrm{error})
Algorithm 0, N=50N=50504.538%
Algorithm 0, N=65N=65650.951%
Algorithm 0, N=87N=87870.094%
Algorithm 1≈47\approx47exact

Table 1.

Thus, for the example the exact method will be faster than any useful version of Algorithm 0.

Applications

In this section we apply Algorithm 1 to three examples.

Random Factored Integers

For s>1s>1, a random integer ZZ is zeta-distributed, if it satisfies

P(Z=n)=n−s/ζ(s)P(Z=n)=n^{-s}/\zeta(s)

for all n∈Nn\in\mathbb{N}, where ζ(s)=∑n=1∞n−s\zeta(s)=\sum_{n=1}^{\infty}n^{-s} is the Riemann zeta function. We can construct zeta-distributed values by sampling the prime factorisation of ZZ as follows: for every prime q∈Nq\in\mathbb{N} let νq\nu_q be geometrically distributed with

P(νq=k)=q−sk(1−q−s)P(\nu_q=k)=q^{-sk}(1-q^{-s})

for all k∈N0k\in\mathbb{N}_0, independently for different qq. Let

Z:=∏qqνq,Z:=\prod_q q^{\nu_q},

where the product is finite since, with probability one, only finitely many vqv_q are non-zero. Then, if nn has prime factorisation n=∏qqv~qn = \prod_q q^{\tilde v_q}, we find

P(Z=n)=∏qP(vq=v~q)=∏qq−sv~q(1−q−s)=n−s∏q(1−q−s).P(Z=n)=\prod_q P(v_q=\tilde v_q)=\prod_q q^{-s\tilde v_q}(1-q^{-s})=n^{-s}\prod_q(1-q^{-s}).

Using the Euler product formula we get

P(Z=n)=n−s1ζ(s).P(Z=n)=n^{-s}\frac{1}{\zeta(s)}.

and thus ZZ is zeta-distributed. This representation is classical: Golomb [16] shows that, for a zeta-distributed integer, divisibility by different primes is independent and that the exponent of each prime is geometrically distributed. A recent use of the representation is the ‘zeta process’ of Alexeev et al. [2], which couples the vqv_q for different values of ss. Our aim here is to sample ZZ together with its prime factorisation, i.e. to sample the vqv_q.

Sampling ZZ alone, without its factorisation, is a standard problem, and Devroye [11] gives a rejection method for the zeta distribution, which is called the Zipf distribution there. Recovering the factorisation afterwards requires factoring ZZ, and this is not feasible when ss is close to 1, because ZZ is then typically very large. Indeed, we have

E(log⁡Z)=1ζ(s)∑n=1∞n−slog⁡n=−ζ′(s)ζ(s).E(\log Z)=\frac{1}{\zeta(s)}\sum_{n=1}^{\infty}n^{-s}\log n=-\frac{\zeta'(s)}{\zeta(s)}.

and this expression behaves like 1/(s−1)1/(s-1) as s↓1s\downarrow1.

Alternatively, we could use Algorithm 0, sampling vqv_q for all primes q≤Nq\leq N and setting vq=0v_q=0 for all primes q>Nq>N. The result is wrong whenever a prime larger than NN divides ZZ, and we have

P(vq>0 for some q>N)=1−∏q>N(1−q−s)≈∑q>Nq−s.P(v_q>0\text{ for some }q>N)=1-\prod_{q>N}(1-q^{-s})\approx\sum_{q>N}q^{-s}.

By the prime number theorem, the sum on the right-hand side decays only like N−(s−1)/log⁡NN^{-(s-1)}/\log N as N→∞N\to\infty. In contrast to Example 2, where the corresponding probabilities decay geometrically, a small error probability thus requires a very large value of NN when ss is close to 1.

The corresponding problem for uniformly distributed integers was solved by Bach [4] and, with a simpler algorithm, by Kalai [17]. Both methods generate a random integer together with its prime factorisation, using primality tests in place of factorisation. Bodini and Lumbroso [6] construct samplers for distributions which are defined by Dirichlet series. Their samplers cover the zeta distribution without the factorisation as well as the distribution of a single random prime, but the multiset construction which would be needed for the prime factorisation is deferred to an extended version of their article. To our knowledge, this extended version has not yet appeared.

To apply Algorithm 1, we note that a prime qq divides ZZ if and only if vq>0v_q>0. These events are independent, with

P(vq>0)=q−sP(v_q>0)=q^{-s}

for all primes qq, and we have ∑qq−s≤ζ(s)−1<∞\sum_q q^{-s}\leq\zeta(s)-1<\infty. Thus, the set of primes which divide ZZ is a random set of the kind considered in this article. Once this set is known, the exponents are easy to generate, since

P(vq=k∣vq>0)=q−s(k−1)(1−q−s)(3)P(v_q=k\mid v_q>0)=q^{-s(k-1)}(1-q^{-s}) \tag*{(3)}

for all k∈Nk \in\mathbb{N} is a geometric distribution.

The index set of the events is now the set of primes instead of N\mathbb{N}, and there is no convenient probability distribution π\pi on the primes which we could use in Algorithm 1. We solve this problem by extending the index set: we set pn=n−sp_n = n^{-s} for all integers n≥2n \ge2, whether prime or not, apply Algorithm 1 to this larger family of events and, at the end, discard all indices which are not prime. As a minor optimisation, we treat the prime 2 separately, by sampling ν2\nu_2 directly, and then restrict the algorithm to the odd integers n≥3n \ge3.

To choose the proposal distribution π\pi, let r=2−(s−1)r = 2^{-(s-1)} and, for k∈Nk \in\mathbb{N}, let BkB_k be the set of all odd integers nn with 2k<n<2k+12^k < n < 2^{k+1}. The sets BkB_k are disjoint, each BkB_k has 2k−12^{k-1} elements, and every odd integer n≥3n \ge3 is contained in exactly one of the BkB_k. We define

πn=(1−r)rk−12−(k−1)=(1−r)2−s(k−1)\pi_n = (1-r)r^{k-1}2^{-(k-1)} = (1-r)2^{-s(k-1)}

for all n∈Bkn \in B_k and all k∈Nk \in\mathbb{N}. Since the weights of the elements of BkB_k sum to (1−r)rk−1(1-r)r^{k-1}, this defines a probability distribution. To sample from π\pi, we can first generate k∈Nk \in\mathbb{N} with probabilities (1−r)rk−1(1-r)r^{k-1} and then choose nn uniformly from BkB_k, which requires k−1k-1 random bits.

To find the constant aa, we again use the fact that the function f(y)=−log⁡(1−y)/yf(y)=-\log(1-y)/y from Example 2 is monotonically increasing on (0,1)(0,1). For n∈Bkn \in B_k we have n>2kn > 2^k and n≥3n \ge3, and thus

an=−log⁡(1−n−s)πn=f(n−s)n−s2s(k−1)1−r≤f(3−s)2−s1−r=:a.a_n = \frac{-\log(1-n^{-s})}{\pi_n} = f(n^{-s})\frac{n^{-s}2^{s(k-1)}}{1-r} \le\frac{f(3^{-s})2^{-s}}{1-r} =: a.

As s↓1s \downarrow1 we have 1−r∼(s−1)log⁡21-r \sim(s-1)\log2, and thus aa behaves like c/(s−1)c/(s-1) where c=3log⁡(3/2)/(2log⁡2)≈0.88c=3\log(3/2)/(2\log2)\approx0.88. Combining these choices with Algorithm 1, we obtain the following method, which we call the zeta sampler.

Zeta sampler. Let rr, BkB_k, ana_n and aa be as above.

  1. Generate ν2∈N0\nu_2 \in\mathbb{N}_0 with P(ν2=k)=2−sk(1−2−s)P(\nu_2=k)=2^{-sk}(1-2^{-s}) for all k∈N0k \in\mathbb{N}_0.

  2. Generate K∼Poiss⁡(a)K \sim\operatorname{Poiss}(a).

  3. For i∈{1,…,K}i \in\{1,\ldots,K\}, independently, generate ki∈Nk_i \in\mathbb{N} with P(ki=k)=(1−r)rk−1P(k_i=k)=(1-r)r^{k-1} for all k∈Nk \in\mathbb{N}, choose NiN_i uniformly from BkiB_{k_i}, and generate UiU_i uniformly distributed on [0,a][0,a].

  4. Let II be the set of all NiN_i such that Ui≤aNiU_i \le a_{N_i} and NiN_i is prime.

  5. For every q∈Iq \in I, generate νq∈N\nu_q \in\mathbb{N} with the probabilities given in (3). Set νq=0\nu_q=0 for all odd primes q∉Iq \notin I.

The output of the zeta sampler is the family (νq)(\nu_q) of exponents, and thus the prime factorisation of Z=∏qqνqZ=\prod_q q^{\nu_q}.

In step 4, the condition Ui≤aNiU_i \le a_{N_i} should be checked first, so that the more expensive primality test is only needed for those candidates which satisfy this condition. By Lemma 2, the expected number of candidates NiN_i is aa. A candidate equals nn and satisfies Ui≤anU_i \le a_n with probability πnan/a\pi_n a_n/a, and thus the expected number of primality tests is

∑n≥3n odd−log⁡(1−n−s)≈∑n≥3n oddn−s=(1−2−s)ζ(s)−1,\sum_{\substack{n\ge3\\ n\ \mathrm{odd}}}-\log(1-n^{-s}) \approx\sum_{\substack{n\ge3\\ n\ \mathrm{odd}}} n^{-s} = (1-2^{-s})\zeta(s)-1,

which behaves like 1/(2(s−1))1/(2(s-1)) as s↓1s \downarrow1. The sum on the left-hand side is the constant a∗a^* from section 2.2 for the events with odd index n≥3n \ge3. Since aa behaves like c/(s−1)c/(s-1), the probability a∗/aa^*/a that a candidate is accepted converges to 1/(2c)=log⁡2/(3log⁡(3/2))≈0.571/(2c) = \log2/(3\log(3/2)) \approx0.57 as s↓1s \downarrow1. A candidate from BkB_k has k+1k+1 binary digits, and the expected number of digits is 1+1/(1−r)≈1.44/(s−1)1+1/(1-r) \approx1.44/(s-1). Since the time needed to test an integer for primality is polynomial in the number of digits (Agrawal et al. [1]), the expected running time of the zeta sampler is bounded by a polynomial in 1/(s−1)1/(s-1). This matches the size of the output, since E(log⁡Z)E(\log Z) is also of order 1/(s−1)1/(s-1).

For comparison, we consider the cut-off NN which Algorithm 0 needs in order to achieve an error probability of 1%. By the prime number theorem we have

∑q>Nq−s≈∫M∞x−slog⁡x dx=E1((s−1)log⁡N),\sum_{q>N} q^{-s} \approx\int_M^\infty\frac{x^{-s}}{\log x}\,\mathrm{d}x = E_1((s-1)\log N),

where E1(x)=∫x∞e−t/t dtE_1(x)=\int_x^\infty e^{-t}/t\,\mathrm{d}t is the exponential integral. The error probability equals 1% when the sum equals −log⁡(0.99)-\log(0.99), and since E1(3.207)≈−log⁡(0.99)E_1(3.207)\approx-\log(0.99), the required cut-off is N≈exp⁡(3.207/(s−1))N\approx\exp(3.207/(s-1)), which grows exponentially in 1/(s−1)1/(s-1). We get the following numerical values.

ssaaexpected number of primality testsexpected number of binary digitscut-off NN for Algorithm 0
1.51.340.724.4601
1.18.274.7415.9101410^{14}
1.0187.249.8145.81013910^{139}
1.001876.9499.81444.210139310^{1393}

Table 1 (PDF p. 10).

The cut-off for s=1.5s=1.5 was determined by direct computation, the other values of NN were obtained using the approximation above. For s=1.01s=1.01, for example, the zeta sampler tests on average 50 integers with about 146 binary digits each for primality, whereas Algorithm 0 would need to consider all primes up to 1013910^{139}.

We conclude this section with three remarks. First, the zeta sampler is exact only if the primality test in step 4 is. If a probabilistic method like the test of Rabin [21] is used instead, each composite candidate is accepted as a prime factor with a probability of less than 4−k4^{-k}, where kk is the number of rounds of the test. Second, the proposal distribution used here is not the only possible choice. For example, we could use the zeta distribution itself, conditioned on n≥2n\ge2, as the proposal for all primes including 2. This corresponds to πn=n−s/(ζ(s)−1)\pi_n=n^{-s}/(\zeta(s)-1) and leads to a=(ζ(s)−1)f(2−s)≈1.39/(s−1)a=(\zeta(s)-1)f(2^{-s})\approx1.39/(s-1), which is larger than the value obtained above. Finally, the same method applies to related distributions. If we replace the νq\nu_q by independent random variables with values in {0,1}\{0,1\} and P(νq=1)=q−s/(1+q−s)P(\nu_q=1)=q^{-s}/(1+q^{-s}), then ZZ is square-free with P(Z=n)P(Z=n) proportional to n−sn^{-s} for all square-free nn. Since −log⁡(1−P(νq=1))=log⁡(1+q−s)≤q−s-\log(1-P(\nu_q=1))=\log(1+q^{-s})\le q^{-s}, we can use the same π\pi with a=2−s/(1−r)a=2^{-s}/(1-r). Step 1 changes accordingly, and step 5 is no longer needed. This is a multiplicative analogue of the powersets considered by Peyen [20].

Random Integer Partitions

As another application of Algorithm 1 we consider how to sample from the uniform distribution on all integer partitions of a given size. For an integer partition λ1+⋯+λm\lambda_1+\cdots+\lambda_m, we define

νj=∑i=1∞1{λi=j}.\nu_j=\sum_{i=1}^{\infty}1_{\{\lambda_i=j\}}.

Since the order of the λi\lambda_i does not matter, each integer partition λ=(λ1,…,λm)\lambda= (\lambda_1,\ldots,\lambda_m) corresponds to a unique sequence ν=(νj)j=1∞\nu= (\nu_j)_{j=1}^{\infty}. Let z∈(0,1)z \in(0,1). As shown by Fristedt [14], choosing νj∼Geom⁡(1−zj)\nu_j \sim\operatorname{Geom}(1-z^j) for all j∈Nj \in\mathbb{N}, independently, leads to a distribution of λ\lambda where all partitions of a given size ∣λ∣=λ1+⋯+λm|\lambda| = \lambda_1+\cdots+\lambda_m have the same probability: for a fixed partition λ~\widetilde{\lambda}, corresponding to a sequence ν~\widetilde{\nu} we have

P(λ=λ~)=P(ν=ν~)=∏j=1∞P(νj=ν~j)=∏j=1∞zjν~j(1−zj)=z∑j=1∞jν~j∏j=1∞(1−zj)=z∣λ~∣∏j=1∞(1−zj).\begin{aligned} P(\lambda=\widetilde{\lambda})=P(\nu=\widetilde{\nu})=\prod_{j=1}^{\infty}P(\nu_j=\widetilde{\nu}_j) \\ &=\prod_{j=1}^{\infty}z^{j\widetilde{\nu}_j}(1-z^j)=z^{\sum_{j=1}^{\infty}j\widetilde{\nu}_j}\prod_{j=1}^{\infty}(1-z^j)=z^{|\widetilde{\lambda}|}\prod_{j=1}^{\infty}(1-z^j). \end{aligned}

Since

∑j=1∞P(νj>0)=∑j=1∞zj=z1−z<∞,\sum_{j=1}^{\infty}P(\nu_j>0)=\sum_{j=1}^{\infty}z^j=\frac{z}{1-z}<\infty,

we can use Algorithm 1 to exactly simulate the set

I={j∈N∣νj>0},\mathcal{I}=\{j\in\mathbb{N}\mid\nu_j>0\},

as was demonstrated in Example 2. Then we have

P(νj=k∣j∈I)=P(νj=k∣νj>0)=zjk(1−zj)1−(1−zj)=zj(k−1)(1−zj)P(\nu_j=k\mid j\in\mathcal{I})=P(\nu_j=k\mid\nu_j>0)=\frac{z^{jk}(1-z^j)}{1-(1-z^j)}=z^{j(k-1)}(1-z^j)

for all k∈Nk\in\mathbb{N} and thus for all j∈Ij\in\mathcal{I} we can simply generate νj∼Geom⁡(1−zj)+1\nu_j\sim\operatorname{Geom}(1-z^j)+1, independently. Finally, for all j∉Ij\notin\mathcal{I}, we set νj=0\nu_j=0.

To generate random partitions from the uniform distribution on all partitions of an integer nn, we can now first generate ν\nu as described above, then take the corresponding λ\lambda, and finally condition on ∣λ∣=n|\lambda|=n by rejecting all generated λ\lambda with ∣λ∣≠n|\lambda|\ne n.

While this method works for every z∈(0,1)z\in(0,1), we can tune zz to make the final rejection step more efficient. The average weight of a partition generated by the algorithm is

E(∣λ∣)=E(∑j=1∞jνj)=∑j=1∞jzj1−zj.E(|\lambda|)=E\left(\sum_{j=1}^{\infty}j\nu_j\right)=\sum_{j=1}^{\infty}j\frac{z^j}{1-z^j}.

This expression increases to infinity as z↑1z\uparrow1. Setting δ:=−log⁡z\delta:=-\log z we find

E(∣λ∣)=1δ2∑j=1∞jδe−jδ1−e−jδδE(|\lambda|)=\frac{1}{\delta^2}\sum_{j=1}^{\infty}j\delta\frac{e^{-j\delta}}{1-e^{-j\delta}}\delta

and for z≈1z\approx1 we can use Riemann approximation to get

E(∣λ∣)≈1δ2∫0∞xe−x1−e−x dx=π26δ2=π26log⁡(z)2.E(|\lambda|)\approx\frac{1}{\delta^2}\int_0^\infty x\frac{e^{-x}}{1-e^{-x}}\,dx=\frac{\pi^2}{6\delta^2}=\frac{\pi^2}{6\log(z)^2}.

Thus, for large nn, we can choose z=exp⁡(−π/6n)z=\exp(-\pi/\sqrt{6n}) to get E(∣λ∣)≈nE(|\lambda|)\approx n.

Similarly, the variance is given by

Var⁡(∣λ∣)=∑j=1∞j2Var⁡(νj)=∑j=1∞j2zj(1−zj)2=1δ3∑j=1∞(jδ)2e−jδ(1−e−jδ)2δ≈1δ3∫0∞x2e−x(1−e−x)2 dx=π23δ3.\begin{aligned} \operatorname{Var}(|\lambda|)=\sum_{j=1}^{\infty}j^2\operatorname{Var}(\nu_j)=\sum_{j=1}^{\infty}j^2\frac{z^j}{(1-z^j)^2} \\ &=\frac{1}{\delta^3}\sum_{j=1}^{\infty}(j\delta)^2\frac{e^{-j\delta}}{(1-e^{-j\delta})^2}\delta\\ &\approx\frac{1}{\delta^3}\int_0^\infty x^2\frac{e^{-x}}{(1-e^{-x})^2}\,\mathrm{d}x=\frac{\pi^2}{3\delta^3}. \end{aligned}

Since δ=−log⁡z=π/6n∝n−1/2\delta=-\log z=\pi/\sqrt{6n}\propto n^{-1/2}, we have

Var⁡(∣λ∣)=π23δ3∝n3/2.\operatorname{Var}(|\lambda|)=\frac{\pi^2}{3\delta^3}\propto n^{3/2}.

Let ρ\rho denote the expected number of attempts needed to obtain a partition with ∣λ∣=n|\lambda|=n. Since the acceptance probability is of order 1/sd⁡(∣λ∣)∝n−3/41/\operatorname{sd}(|\lambda|)\propto n^{-3/4}, we have ρ∝n3/4\rho\propto n^{3/4}. The cost of each attempt is determined by the expected number of Poisson points. Since z=e−π/6n≈1−π6nz=e^{-\pi/\sqrt{6n}}\approx1-\frac{\pi}{\sqrt{6n}}, we have

E(K)=a=−log⁡(1−z)1−z≈−log⁡π6nπ6n∝nlog⁡n.E(K)=a=-\frac{\log(1-z)}{1-z}\approx\frac{-\log\frac{\pi}{\sqrt{6n}}}{\frac{\pi}{\sqrt{6n}}}\propto\sqrt{n}\log n.

Thus the overall complexity of the rejection sampling algorithm is

ρ⋅E(K)∝n3/4⋅n1/2log⁡n=n5/4log⁡n.\rho\cdot E(K)\propto n^{3/4}\cdot n^{1/2}\log n=n^{5/4}\log n.

The factor log⁡n\log n is caused by the geometric proposal distribution from Example 2. Using the Riemann approximation again, we find that the lower bound a∗a^* from § 2.2 satisfies

a∗=−∑j=1∞log⁡(1−zj)≈1δ∫0∞−log⁡(1−e−x) dx=π26δ=πn/6,a^*=-\sum_{j=1}^{\infty}\log(1-z^j)\approx\frac{1}{\delta}\int_0^\infty-\log(1-e^{-x})\,\mathrm{d}x=\frac{\pi^2}{6\delta}=\pi\sqrt{n/6},

and thus the probability a∗/aa^*/a that a point is accepted is only of order 1/log⁡n1/\log n. A proposal distribution for which aa is of the same order as a∗a^* would reduce the cost to order n5/4n^{5/4}.

For comparison, Arratia and DeSalvo [3] represent each geometric random variable as a sum of independent Poisson random variables and generate all νj\nu_j from a single Poisson process. This requires of order n\sqrt{n} random numbers per attempt, which is the order of a∗a^*, so that the rejection method has cost of order n5/4n^{5/4}, without the logarithmic factor, and their probabilistic divide-and-conquer method reduces the number of attempts further. For integer partitions, Algorithm 1 thus does not improve on the existing methods. We include the example because it is the simplest application of the algorithm.

Convex Polygonal Lines

A convex polygonal line is a path from the origin (0,0)(0,0) to some endpoint (m1,m2)(m_1,m_2), with vertices in Z2\mathbb{Z}^2 and consisting of segments with strictly increasing slope. As observed by Sinaï [22], such paths are in one-to-one correspondence with finitely supported functions ν:X→N0\nu:\mathcal{X}\to\mathbb{N}_0, where

X={(i1,i2)∈N02∣gcd⁡(i1,i2)=1}\mathcal{X}=\{(i_1,i_2)\in\mathbb{N}_0^2\mid\gcd(i_1,i_2)=1\}

and ν(x)\nu(x) gives the multiplicity of the side in direction xx.

For parameters 0<z1,z2<10 < z_1, z_2 < 1, consider the family of independent random variables (νx)x∈X(\nu_x)_{x \in\mathcal{X}} with geometric distributions, given by

P(νi1,i2=k)=z1ki1z2ki2(1−z1i1z2i2)(4)P(\nu_{i_1,i_2}=k)=z_1^{ki_1}z_2^{ki_2}\left(1-z_1^{i_1}z_2^{i_2}\right) \tag*{(4)}

for all (i1,i2)∈X(i_1,i_2) \in\mathcal{X} and all k∈N0k \in\mathbb{N}_0. The path corresponding to ν\nu has endpoint (m1,m2)=(∑xνxx1,∑xνxx2)(m_1,m_2) = \left(\sum_{x} \nu_x x_1,\sum_{x} \nu_x x_2\right), and all paths with a given endpoint have the same probability: for a fixed ν~\tilde{\nu} with endpoint (m~1,m~2)(\tilde{m}_1,\tilde{m}_2) we have

P(ν=ν~)=∏x∈Xz1ν~xx1z2ν~xx2(1−z1x1z2x2)=z1m~1z2m~2∏x∈X(1−z1x1z2x2),\begin{aligned} P(\nu=\tilde{\nu})=\prod_{x\in\mathcal{X}}z_1^{\tilde{\nu}_x x_1}z_2^{\tilde{\nu}_x x_2}\left(1-z_1^{x_1}z_2^{x_2}\right) \\ &=z_1^{\tilde{m}_1}z_2^{\tilde{m}_2}\prod_{x\in\mathcal{X}}\left(1-z_1^{x_1}z_2^{x_2}\right), \end{aligned}

which does not depend on ν~\tilde{\nu} except via the endpoint of the path.

Our aim is to sample from the random field (νx)x∈X(\nu_x)_{x\in\mathcal{X}} using Algorithm 1. Because there is no simple closed form for the normalizing constant of a probability distribution supported on X\mathcal{X}, it is difficult to apply the algorithm directly to the random field on X\mathcal{X}. However, since the distribution π\pi factorizes as a product of geometric distributions on N2\mathbb{N}^2, we can first extend the random field from X\mathcal{X} to N2\mathbb{N}^2, apply Algorithm 1 there, and then restrict the result back to X\mathcal{X}, as we did for the primes in section 3.1.

As before, we use Algorithm 1 to determine which νx\nu_x should be non-zero, and then sample each non-zero νx\nu_x from the distribution given in (4), conditioned on νx>0\nu_x > 0. For this, let

pi1,i2:=P(νi1,i2≠0)=1−P(νi1,i2=0)=1−(1−z1i1z2i2)=z1i1z2i2.p_{i_1,i_2}:=P(\nu_{i_1,i_2}\ne0)=1-P(\nu_{i_1,i_2}=0)=1-\left(1-z_1^{i_1}z_2^{i_2}\right)=z_1^{i_1}z_2^{i_2}.

Here we choose

πi1,i2=(1−z1)z1i1−1(1−z2)z2i2−1\pi_{i_1,i_2}=(1-z_1)z_1^{i_1-1}(1-z_2)z_2^{i_2-1}

for all (i1,i2)∈N2(i_1,i_2) \in\mathbb{N}^2. Since π\pi is the product of two geometric distributions, it is clear that π\pi is a probability distribution. Furthermore, we have

−log⁡(1−pi1,i2)πi1,i2=−log⁡(1−z1i1z2i2)(1−z1)z1i1−1(1−z2)z2i2−1=z1z2(1−z1)(1−z2)⋅−log⁡(1−z1i1z2i2)z1i1z2i2.\begin{aligned} \frac{-\log(1-p_{i_1,i_2})}{\pi_{i_1,i_2}} = \frac{-\log\left(1-z_1^{i_1}z_2^{i_2}\right)} {(1-z_1)z_1^{i_1-1}(1-z_2)z_2^{i_2-1}} \\ &= \frac{z_1z_2}{(1-z_1)(1-z_2)} \cdot \frac{-\log\left(1-z_1^{i_1}z_2^{i_2}\right)} {z_1^{i_1}z_2^{i_2}}. \end{aligned}

Since y↦−log⁡(1−y)/yy \mapsto-\log(1-y)/y is monotonically increasing on (0,1)(0,1) and z1,z2∈(0,1)z_1,z_2 \in(0,1) we find

−log⁡(1−pi1,i2)πi1,i2≤z1z2(1−z1)(1−z2)⋅−log⁡(1−z1z2)z1z2=−log⁡(1−z1z2)(1−z1)(1−z2)=:a<∞.\begin{aligned} \frac{-\log(1-p_{i_1,i_2})}{\pi_{i_1,i_2}} \le \frac{z_1z_2}{(1-z_1)(1-z_2)} \cdot \frac{-\log(1-z_1z_2)}{z_1z_2} \\ &= \frac{-\log(1-z_1z_2)}{(1-z_1)(1-z_2)} =:a<\infty. \end{aligned}

Thus, we can apply Algorithm 1 with index set N2\mathbb{N}^2 and discard all points (i1,i2)(i_1,i_2) with gcd⁡(i1,i2)≠1\gcd(i_1,i_2)\ne1. By Lemma 2, the expected number of proposals is aa. The set X\mathcal{X} also contains the two points (1,0)(1,0) and (0,1)(0,1), which are not elements of N2\mathbb{N}^2. For these two points we sample ν1,0\nu_{1,0} and ν0,1\nu_{0,1} directly from the geometric distributions in (4).

To generate convex polygonal lines from the uniform distribution on all such lines with a given endpoint (m1,m2)(m_1,m_2), we can proceed as for integer partitions in § 3.2. We first generate ν\nu as described above, then take the corresponding path, and finally reject the path if it does not end at (m1,m2)(m_1,m_2). Since all paths with the same endpoint have the same probability, the accepted path is uniformly distributed. This method works for all z1,z2∈(0,1)z_1,z_2 \in(0,1), but the final rejection step is more efficient if z1z_1 and z2z_2 are chosen so that the expected endpoint of the path is close to (m1,m2)(m_1,m_2).

A note on the use of AI. The original draft, including Sections 2, 3.2 and 3.3, was written by the authors, before large language models existed. The application which is now Section 3.1 was suggested by AI (Anthropic’s Claude), and AI was also used to help with the literature review, to polish the presentation, and to write the Python script which in turn produced Figure 1.

References

  1. [1]M. Agrawal, N. Kayal, and N. Saxena. PRIMES is in P. Annals of Mathematics, 160 (2004), no. 2, 781–793. doi:10.4007/annals.2004.160.781DOI
  2. [2]B. Alexeev, K. Barreto, Y. Li, J. D. Lichtman, L. Price, J. I. Shah, Q. Tang, and T. Tao. Primitive sets and von Mangoldt chains: Erdős problem #1196 and beyond (2026). https://arxiv.org/abs/2605.00301
  3. [3]R. Arratia and S. DeSalvo. Probabilistic divide-and-conquer: A new exact simulation method, with integer partitions as an example. Combinatorics, Probability and Computing, 25 (2016), no. 3, 324–351. doi:10.1017/S0963548315000358DOI
  4. [4]E. Bach. How to generate factored random numbers. SIAM Journal on Computing, 17 (1988), no. 2, 179–193. doi:10.1137/0217012DOI
  5. [5]A. Beskos, O. Papaspiliopoulos, and G. O. Roberts. Retrospective exact simulation of diffusion sample paths with applications. Bernoulli, 12 (2006), no. 6, 1077–1098. doi:10.3150/bj/1165269151DOI
  6. [6]O. Bodini and J. Lumbroso. Dirichlet random samplers for multiplicative structures. In 2012 Proceedings of the Ninth Workshop on Analytic Algorithmics and Combinatorics (ANALCO). Society for Industrial and Applied Mathematics (2012) pp. 92–106. doi:10.1137/1.9781611973020.12DOI
  7. [7]L. V. Bogachev. Unified derivation of the limit shape for multiplicative ensembles of random integer partitions with equiweighted parts. Random Structures & Algorithms, 47 (2015), no. 2, 227–266. doi:10.1002/rsa.20540DOI
  8. [8]L. V. Bogachev, A. V. Gnedin, and Y. V. Yakubovich. On the variance of the number of occupied boxes. Advances in Applied Mathematics, 40 (2008), no. 4, 401–432. doi:10.1016/j.aam.2007.05.002DOI
  9. [9]L. V. Bogachev and S. M. Zarbaliev. Universality of the limit shape of convex lattice polygonal lines. The Annals of Probability, 39 (2011), no. 6, 2271–2317. doi:10.1214/10-AOP607DOI
  10. [10]S. DeSalvo. Improvements to exact Boltzmann sampling using probabilistic divide-and-conquer and the recursive method. Pure Mathematics and Applications, 26 (2017), no. 1, 22–45. doi:10.1515/puma-2015-0020DOI
  11. [11]L. Devroye. Non-uniform random variate generation. Springer-Verlag, New York (1986). doi:10.1007/978-1-4613-8643-8DOI
  12. [12]P. Duchon, P. Flajolet, G. Louchard, and G. Schaeffer. Boltzmann samplers for the random generation of combinatorial structures. Combinatorics, Probability and Computing, 13 (2004), no. 4-5, 577–625. doi:10.1017/S0963548304006315DOI
  13. [13]P. Flajolet, É. Fusy, and C. Pivoteau. Boltzmann sampling of unlabelled structures. In Proceedings of the Fourth Workshop on Analytic Algorithmics and Combinatorics (ANALCO). Society for Industrial and Applied Mathematics (2007) pp. 201–211. doi:10.1137/1.9781611972979.5DOI
  14. [14]B. Fristedt. The structure of random partitions of large integers. Transactions of the American Mathematical Society, 337 (1993), no. 2, 703–735. doi:10.1090/S0002-9947-1993-1094553-1DOI
  15. [15]A. Gnedin, B. Hansen, and J. Pitman. Notes on the occupancy problem with infinitely many boxes: general asymptotics and power laws. Probability Surveys, 4 (2007), 146–171. doi:10.1214/07-PS092DOI
  16. [16]S. W. Golomb. A class of probability distributions on the integers. Journal of Number Theory, 2 (1970), no. 2, 189–192. doi:10.1016/0022-314X(70)90018-1DOI
  17. [17]A. Kalai. Generating random factored numbers, easily. Journal of Cryptology, 16 (2003), no. 4, 287–289. doi:10.1007/s00145-003-0051-5DOI
  18. [18]J. F. C. Kingman. Poisson processes, volume 3 of Oxford Studies in Probability. Clarendon Press (1993).DOI
  19. [19]P. A. W. Lewis and G. S. Shedler. Simulation of nonhomogeneous Poisson processes by thinning. Naval Research Logistics Quarterly, 26 (1979), no. 3, 403–413. doi:10.1002/nav.3800260304DOI
  20. [20]J. C. Peyen. Oracle-free Boltzmann sampling for powersets (2026). https://arxiv.org/abs/2601.09508
  21. [21]M. O. Rabin. Probabilistic algorithm for testing primality. Journal of Number Theory, 12 (1980), no. 1, 128–138. doi:10.1016/0022-314x(80)90084-0DOI
  22. [22]Y. G. Sinaï. Probabilistic approach to the analysis of statistics for convex polygonal lines. Functional Analysis and its Applications, 28 (1994), no. 2, 108–113. Russian original: Funktsional. Anal. i Prilozhen. 28 (1994), no. 2, 41–48. doi:10.1007/BF01076497DOI
  23. [23]A. M. Vershik. Statistical mechanics of combinatorial partitions, and their limit shapes. Functional Analysis and its Applications, 30 (1996), no. 2, 90–105. Russian original: Funktsional. Anal. i Prilozhen. 30 (1996), no. 2, 19–39. doi:10.1007/BF02509449DOI

Paper details

vlnc:W_55kw3bet
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 3

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Mathematics

Not recorded for this paper

View statement
Looking for related papers…
Contents