Introduction
The scale of modern data systems often makes it infeasible to store or repeatedly process an entire dataset. In many settings, such as network monitoring and large-scale database systems, data instead arrives as a continuous stream of updates. The streaming model of computation formalizes this setting by requiring algorithms to process the input using memory far smaller than the size of the data itself. In the standard turnstile model, the stream implicitly defines a high-dimensional frequency vector x ∈ R n x \in\mathbb{R}^n x ∈ R n that is initialized to the all zeros vector and evolves through updates of the form x i ← x i + Δ x_i \gets x_i + \Delta x i ← x i + Δ , where Δ \Delta Δ may be positive or negative. This model naturally captures dynamic settings in which data is both inserted and deleted, such as updates to database records or changes in network traffic.
A central goal in the streaming model is to design primitives that extract useful information from the frequency vector while respecting stringent space constraints. One particularly powerful primitive is L p L_p L p sampling, which returns an index i ∈ [ n ] i \in[n] i ∈ [ n ] with probability proportional to ( 1 ± ε ) ⋅ ∣ x i ∣ p ∥ x ∥ p p + 1 poly ( n ) (1 \pm\varepsilon) \cdot\frac{|x_i|^p}{\lVert x \rVert_p^p} + \frac{1}{\operatorname{poly}(n)} ( 1 ± ε ) ⋅ ∥ x ∥ p p ∣ x i ∣ p + poly ( n ) 1 . Informally, an L p L_p L p sampler selects coordinates according to their contribution to the p p p -th frequency moment, biasing the sample toward larger entries as p p p increases. The sampler is called perfect if ε = 0 \varepsilon= 0 ε = 0 and approximate otherwise. Because L p L_p L p sampling captures structure in the frequency vector beyond global aggregates by extracting representative coordinates according to the geometry induced by the L p L_p L p norm, L p L_p L p sampling has emerged as a powerful primitive in a variety of sublinear and streaming algorithms. In particular, it has found applications in a broad spectrum of settings, including network monitoring and anomaly detection [11 HNG+07, 14 , 44 , 33 ] , distributed computation frameworks [7 , 46 JSTW19, 49 , 4 ] , database query processing tasks [20 , 31 GM98, 5 , 40 , 18 , 30 , 21 ] , and techniques for compact representation and summarization of large datasets [12 , 9 , 10 , 1 , 23 , 34 , 8 , 22 MRWZ20, 29 , 38 , 16 , 36 , 32 ] . Despite this broad applicability, the complexity and behavior of L p L_p L p sampling depend strongly on the choice of p p p , and different regimes require fundamentally different algorithmic ideas.
Among the family of L p L_p L p samplers, the case p = 2 p=2 p = 2 occupies a particularly important position. From a geometric perspective, the L 2 L_2 L 2 norm underlies Euclidean structure and is therefore deeply connected to many algorithmic techniques based on linear algebra and sketching. Within database systems, the second frequency moment F 2 = ∥ x ∥ 2 2 F_2=\lVert x\rVert_2^2 F 2 = ∥ x ∥ 2 2 corresponds directly to self-join size, making L 2 L_2 L 2 sampling a natural primitive for approximate query processing, join estimation, and regression over joins without explicitly materializing them, where sampling-based techniques are commonly used [27 ] . Moreover, it is used in a number of subroutines such as streaming algorithms for L p L_p L p norm estimation for p > 2 p>2 p > 2 [50 , 48 ] . Thus, progress on L 2 L_2 L 2 sampling directly influences the complexity of a much broader class of problems. In particular, p = 2 p=2 p = 2 is the largest exponent for which polylogarithmic space L p L_p L p sampling is possible, as Ω ~ ( n 1 − 2 / p ) \widetilde{\Omega}(n^{1-2/p}) Ω ( n 1 − 2/ p ) space is necessary for p > 2 p>2 p > 2 [15 , 48 , 24 ] .
Previous work. Despite its central role, constructing efficient L p L_p L p samplers has been well-studied in the streaming literature. In the insertion-only setting, the classical reservoir sampling technique [47 ] gives an exact L 1 L_1 L 1 sampler using O ( log n ) O(\log n) O ( log n ) bits of space with no distortion, both multiplicative and additive. However, beyond the L 1 L_1 L 1 case or outside insertion-only streams, the problem becomes significantly more complex and the question of whether such samplers exist was explicitly posed by [6 ] , and subsequently resolved in the affirmative for p ≤ 2 p\leq2 p ≤ 2 in the approximate setting [37 ] . These initial constructions used poly ( 1 / ε , log n ) \operatorname{poly}(1/\varepsilon,\log n) poly ( 1/ ε , log n ) space, and were later improved to near-optimal bounds by [2 ] and by [25 ] , achieving roughly O ( 1 ε max ( 1 , p ) log 2 n ) O\left(\frac{1}{\varepsilon^{\max(1,p)}}\log^2 n\right) O ( ε m a x ( 1 , p ) 1 log 2 n ) space for p ∈ ( 0 , 2 ) p\in(0,2) p ∈ ( 0 , 2 ) and O ( 1 ε 2 log 3 n ) O\left(\frac{1}{\varepsilon^2}\log^3 n\right) O ( ε 2 1 log 3 n ) for p = 2 p=2 p = 2 . While these results established near-optimal space complexity for approximate sampling, they left open finer questions regarding distortion and randomness requirements. This gap was later resolved by [28 ] , who introduced the first perfect L p L_p L p samplers for p ∈ ( 0 , 2 ) p\in(0,2) p ∈ ( 0 , 2 ) with O ~ ( log 2 n ) \widetilde{O}(\log^2 n) O ( log 2 n ) space and for p = 2 p=2 p = 2 with O ~ ( log 3 n ) \widetilde{O}(\log^3 n) O ( log 3 n ) space.
Update time. Despite resolving the space complexity, the algorithms of [28 ] and related work [5 ] suffer from a severe computational bottleneck, duplicating each coordinate n c n^c n c times and assigning each copy an independent exponential weight. Consequently, a single update requires Ω ( n c ) \Omega(n^c) Ω ( n c ) structural operations, so that the update time per element is polynomial in n n n , which can be prohibitively large in many settings. This sparked work on fast perfect L p L_p L p sampling. For insertion-only streams, [41 ] achieved O ( 1 ) O(1) O ( 1 ) update time for p ≤ 1 p\leq1 p ≤ 1 in the random oracle model. Subsequently, [43 ] introduced a continuous simulation framework for general turnstile streams, achieving polylogarithmic update time for p < 2 p<2 p < 2 . Unfortunately, the framework of [43 ] does not extend to the critical case p = 2 p=2 p = 2 , where the limiting behavior underlying the continuous simulation approach changes qualitatively and the techniques used for p < 2 p<2 p < 2 no longer apply (see § 3 for more details).
At first glance, this distinction may appear to be merely a change of regime. However, the situation is less clear from a complexity perspective. Indeed, while a combination of techniques from [24 , 42 ] showed an Ω ( log 3 n ) \Omega(\log^3 n) Ω ( log 3 n ) space lower bound for perfect L 2 L_2 L 2 sampling, perfect samplers for p < 2 p < 2 p < 2 are known using only O ~ ( log 2 n ) \widetilde{O}(\log^2 n) O ( log 2 n ) space [28 , 43 ] . Thus, it is natural to ask whether the additional memory complexity of the L 2 L_2 L 2 regime fundamentally obstructs fast algorithms, or whether one can still achieve polylogarithmic update time while maintaining optimal space.
Our contributions. In this paper, we resolve the open question of whether perfect L 2 L_2 L 2 sampling admits both optimal space and fast update time in the turnstile model. We introduce a new approach for implementing perfect L 2 L_2 L 2 sampling without relying on the explicit polynomial duplication used in previous constructions to achieve the first perfect L 2 L_2 L 2 sampler with expected polylogarithmic update time and optimal space complexity.
Theorem 1.1. Given a sequence of turnstile updates defining a frequency vector x ∈ R n x \in\mathbb{R}^n x ∈ R n , and a failure probability parameter δ ∈ ( 0 , 1 ) \delta\in(0,1) δ ∈ ( 0 , 1 ) , there exists a perfect L 2 L_2 L 2 sampler that outputs a failure symbol ⊥ \perp ⊥ with probability at most δ \delta δ . Conditioned on returning an index i ∗ ∈ [ n ] i^* \in[n] i ∗ ∈ [ n ] ,
Pr [ i ∗ = j ] = x j 2 ∥ x ∥ 2 2 ± 1 poly ( n ) . \Pr[i^* = j] = \frac{x_j^2}{\lVert x\rVert_2^2} \pm\frac{1}{\operatorname{poly}(n)}. Pr [ i ∗ = j ] = ∥ x ∥ 2 2 x j 2 ± poly ( n ) 1 . The algorithm uses O ~ ( log 3 n log 1 δ ) \widetilde{O}\left(\log^3 n \log\frac{1}{\delta}\right) O ( log 3 n log δ 1 ) bits of space and processes each stream update in polylog ( n ) \operatorname{polylog}(n) polylog ( n ) time in expectation.
We remark that the output ⊥ \perp ⊥ corresponds to a failure event that occurs with probability at most δ \delta δ ; this is standard in perfect sampling constructions and can be reduced arbitrarily by repetition without affecting the conditional sampling guarantee. Conceptually, our result shows that the additional complexity of the L 2 L_2 L 2 regime does not fundamentally obstruct efficient algorithms. Although the methods developed for p < 2 p < 2 p < 2 do not directly extend to p = 2 p = 2 p = 2 , we show that this qualitative change in behavior need not incur an algorithmic penalty. Thus, despite occupying a distinct space complexity regime, perfect L 2 L_2 L 2 sampling remains achievable with both optimal space and efficient updates.
Motivation and Applications
Statistical indistinguishability. Sampling is a fundamental primitive for extracting information from massive datasets. In particular, L 2 L_2 L 2 sampling has been used as a subroutine for central streaming tasks such as heavy-hitters, norm and moment estimation, duplicate detection, and data summarization [37 , 2 , 25 , 3 , 28 ] . Since these summaries effectively represent the dataset itself, it is important that the samples accurately reflect the target distribution. Approximate samplers permit multiplicative distortion in the sampling probabilities. While this distortion may be small for an individual sample, the effect can accumulate when many samples are repeatedly combined or reused throughout a larger computational pipeline. Consequently, hidden statistical bias may propagate into downstream procedures and alter their behavior. Perfect L 2 L_2 L 2 samplers avoid this issue by reducing the additive distortion in the output distribution to an arbitrarily small inverse-polynomial quantity while preserving essentially the same asymptotic space complexity. For example, if an application extracts n c n^c n c samples for some constant c > 0 c > 0 c > 0 , then choosing an additive error of n − ( c + 100 ) n^{-(c+100)} n − ( c + 100 ) ensures that the resulting joint distribution remains statistically indistinguishable from one obtained using truly exact samples. This makes perfect samplers particularly attractive as reusable black-box primitives.
Distributed databases and query processing. The distinction between approximate and perfect sampling becomes especially important in distributed database systems. Modern data processing architectures partition datasets across many machines, where local summaries are constructed independently and later combined into global estimates. Sampling provides a natural mechanism for constructing such summaries while avoiding communication of the raw data itself. However, local inaccuracies need not remain local. Even small distortions introduced by approximate samplers can accumulate when summaries are merged, reused, or incorporated into later stages of processing. This phenomenon is particularly relevant in relational settings involving repeated statistical estimation, joins, and self-join computations, where the output of one randomized procedure often becomes the input to another. Perfect samplers substantially reduce such accumulated bias and therefore preserve the fidelity of both local and global statistical summaries.
Information leakage and adaptive interaction. Approximate sampling probabilities may also reveal unintended information about the underlying dataset. Since the permitted multiplicative distortion can depend on global properties of the data, repeated observations of samples may allow an observer to infer information beyond the sampled index itself. For instance, suppose a sampler increases the total probability mass of a large set of coordinates by a factor of ( 1 + ε ) (1+\varepsilon) ( 1 + ε ) whenever a property P \mathcal{P} P holds and decreases it by ( 1 − ε ) (1-\varepsilon) ( 1 − ε ) otherwise. Then an observer could estimate whether P \mathcal{P} P holds simply by collecting sufficiently many samples and measuring aggregate frequencies. Perfect L 2 L_2 L 2 samplers mitigate this issue because their output distributions differ from the ideal distribution only by an arbitrarily small additive amount. As a result, repeated interactions with the sampler reveal essentially no additional information beyond that inherent to the target distribution itself.
Algorithmic and Technical Overview
In this section, we provide an overview of our algorithmic framework and the technical novelties required to achieve polylogarithmic update time for perfect L 2 L_2 L 2 sampling, c.f., Figure 1. To contextualize our approach, it is instructive to first review the mechanics and limitations of previous sampling frameworks before explaining how we overcome them.
Exponential random variables and duplication. The standard approach [28 , 43 , 48 ] for perfect L p L_p L p sampling involves scaling each stream coordinate x i x_i x i by an inverse exponential random variable e i − 1 / p e_i^{-1/p} e i − 1/ p . Due to the max-stability property of exponential random variables [2 ] , the probability that coordinate i ∈ [ n ] i \in[n] i ∈ [ n ] yields the largest scaled value ∣ x i ∣ e i 1 / p \frac{|x_i|}{e_i^{1/p}} e i 1/ p ∣ x i ∣ is exactly ∣ x i ∣ p ∥ x ∥ p p \frac{|x_i|^p}{\lVert x\rVert_p^p} ∥ x ∥ p p ∣ x i ∣ p . To recover this maximum element in a data stream, the coordinate is identified using a heavy-hitters data structure such as CountSketch, coupled with a statistical test to ensure the maximum is reliably isolated from the background noise. However, the probability of passing this test is heavily correlated with the identity of the maximum element itself, distorting the sampling probabilities by an Ω ( 1 ) \Omega(1) Ω ( 1 ) multiplicative bias that destroys the “perfect” sampling guarantee. To handle this issue, [28 ] duplicated each coordinate i ∈ [ n ] i \in[n] i ∈ [ n ] a total of k = n C k = n^{C} k = n C times, scaling each duplicate by its own independent exponential random variable. This flattens the background noise so that the statistical test becomes nearly independent of the identity of the maximum element, recovering the desired perfect sampling distribution. Unfortunately, explicitly routing n C n^{C} n C duplicate coordinates into the sketch requires a prohibitively high update time of Ω ( n C ) \Omega(n^{C}) Ω ( n C ) .
Algorithm Pipeline: Fast Perfect L 2 L_2 L 2 Sampling
Explicit Head: Conceptually duplicate each update n C n^{C} n C times, but explicitly generate only the top τ = Θ ( log n ) \tau= \Theta(\log n) τ = Θ ( log n ) exponential weights.
Tail Simulation: Compress the remaining copies into a variance V t a i l V_{\mathrm{tail}} V tail , sampled via fast quadrature of its 1-stable continuous CDF.
Sketch Injection: Update a dense Gaussian CountSketch, injecting the head directly and the aggregate tail as a single N ( 0 , V t a i l ) \mathcal{N}(0,V_{\mathrm{tail}}) N ( 0 , V tail ) .
Recovery: Run a statistical test and extract the maximum coordinate if it succeeds.
Fig. 1: Overview of the framework, reducing update time to an expected poly ( log n ) \operatorname{poly}(\log n) poly ( log n ) .
Algorithmic framework: explicit heads and simulated tails. Our goal is to preserve the exact statistical behavior of this duplication process while avoiding its explicit realization. Our approach is based on a simple structural observation: although the duplicated coordinates are numerous, only a small number contribute significantly to the sketch on any given update. We therefore separate the duplicated copies into two components. For a coordinate i ∈ [ n ] i \in[n] i ∈ [ n ] , the largest τ = Θ ( log n ) \tau= \Theta(\log n) τ = Θ ( log n ) duplicated coordinates are generated and maintained explicitly (the “head”), while the remaining m = k − τ m = k - \tau m = k − τ coordinates are aggregated into a single random contribution (the “tail”).
Crucially, this decomposition integrates seamlessly into the sketching framework. Following the approach of [43 ] , we utilize a dense Gaussian CountSketch. Because Gaussian random variables are exactly 2-stable, the aggregate contribution of the uninstantiated tail duplicates in each sketch row behaves identically to a single Gaussian variable N ( 0 , V t a i l ) \mathcal{N}(0,V_{\mathrm{tail}}) N ( 0 , V tail ) . Rather than explicitly materializing the m m m tail coordinates, we can compress their contribution into a single sampled variance parameter V t a i l V_{\mathrm{tail}} V tail . Thus, as detailed in Algorithm 1, the algorithm maintains only the explicit heavy coordinates H i \mathcal{H}_i H i , while the remaining copies are implicitly injected into the sketch through the sampled tail variance.
The explicit heavy coordinates H i \mathcal{H}_i H i and the necessary truncation parameters can be generated efficiently using standard properties of exponential spacings, as shown in Algorithm 2.
Sampling the continuous tail distribution and the L 2 L_2 L 2 barrier. The core algorithmic challenge lies in generating the variance parameter V t a i l V_{\mathrm{tail}} V tail . We simulate the sum of the tail variables V = ∑ j = 1 m e i , j V = \sum_{j=1}^{m} e_{i,j} V = ∑ j = 1 m e i , j as a single random draw from its limiting continuous distribution, Z \mathcal{Z} Z . We perform this via inverse transform sampling (Algorithm 3): we draw U ∼ Unif ( 0 , 1 ) U \sim\operatorname{Unif}(0,1) U ∼ Unif ( 0 , 1 ) and compute z ∗ z^* z ∗ such that F Z ( z ∗ ) ≈ U F_{\mathcal{Z}}(z^*) \approx U F Z ( z ∗ ) ≈ U , where F Z F_{\mathcal{Z}} F Z is the Cumulative Distribution Function (CDF) of the limiting tail.
To evaluate F Z ( x ) F_{\mathcal{Z}}(x) F Z ( x ) efficiently inside the binary search, we must rely on numerical inversion of the Gil-Pelaez integral. This requires obtaining the characteristic function of the tail distribution.
Algorithm 1 Perfect L 2 L_2 L 2 stream update processing
Input: Stream update ( i , Δ ) (i, \Delta) ( i , Δ )
Output: Update the dense CountSketch associated with coordinate i i i
r = O ( log 2 n ) r = \mathcal{O}\left(\log^2 n\right) r = O ( log 2 n ) , τ = O ( log n ) \tau= \mathcal{O}(\log n) τ = O ( log n ) , k = n C k = n^C k = n C
Generate ( H i , V t a i l ) (\mathcal{H}_i, V_{\mathrm{tail}}) ( H i , V tail ) using Algorithm 2
for each row ℓ ∈ [ R ] \ell\in[R] ℓ ∈ [ R ] do
for each ( j , Y ( j ) ) ∈ H i (j, Y_{(j)}) \in\mathcal{H}_i ( j , Y ( j ) ) ∈ H i do
Draw g ℓ , i , j ∼ N ( 0 , 1 ) g_{\ell,i,j} \sim\mathcal{N}(0,1) g ℓ , i , j ∼ N ( 0 , 1 )
Update row ℓ \ell ℓ by Δ ⋅ g ℓ , i , j ⋅ Y ( j ) \Delta\cdot g_{\ell,i,j} \cdot\sqrt{Y_{(j)} } Δ ⋅ g ℓ , i , j ⋅ Y ( j )
Draw g ℓ , i , t a i l ∼ N ( 0 , 1 ) g_{\ell,i,\mathrm{tail}} \sim\mathcal{N}(0,1) g ℓ , i , tail ∼ N ( 0 , 1 )
Update row ℓ \ell ℓ by Δ ⋅ g ℓ , i , t a i l ⋅ V t a i l \Delta\cdot g_{\ell,i,\mathrm{tail}} \cdot\sqrt{V_{\mathrm{tail}}} Δ ⋅ g ℓ , i , tail ⋅ V tail
Algorithm 2 Generation of heavy coordinates and tail variance
Input: Coordinate i i i , duplication count k k k , truncation parameter τ \tau τ from Algorithm 1
Output: ( H i , V t a i l ) (\mathcal{H}_i, V_{\mathrm{tail}}) ( H i , V tail )
Seed a pseudorandom generator using the instance ID and coordinate i i i
Generate δ 1 , … , δ τ ∼ Exp ( 1 ) \delta_1,\ldots,\delta_\tau\sim\operatorname{Exp}(1) δ 1 , … , δ τ ∼ Exp ( 1 )
Generate order statistics
E D ( j ) = E D ( j − 1 ) + δ j k − j + 1 , E D ( 0 ) = 0 E_{D(j)} = E_{D(j-1)} + \frac{\delta_j}{k-j+1}, \qquad E_{D(0)}=0 E D ( j ) = E D ( j − 1 ) + k − j + 1 δ j , E D ( 0 ) = 0
Set H i = { ( j , 1 E D ( j ) ) } j ∈ [ τ ] \mathcal{H}_i = \left\{\left(j,\frac{1}{E_{D(j)}}\right)\right\}_{j\in[\tau]} H i = { ( j , E D ( j ) 1 ) } j ∈ [ τ ] and draw U ∼ Unif ( 0 , 1 ) U \sim\operatorname{Unif}(0,1) U ∼ Unif ( 0 , 1 )
m ← k − τ m \leftarrow k-\tau m ← k − τ and R ← 1 E D ( τ ) ⋅ m R \leftarrow\frac{1}{E_{D(\tau)}\cdot m} R ← E D ( τ ) ⋅ m 1
Compute z ∗ z^* z ∗ via inverse CDF using Algorithm 3
Set V t a i l ← max ( 0 , m ( z ∗ + ln m ) ) V_{\mathrm{tail}} \leftarrow\max(0,m(z^*+\ln m)) V tail ← max ( 0 , m ( z ∗ + ln m ))
Return ( H i , V t a i l ) (\mathcal{H}_i,V_{\mathrm{tail}}) ( H i , V tail )
Algorithm 3 Inverse CDF via binary search
Input: U ∈ ( 0 , 1 ) U \in(0,1) U ∈ ( 0 , 1 ) , interval [ ℓ , u ] = [ − O ( log n ) , O ( log n ) ] [\ell,u]=[-\mathcal{O}(\log n),\mathcal{O}(\log n)] [ ℓ , u ] = [ − O ( log n ) , O ( log n )]
Output: z ∗ z^* z ∗ such that F Z ( z ∗ ) ≈ U F_Z(z^*)\approx U F Z ( z ∗ ) ≈ U
while u − ℓ > 1 n O ( C + c ) u-\ell> \frac{1}{n^{\mathcal{O}(C+c)}} u − ℓ > n O ( C + c ) 1 do
m ← ℓ + u 2 m \leftarrow\frac{\ell+u}{2} m ← 2 ℓ + u
if CDF ( m ) < U \operatorname{CDF}(m)<U CDF ( m ) < U then ▹ CDF ( x ) \triangleright\operatorname{CDF}(x) ▹ CDF ( x ) denotes F Z ( x ) F_Z(x) F Z ( x ) evaluated via Algorithm 5
ℓ ← m \ell\leftarrow m ℓ ← m
else
u ← m u \leftarrow m u ← m
Draw W ∼ Unif ( 0 , 1 ) W \sim\operatorname{Unif}(0,1) W ∼ Unif ( 0 , 1 )
return ℓ + W ( u − ℓ ) \ell+W(u-\ell) ℓ + W ( u − ℓ )
This introduces the main technical barrier distinguishing perfect L 2 L_2 L 2 sampling from prior work.
For p < 2 p<2 p < 2 [43 ] , the sum of the tail elements V = ∑ j = 1 m e i , j − 2 / p V=\sum_{j=1}^{m}e_{i,j}^{-2/p} V = ∑ j = 1 m e i , j − 2/ p has a heavy tail that converges tightly to a p 2 \frac{p}{2} 2 p -stable distribution. Because p 2 < 1 \frac{p}{2}<1 2 p < 1 , its characteristic function is well-behaved near the origin, allowing the CDF to be evaluated directly using standard quadrature in polylogarithmic time. However, for the p = 2 p=2 p = 2 regime, the variables e i , j − 1 e_{i,j}^{-1} e i , j − 1 are inverse standard exponentials, which have infinite expectation. Consequently, as the number of tail items m m m grows, the sum V V V diverges at a rate of m ln m m\ln m m ln m rather than converging to a standard stable limit. This is not merely a different analytic computation; the logarithmic divergence causes the limiting distribution to be exactly 1-stable, where the characteristic function develops a non-integrable logarithmic singularity near the origin in the Fourier domain. Because standard numerical integration techniques require analytic or sufficiently smooth integrands, the singularity at this 1-stable boundary causes classical numerical quadrature to either require exponential time to converge or fail outright.
Recentering and delaying the limit. To stabilize this divergence, we recenter the sum by defining the random variable Z m = 1 m ∑ j = 1 m e i , j − 1 − ln m Z_m=\frac{1}{m}\sum_{j=1}^{m}e_{i,j}^{-1}-\ln m Z m = m 1 ∑ j = 1 m e i , j − 1 − ln m . Unlike the p < 2 p<2 p < 2 regime, where the limiting characteristic function possesses an integrable singularity that evaluates cleanly to an incomplete Gamma function, the p = 2 p=2 p = 2 boundary results in a 1-stable limit with a non-integrable logarithmic singularity (∼ 1 / u \sim1/u ∼ 1/ u ) at the origin in the Fourier domain. Naïvely recentering the random variable and taking the continuous limit fails because this non-integrable singularity prevents the exchange of the limit and the integral, breaking the standard numerical quadrature required for fast evaluation. We overcome this barrier by delaying the limit and performing analytic surgery at a finite tail size m m m . By considering the characteristic function Ψ ( t ) = E [ e i t Z m ] \Psi(t)=\mathbb{E}\left[e^{itZ_m}\right] Ψ ( t ) = E [ e i t Z m ] for finite m m m , we observe that we can express its core integral as:
∫ ( e i t u − 1 ) u − 2 e − 1 / ( u m ) d u = ∫ [ ( e i t u − 1 − i t u ) + i t u ] u − 2 e − 1 / ( u m ) d u . \int\left(e^{itu}-1\right)u^{-2}e^{-1/(um)}\,du=\int\left[\left(e^{itu}-1-itu\right)+itu\right]u^{-2}e^{-1/(um)}\,du. ∫ ( e i t u − 1 ) u − 2 e − 1/ ( u m ) d u = ∫ [ ( e i t u − 1 − i t u ) + i t u ] u − 2 e − 1/ ( u m ) d u .
By explicitly isolating the singular linear term i t u itu i t u , the extracted component i t ∫ 1 u e − 1 / ( u m ) d u it\int\frac{1}{u}e^{-1/(um)}\,du i t ∫ u 1 e − 1/ ( u m ) d u evaluates exactly to an Exponential Integral (E 1 E_1 E 1 ). Using its asymptotic expansion via the Entire Exponential Integral (Ein \operatorname{Ein} Ein ), E 1 ( z ) = − γ − ln z + Ein ( z ) E_1(z)=-\gamma-\ln z+\operatorname{Ein}(z) E 1 ( z ) = − γ − ln z + Ein ( z ) , it naturally generates a + i t ln m +it\ln m + i t ln m phase shift. This algebraically annihilates the algorithmic − i t ln m -it\ln m − i t ln m recentering penalty before taking m → ∞ m\to\infty m → ∞ . Thus, delaying the limit completely removes the logarithmic divergence, leaving a smooth, bounded remainder defined by Sine and Cosine Integrals that permits fast Gauss–Legendre quadrature.
Trigonometric integrals and fast quadrature. After cancellation, the remaining regularized expression becomes ∫ 0 R e i t u − 1 − i t u u 2 d u \int_{0}^{R}\frac{e^{itu}-1-itu}{u^{2}}\,du ∫ 0 R u 2 e i t u − 1 − i t u d u , where R R R is the truncation parameter for the magnitude of the tail elements. This differs substantially from the p < 2 p<2 p < 2 setting, which resolves into incomplete Gamma functions. Instead, applying integration by parts transforms the expression into e i t R − 1 R \frac{e^{itR}-1}{R} R e i tR − 1 , yielding real and imaginary parts ∫ cos ( t u ) − 1 u d u \int\frac{\cos(tu)-1}{u}\,du ∫ u c o s ( t u ) − 1 d u and ∫ sin ( t u ) u d u \int\frac{\sin(tu)}{u}\,du ∫ u s i n ( t u ) d u . These correspond precisely to the Cosine Integral Cin \operatorname{Cin} Cin and Sine Integral Si \operatorname{Si} Si . Consequently, we obtain an explicit analytic form for the characteristic function at the 1-stable boundary:
Ψ ( t ) = exp ( i t ( ln R − γ ) − e i t R − 1 − i t R R − i t Cin ( t R ) − t Si ( t R ) ) . \Psi(t)=\exp\left(it(\ln R-\gamma)-\frac{e^{itR}-1-itR}{R}-it\operatorname{Cin}(tR)-t\operatorname{Si}(tR)\right). Ψ ( t ) = exp ( i t ( ln R − γ ) − R e i tR − 1 − i tR − i t Cin ( tR ) − t Si ( tR ) ) .
With the explicit characteristic function derived, we can evaluate its CDF through the Gil-Pelaez inversion formula. To achieve polylogarithmic update time, the infinite integration domain must be truncated to a logarithmic interval while introducing only negligible error. The magnitude of the characteristic function is governed by Re ( ln Ψ ( t ) ) = 1 − cos ( t R ) R − t Si ( t R ) \operatorname{Re}(\ln\Psi(t)) = \frac{1-\cos(tR)}{R} - t\operatorname{Si}(tR) Re ( ln Ψ ( t )) = R 1 − c o s ( tR ) − t Si ( tR ) . We show that the Sine Integral is the dominating term, yielding the global bound ∣ Ψ ( t ) ∣ ≤ exp ( 2 R − κ ∣ t ∣ ) |\Psi(t)| \le\exp\left(\frac{2}{R} - \kappa|t|\right) ∣Ψ ( t ) ∣ ≤ exp ( R 2 − κ ∣ t ∣ ) for a universal constant κ > 0 \kappa> 0 κ > 0 . Using standard concentration and anti-concentration properties (c.f., Rényi’s representation theorem for exponential spacings), we show the algorithmic truncation parameter satisfies 1 R = Θ ( log n ) \frac{1}{R} = \Theta(\log n) R 1 = Θ ( log n ) . This exponential decay guarantees that we can truncate the inversion integral to an interval of size O ( log n ) O(\log n) O ( log n ) while incurring only an additive error of 1 poly ( n ) \frac{1}{\operatorname{poly}(n)} poly ( n ) 1 in the sampling distribution.
Finally, before applying numerical integration, we note that the standard Gil-Pelaez formula contains an imaginary-part operator. This introduces non-analytic behavior that prevents the direct use of exponentially convergent quadrature methods. To circumvent this, we rewrite the integrand as g ( t ) = e i t x Ψ ( t ) − e − i t x Ψ ( t ) 2 i t g(t) = \frac{e^{itx}\Psi(t)-e^{-itx}\Psi(t)}{2it} g ( t ) = 2 i t e i t x Ψ ( t ) − e − i t x Ψ ( t ) and show that g ( t ) g(t) g ( t ) extends holomorphically into the complex plane, allowing the integration contour to be enclosed within a Bernstein ellipse. Because the domain integral is truncated at R = Θ ( 1 log n ) R = \Theta\left(\frac{1}{\log n}\right) R = Θ ( l o g n 1 ) and the inversion integral at t = Θ ( log n ) t = \Theta(\log n) t = Θ ( log n ) , then ∣ t R ∣ = Θ ( 1 ) |tR| = \Theta(1) ∣ tR ∣ = Θ ( 1 ) . Thus, the trigonometric integrals do not exhibit rapid growth, enabling exponentially convergent Gauss-Legendre quadrature to evaluate the CDF using only O ( log 2 n ) O(\log^2 n) O ( log 2 n ) points. We summarize the main differences between our approach and previous works in Table 1 .
Table 1. The p = 2 p = 2 p = 2 boundary introduces non-integrable singularities, breaking prior techniques and requiring a fundamentally different analytic toolkit.
Preliminaries
In this section, we briefly recall standard concepts that we will use in our algorithmic design and analysis.
Given an integer n > 0 n > 0 n > 0 , we use [ n ] [n] [ n ] to denote the set { 1 , 2 , … , n } \{1, 2, \ldots, n\} { 1 , 2 , … , n } . Recall that the L 2 L_2 L 2 norm of a vector x ∈ R n x \in\mathbb{R}^n x ∈ R n is defined by x 1 2 + … + x n 2 \sqrt{x_1^2 + \ldots+ x_n^2} x 1 2 + … + x n 2 while the F 2 F_2 F 2 moment of x x x is defined by ∥ x ∥ 2 2 \lVert x\rVert_2^2 ∥ x ∥ 2 2 . We use poly ( n ) \operatorname{poly}(n) poly ( n ) to denote an arbitrary but fixed polynomial in n n n , whose degree can be adjusted by appropriately adjusting corresponding constants. We use polylog ( n ) \operatorname{polylog}(n) polylog ( n ) to denote poly ( log n ) \operatorname{poly}(\log n) poly ( log n ) . We say an event happens with high probability if it occurs with probability 1 − 1 poly ( n ) 1 - \frac{1}{\operatorname{poly}(n)} 1 − poly ( n ) 1 .
Theorem 4.1 (Markov’s Inequality). For any non-negative random variable X X X and any constant t > 0 t > 0 t > 0 , we have Pr [ X ≥ t ] ≤ E [ X ] t \Pr[X \ge t] \le\frac{\mathbb{E}[X]}{t} Pr [ X ≥ t ] ≤ t E [ X ] .
Probability Distributions
Definition 4.2 (Exponential random variable). A continuous random variable E E E follows an exponential distribution with scale λ > 0 \lambda> 0 λ > 0 , denoted E ∼ Exp ( λ ) E \sim\operatorname{Exp}(\lambda) E ∼ Exp ( λ ) , if its probability density function is
given by f E ( x ) = λ e − λ x f_{\mathrm{E}}(x)=\lambda e^{-\lambda x} f E ( x ) = λ e − λ x for x ≥ 0 x \ge0 x ≥ 0 , and 0 otherwise.
Fact 4.3. The exponential distribution satisfies the properties:
(1) (Memory-less property) For all s , t ≥ 0 s,t \ge0 s , t ≥ 0 , Pr [ E > s + t ∣ E > s ] = Pr [ E > t ] \Pr[\mathrm{E}>s+t\mid\mathrm{E}>s]=\Pr[\mathrm{E}>t] Pr [ E > s + t ∣ E > s ] = Pr [ E > t ] .
(2) (Max-stability) If E 1 , … , E n \mathrm{E}_1,\ldots,\mathrm{E}_n E 1 , … , E n are independent exponential random variables with rates λ 1 , … , λ n \lambda_1,\ldots,\lambda_n λ 1 , … , λ n , then max i E i \max_i \mathrm{E}_i max i E i has cumulative distribution function
Pr [ max i E i ≤ t ] = ∏ i = 1 n ( 1 − e − λ i t ) . \Pr\left[\max_i \mathrm{E}_i \le t\right]=\prod_{i=1}^{n}\left(1-e^{-\lambda_i t}\right). Pr [ i max E i ≤ t ] = i = 1 ∏ n ( 1 − e − λ i t ) .
Definition 4.4 (Gaussian random variable). A continuous random variable g g g follows a standard Gaussian (or normal) distribution, denoted g ∼ N ( 0 , 1 ) g \sim\mathcal{N}(0,1) g ∼ N ( 0 , 1 ) , if its probability density function is f g ( x ) = 1 2 π e − x 2 / 2 f_g(x)=\frac{1}{\sqrt{2\pi}}e^{-x^2/2} f g ( x ) = 2 π 1 e − x 2 /2 .
Definition 4.5 (Cauchy random variable). A continuous random variable C C C follows a standard Cauchy distribution if its probability density function is f C ( x ) = 1 π ( 1 + x 2 ) f_C(x)=\frac{1}{\pi(1+x^2)} f C ( x ) = π ( 1 + x 2 ) 1 .
Definition 4.6 (p p p -stable). A distribution D \mathcal{D} D over R \mathbb{R} R is called p p p -stable for 0 < p ≤ 2 0<p\le2 0 < p ≤ 2 if for any independent random variables X 1 , … , X k ∼ D X_1,\ldots,X_k\sim\mathcal{D} X 1 , … , X k ∼ D and any constants c 1 , … , c k ∈ R c_1,\ldots,c_k\in\mathbb{R} c 1 , … , c k ∈ R , we have
∑ j = 1 k c j X j ∼ ( ∑ j = 1 k ∣ c j ∣ p ) 1 / p X , \sum_{j=1}^{k}c_jX_j\sim\left(\sum_{j=1}^{k}|c_j|^p\right)^{1/p}X, j = 1 ∑ k c j X j ∼ ( j = 1 ∑ k ∣ c j ∣ p ) 1/ p X , where X ∼ D X\sim\mathcal{D} X ∼ D , so that ∼ \sim ∼ denotes equality in distribution.
Fact 4.7. The Cauchy distribution is 1 1 1 -stable, while the Gaussian distribution is 2 2 2 -stable. Moreover, if g 1 , g 2 g_1,g_2 g 1 , g 2 are independent standard Gaussian random variables, then g 1 g 2 \frac{g_1}{g_2} g 2 g 1 follows the standard Cauchy distribution.
Characteristic Functions and Inversion Formulas
To analyze the continuous limits of the sums of random variable when explicit probability density functions become mathematically intractable, we instead use Fourier-domain transformations.
Definition 4.8 (Characteristic function and cumulant-generating function). The characteristic function of a random variable X X X , denoted Ψ X ( t ) \Psi_X(t) Ψ X ( t ) , is the expected value of e i t X e^{itX} e i tX , representing the Fourier transform of its probability measure. For any real t ∈ R t\in\mathbb{R} t ∈ R :
Ψ X ( t ) = E [ e i t X ] = ∫ − ∞ ∞ e i t x f X ( x ) d x . \Psi_X(t)=\mathbb{E}\left[e^{itX}\right]=\int_{-\infty}^{\infty}e^{itx}f_X(x)\,dx. Ψ X ( t ) = E [ e i tX ] = ∫ − ∞ ∞ e i t x f X ( x ) d x . where f X ( x ) f_X(x) f X ( x ) is the probability density function of X X X , and i = − 1 i=\sqrt{-1} i = − 1 . The natural logarithm of the characteristic function, ln Ψ X ( t ) \ln\Psi_X(t) ln Ψ X ( t ) , is known as the cumulant-generating function.
Unlike moment-generating functions, the characteristic function is globally bounded and uniquely exists for all random variables, including those with heavy tails (e.g., Cauchy distributions).
Theorem 4.9 (Gil-Pelaez Inversion Formula). Let X X X be a continuous random variable have characteristic function Ψ X ( t ) \Psi_X(t) Ψ X ( t ) . Then the cumulative distribution function (CDF) F X ( x ) = Pr [ X ≤ x ] F_X(x) = \Pr[X \le x] F X ( x ) = Pr [ X ≤ x ] can be computed for any real x x x via the integral:
F X ( x ) = 1 2 − 1 π ∫ 0 ∞ Im ( e − i t x Ψ X ( t ) ) t d t , F_X(x) = \frac{1}{2} - \frac{1}{\pi}\int_{0}^{\infty}\frac{\operatorname{Im}\left(e^{-itx}\Psi_X(t)\right)}{t}\,dt, F X ( x ) = 2 1 − π 1 ∫ 0 ∞ t Im ( e − i t x Ψ X ( t ) ) d t , where Im ( ⋅ ) \operatorname{Im}(\cdot) Im ( ⋅ ) denotes the imaginary component of a complex number.
A standard approach for generating random samples from a target distribution with continuous and monotonically increasing CDF F ( x ) F(x) F ( x ) is inverse transform sampling, which is simply to generate a uniform random variable U ∼ Unif ( 0 , 1 ) U \sim\operatorname{Unif}(0,1) U ∼ Unif ( 0 , 1 ) and then compute X = F − 1 ( U ) X = F^{-1}(U) X = F − 1 ( U ) .
Statistical Distances
To quantify the discrepancy between an algorithmic output distribution and the ideal target distribution, we utilize standard statistical distance metrics.
Definition 4.10 (Kolmogorov-Smirnov Distance). The Kolmogorov-Smirnov distance (KS) is the maximum deviation between the Cumulative Distribution Functions F ( x ) F(x) F ( x ) and G ( x ) G(x) G ( x ) of two probability distributions, i.e., d K S ( F , G ) = sup x ∈ R ∣ F ( x ) − G ( x ) ∣ d_{\mathrm{KS}}(F,G) = \sup_{x \in\mathbb{R}} \lvert F(x) - G(x) \rvert d KS ( F , G ) = sup x ∈ R ∣ F ( x ) − G ( x )∣ .
Definition 4.11 (Total variation distance). *Let P P P and Q Q Q be probability distributions on R \mathbb{R} R with probability density functions p p p and q q q . Then the total variation distance is defined by d T V ( P , Q ) = d_{\mathrm{TV}}(P,Q) = d TV ( P , Q ) =
1 2 ∫ R ∣ p ( x ) − q ( x ) ∣ d x . \frac{1}{2}\int_{\mathbb{R}}\lvert p(x)-q(x)\rvert\,dx. 2 1 ∫ R ∣ p ( x ) − q ( x )∣ d x .
Real Analysis and Special Functions
Evaluating continuous limits mathematically frequently yields classical non-elementary integrals and requires rigorously interchanging limits and integrals.
Theorem 4.12 (Dominated Convergence Theorem). Let { f n ( x ) } \{f_n(x)\} { f n ( x )} be a sequence of measurable functions converging pointwise to a limit function f ( x ) f(x) f ( x ) . If there exists an absolutely integrable bounding function g ( x ) g(x) g ( x ) such that ∣ f n ( x ) ∣ ≤ g ( x ) \lvert f_n(x)\rvert\le g(x) ∣ f n ( x )∣ ≤ g ( x ) for all n n n and x x x , then the limit and integral operators may be exchanged:
lim n → ∞ ∫ f n ( x ) d x = ∫ f ( x ) d x . \lim_{n \to\infty}\int f_n(x)\,dx = \int f(x)\,dx. n → ∞ lim ∫ f n ( x ) d x = ∫ f ( x ) d x .
Definition 4.13 (Special Integral Functions). The mathematical evaluation of limits frequently isolates the following classical analytic functions:
Exponential Integral: E 1 ( z ) = ∫ z ∞ e − v v d v , ( z > 0 ) E_1(z) = \int_z^\infty\frac{e^{-v}}{v}\,dv,\quad(z > 0) E 1 ( z ) = ∫ z ∞ v e − v d v , ( z > 0 )
Entire Exponential Integral: Ein ( z ) = ∫ 0 z 1 − e − v v d v = ∑ k = 1 ∞ ( − 1 ) k − 1 z k k ⋅ k ! \operatorname{Ein}(z) = \int_0^z \frac{1-e^{-v}}{v}\,dv = \sum_{k=1}^{\infty}\frac{(-1)^{k-1}z^k}{k\cdot k!} Ein ( z ) = ∫ 0 z v 1 − e − v d v = ∑ k = 1 ∞ k ⋅ k ! ( − 1 ) k − 1 z k
Sine Integral: Si ( x ) = ∫ 0 x sin ( u ) u d u \operatorname{Si}(x) = \int_0^x \frac{\sin(u)}{u}\,du Si ( x ) = ∫ 0 x u s i n ( u ) d u
Cosine Integral: Cin ( x ) = ∫ 0 x 1 − cos ( u ) u d u \operatorname{Cin}(x) = \int_0^x \frac{1-\cos(u)}{u}\,du Cin ( x ) = ∫ 0 x u 1 − c o s ( u ) d u
Order Statistics
Definition 4.14 (Order statistics and anti-ranks). Given a sample of k k k independent and identically distributed random variables X 1 , X 2 , … , X k X_1,X_2,\ldots,X_k X 1 , X 2 , … , X k , their order statistics are the sequence of values sorted in non-decreasing order, so that X D ( 1 ) ≤ X D ( 2 ) ≤ … ≤ X D ( k ) X_{D(1)} \le X_{D(2)} \le\ldots\le X_{D(k)} X D ( 1 ) ≤ X D ( 2 ) ≤ … ≤ X D ( k ) . Here D ( 1 ) , … , D ( k ) D(1),\ldots,D(k) D ( 1 ) , … , D ( k ) are called the anti-ranks for X X X .
Theorem 4.15 (Rényi Representation Theorem for Exponential Spacings). [39 ] Let E ( 1 ) ≤ E ( 2 ) ≤ ⋯ ≤ E ( k ) E_{(1)} \le E_{(2)} \le\cdots\le E_{(k)} E ( 1 ) ≤ E ( 2 ) ≤ ⋯ ≤ E ( k ) be the order statistics of k k k independent standard exponential random variables E i ∼ Exp ( 1 ) E_i \sim\operatorname{Exp}(1) E i ∼ Exp ( 1 ) . The j j j -th order statistic is equal in distribution to
E D ( j ) ∼ ∑ ℓ = 1 j δ ℓ k − ℓ + 1 . E_{D(j)} \sim\sum_{\ell=1}^{j} \frac{\delta_\ell}{k-\ell+1}. E D ( j ) ∼ ℓ = 1 ∑ j k − ℓ + 1 δ ℓ . i.e., a linear combination of independent standard exponentials δ 1 , … , δ j ∼ Exp ( 1 ) \delta_1,\ldots,\delta_j \sim\operatorname{Exp}(1) δ 1 , … , δ j ∼ Exp ( 1 ) .
Lemma 4.16 (Lemma 2 in [28 ] ). Let x ∈ R n x \in\mathbb{R}^n x ∈ R n and define z i , j = x i e i , j 1 / p z_{i,j} = \frac{x_i}{e_{i,j}^{1/p}} z i , j = e i , j 1/ p x i , where the variables e i , j e_{i,j} e i , j are independent exponential random variables and j ∈ [ n c ] j \in[n^c] j ∈ [ n c ] . Set N = n c + 1 N = n^{c+1} N = n c + 1 , and let z ∈ R N z \in\mathbb{R}^N z ∈ R N denote a flattened vector obtained from the collection of values { z i , j } \{z_{i,j}\} { z i , j } . Similarly, define F ∈ R N F \in\mathbb{R}^N F ∈ R N to be the duplicated vector obtained by repeating each coordinate of x x x exactly n c n^c n c times. Then for every integer k ∈ [ 1 , N − n ζ / 10 ) k \in[1,N-n^{\zeta/10}) k ∈ [ 1 , N − n ζ /10 ) , with probability at least 1 − O ( e − n c / 3 ) 1-\mathcal{O}\left(e^{-n^{c/3}}\right) 1 − O ( e − n c /3 ) we have
∣ z D ( k ) ∣ = [ ( 1 ± O ( n − ζ / 10 ) ) ⋅ ∑ τ = 1 k E τ E [ ∑ j = τ N ∣ F D ( j ) ∣ p ] ] − 1 / p . \lvert z_{D(k)}\rvert= \left[\left(1 \pm\mathcal{O}\left(n^{-\zeta/10}\right)\right)\cdot\sum_{\tau=1}^{k}\frac{E_\tau}{\mathbb{E}\left[\sum_{j=\tau}^{N}\lvert F_{D(j)}\rvert^p\right]}\right]^{-1/p}. ∣ z D ( k ) ∣ = ( 1 ± O ( n − ζ /10 ) ) ⋅ τ = 1 ∑ k E [ ∑ j = τ N ∣ F D ( j ) ∣ p ] E τ − 1/ p .
Streaming Algorithms
We use a dense variant of CountSketch as the basic estimation primitive throughout our construction, described in Algorithm 4. Unlike sparse hashing-based sketches, dense CountSketch projects the frequency vector onto independent Gaussian directions, allowing each coordinate estimate to be expressed as an inner product with a corresponding Gaussian column. This representation yields uniform additive error guarantees across all coordinates, with the error proportional to the global L 2 L_2 L 2 norm of the stream. The dense structure is particularly convenient in our setting because the Gaussian random variables interacts naturally with the tail noise introduced by the perfect sampling procedure.
Algorithm 4 Dense CountSketch
Input: Frequency vector x ∈ R n x \in\mathbb{R}^n x ∈ R n
Output: Estimates of x i x_i x i for all i ∈ [ n ] i \in[n] i ∈ [ n ]
Let G ∈ R R × n G \in\mathbb{R}^{R \times n} G ∈ R R × n be a matrix where each entry is drawn from N ( 0 , 1 ) \mathcal{N}(0,1) N ( 0 , 1 )
Let G i G_i G i denote the i i i -th column of G G G
return x ^ i = 1 R ⋅ ⟨ G i , G x ⟩ \hat{x}_i = \frac{1}{R}\cdot\langle G_i,Gx\rangle x ^ i = R 1 ⋅ ⟨ G i , G x ⟩ as the estimate for x i x_i x i
Recall the following guarantees for dense CountSketch in Algorithm 4, e.g., from [43 ] , by taking the median of O ( log n ) \mathcal{O}(\log n) O ( log n ) groups of tables with r r r rows:
Theorem 4.17. [43 ] With probability at least 1 − 1 poly ( n ) 1-\frac{1}{\operatorname{poly}(n)} 1 − poly ( n ) 1 , the dense CountSketch data structure with O ( r log n ) O(r\log n) O ( r log n ) rows returns estimates x ^ 1 , … , x ^ n \widehat{x}_1,\ldots,\widehat{x}_n x 1 , … , x n satisfying
∣ x ^ i − x i ∣ ≤ 4 r ∥ x ∥ 2 |\widehat{x}_i-x_i|\le\frac{4}{\sqrt{r}}\lVert x\rVert_2 ∣ x i − x i ∣ ≤ r 4 ∥ x ∥ 2 for every i ∈ [ n ] i\in[n] i ∈ [ n ] . The total space complexity is O ( r log 2 n ) O(r\log^2 n) O ( r log 2 n ) bits.
Analysis of the Continuous Tail Distribution
Algorithm 3 replaces the explicit contribution of the m = k − τ m=k-\tau m = k − τ tail coordinates with a single sample from a limiting continuous distribution Z Z Z . In this section, we formalize this limiting object and derive the normalization needed to preserve the induced variance distribution. The main challenge is that the reciprocal exponential variables governing the tail are heavy-tailed: before truncation they have infinite expectation, and even after conditioning on the τ \tau τ -th order statistic their moments exhibit logarithmic growth, scaling as O ( log m ) O(\log m) O ( log m ) . As a result, standard concentration arguments and classical central limit heuristics do not apply directly.
Our analysis proceeds in three steps. First, we characterize the conditioning induced by removing the largest τ \tau τ coordinates and show that the remaining variables admit a simple truncated inverse-exponential description. Second, we identify the natural normalization under which the aggregate tail contribution converges to a limiting continuous distribution. Unlike Gaussian limits arising from finite-variance settings, the logarithmic divergence of the reciprocal exponential variables leads to a 1-stable phenomenon, requiring a centering correction of ln m \ln m ln m . Finally, we derive an explicit representation of the limiting characteristic function and show how it can be evaluated efficiently for use inside the inverse-CDF sampling procedure.
At a high level, the proof may be viewed as an analytic surgery argument. Directly evaluating the characteristic function produces a non-integrable 1 u \frac{1}{u} u 1 singularity near the origin, preventing a straightforward interchange of limits and integration. We isolate the singular component, show that it exactly cancels the logarithmic centering term, and then evaluate the remaining regularized expression using special-function identities. This converts the limiting law into an explicit form suitable for numerical inversion.
Base Variables and Conditioning Shift
By the memory-less property of the exponential distribution, c.f., Fact 4.3, conditioning on the τ \tau τ -th order statistic E D ( τ ) E_{D(\tau)} E D ( τ ) implies that the remaining m m m variables are distributed as independent exponentials shifted by E D ( τ ) E_{D(\tau)} E D ( τ ) . Equivalently, in the inverse representation, the corresponding variables are distributed as independent samples conditioned on lying below a threshold determined by E D ( τ ) E_{D(\tau)} E D ( τ ) .
Let X X X denote a random variable distributed as Y ∼ Exp ( 1 ) − 1 Y\sim\operatorname{Exp}(1)^{-1} Y ∼ Exp ( 1 ) − 1 conditioned on Y ≤ Y D ( τ ) Y\le Y_{D(\tau)} Y ≤ Y D ( τ ) . In the algorithmic setting, Y ( τ ) = R ⋅ m Y_{(\tau)}=R\cdot m Y ( τ ) = R ⋅ m . The induced density of X X X is
f X ( x ) = 1 Pr [ Y ≤ R m ] x − 2 e − 1 / x 1 ( 0 , R m ] ( x ) . f_X(x)=\frac{1}{\Pr[Y\le Rm]}x^{-2}e^{-1/x}\mathbf{1}_{(0,Rm]}(x). f X ( x ) = Pr [ Y ≤ R m ] 1 x − 2 e − 1/ x 1 ( 0 , R m ] ( x ) .
Let X 1 , … , X m X_1,\ldots,X_m X 1 , … , X m be i.i.d. copies of X X X . We denote the exact discrete tail statistic by V e x a c t = ∑ j = 1 m X j V_{\mathrm{exact}}=\sum_{j=1}^{m}X_j V exact = ∑ j = 1 m X j .
To isolate the dominant scaling behavior, we define the normalized statistic
Z m : = 1 m ∑ j = 1 m X j − ln m . Z_m := \frac{1}{m}\sum_{j=1}^{m} X_j - \ln m. Z m := m 1 j = 1 ∑ m X j − ln m .
The tail-variance functional V ( ⋅ ) V(\cdot) V ( ⋅ ) . In Algorithm 2, the tail-variance functional V ( ⋅ ) V(\cdot) V ( ⋅ ) maps the inverse-CDF sample z ∗ z^* z ∗ produced via Algorithm 3 back to the variance parameter of the stream. This should correspond to the quantity V e x a c t = m ( z ∗ + ln m ) V_{\mathrm{exact}} = m(z^* + \ln m) V exact = m ( z ∗ + ln m ) . However, since the limiting 1-stable law underlying Z \mathcal{Z} Z is supported on all of R \mathbb{R} R , the sampled value z ∗ z^* z ∗ may occasionally satisfy z ∗ < − ln m z^* < -\ln m z ∗ < − ln m , in which case V e x a c t V_{\mathrm{exact}} V exact becomes negative, which cannot correspond to a realizable variance. We therefore define the tail variance functional by the truncation
V ( z ∗ ) : = max ( 0 , m ( z ∗ + ln m ) ) , V(z^*) := \max\left(0, m(z^* + \ln m)\right), V ( z ∗ ) := max ( 0 , m ( z ∗ + ln m ) ) ,
so that the computation of σ i 2 ~ \sqrt{\widetilde{\sigma_i^2}} σ i 2 in Algorithm 1 is well-defined and the total variation distance remains within the overall ± ν \pm\nu ± ν additive error tolerance.
Correcting the Order Statistics Boundaries
We now establish the asymptotic behavior for the tail simulation procedure. Specifically, we show that the reciprocal scale parameter 1 R \frac{1}{R} R 1 is only polylogarithmic in n n n . Throughout, let k = n C k = n^C k = n C for a sufficiently large constant, let the explicitly tracked head size be τ = c 1 log n \tau= c_1 \log n τ = c 1 log n for a sufficiently large constant c 1 > 0 c_1 > 0 c 1 > 0 , so that m = k − τ m = k - \tau m = k − τ is the number of tail coordinates. The target additive failure probability is ν = n − c 2 \nu= n^{-c_2} ν = n − c 2 for some input parameter c 2 > 0 c_2 > 0 c 2 > 0 .
Informally, the argument works as follows. Recall that we define the truncation boundary to be R = Y ( τ ) m R = \frac{Y_{(\tau)}}{m} R = m Y ( τ ) , where Y ( τ ) Y_{(\tau)} Y ( τ ) denotes the τ \tau τ -th largest inverse exponential. Equivalently, if E ( 1 ) ≤ E ( 2 ) ≤ ⋯ E_{(1)} \le E_{(2)} \le\cdots E ( 1 ) ≤ E ( 2 ) ≤ ⋯ denote the ordered standard exponentials, then Y ( τ ) = 1 E ( τ ) Y_{(\tau)} = \frac{1}{E_{(\tau)}} Y ( τ ) = E ( τ ) 1 . Using Rényi’s exact representation theorem for exponential order statistics, c.f., Theorem 4.15, we decompose E ( τ ) = ∑ j = 1 τ δ j k − j + 1 E_{(\tau)} = \sum_{j=1}^{\tau} \frac{\delta_j}{k-j+1} E ( τ ) = ∑ j = 1 τ k − j + 1 δ j , where the δ j \delta_j δ j are independent exponential random variables Exp ( 1 ) \operatorname{Exp}(1) Exp ( 1 ) . Since τ = Θ ( log n ) \tau= \Theta(\log n) τ = Θ ( log n ) and k = n C k = n^C k = n C , then the denominators satisfy k − j + 1 = ( 1 − o ( 1 ) ) k k-j+1 = (1-o(1))k k − j + 1 = ( 1 − o ( 1 )) k for all j ∈ [ τ ] j \in[\tau] j ∈ [ τ ] . Thus,
E ( τ ) = 1 + o ( 1 ) k ⋅ ∑ j = 1 τ δ j . E_{(\tau)} = \frac{1+o(1)}{k}\cdot\sum_{j=1}^{\tau}\delta_j. E ( τ ) = k 1 + o ( 1 ) ⋅ j = 1 ∑ τ δ j .
The sum ∑ j = 1 τ δ j \sum_{j=1}^{\tau}\delta_j ∑ j = 1 τ δ j is distributed as a Gamma random variable with mean τ \tau τ and satisfies standard Chernoff concentration bounds. Therefore, with high probability, ∑ j = 1 τ δ j = Θ ( τ ) \sum_{j=1}^{\tau}\delta_j = \Theta(\tau) ∑ j = 1 τ δ j = Θ ( τ ) , which implies E ( τ ) = Θ ( τ k ) E_{(\tau)} = \Theta\left(\frac{\tau}{k}\right) E ( τ ) = Θ ( k τ ) and so Y ( τ ) = Θ ( k τ ) Y_{(\tau)} = \Theta\left(\frac{k}{\tau}\right) Y ( τ ) = Θ ( τ k ) . Substituting into the definition of R R R and using m = k − τ = ( 1 − o ( 1 ) ) k m = k-\tau= (1-o(1))k m = k − τ = ( 1 − o ( 1 )) k , we obtain R = Θ ( 1 τ ) = Θ ( 1 log n ) R = \Theta\left(\frac{1}{\tau}\right) = \Theta\left(\frac{1}{\log n}\right) R = Θ ( τ 1 ) = Θ ( l o g n 1 ) or equivalently, 1 R = Θ ( log n ) \frac{1}{R} = \Theta(\log n) R 1 = Θ ( log n ) .
The crucial observation is that the polynomial duplication scale k k k cancels completely in the ratio Y ( τ ) m \frac{Y_{(\tau)}}{m} m Y ( τ ) since m = k − τ = k − o ( k ) m = k-\tau= k-o(k) m = k − τ = k − o ( k ) . Thus, the truncation boundary depends entirely on the logarithmic head parameter τ \tau τ , rather than by the underlying duplication factor.
Lemma 5.1 (Parameter bounds for the truncation scale). Let Y ( τ ) Y_{(\tau)} Y ( τ ) denote the τ \tau τ -th largest order statistic among k k k independent inverse exponentials Y j ∼ Exp ( 1 ) − 1 Y_j \sim\operatorname{Exp}(1)^{-1} Y j ∼ Exp ( 1 ) − 1 . Let k = n C k = n^C k = n C , τ = c 1 ln n \tau= c_1 \ln n τ = c 1 ln n , and m = k − τ m = k-\tau m = k − τ , where C , c 1 > 0 C,c_1 > 0 C , c 1 > 0 are sufficiently large constants. Define the normalized truncation ratio
R = Y ( τ ) τ R = \frac{Y_{(\tau)}}{\tau} R = τ Y ( τ ) . Then, with probability at least 1 − 2 n − c 1 - 2n^{-c} 1 − 2 n − c , we have R = Θ ( 1 log n ) R = \Theta\left(\frac{1}{\log n}\right) R = Θ ( l o g n 1 ) , where the constant c > 0 c > 0 c > 0 may be made arbitrarily large by choosing c 1 c_1 c 1 sufficiently large.
Proof. The proof proceeds by using Rényi’s representation theorem, c.f., Theorem 4.15 to decouple the standard exponential order statistics and then applying concentration bounds. Let E 1 , … , E k E_1,\ldots,E_k E 1 , … , E k be a sequence of independent, identically distributed standard exponential random variables, so that E j ∼ Exp ( 1 ) E_j \sim\operatorname{Exp}(1) E j ∼ Exp ( 1 ) for all j ∈ [ k ] j \in[k] j ∈ [ k ] . Let E D ( 1 ) ≤ E D ( 2 ) ≤ … ≤ E D ( k ) E_{D(1)} \le E_{D(2)} \le\ldots\le E_{D(k)} E D ( 1 ) ≤ E D ( 2 ) ≤ … ≤ E D ( k ) denote the corresponding order statistics, so that Y j = 1 E D ( j ) Y_j = \frac{1}{E_{D(j)}} Y j = E D ( j ) 1 for all j ∈ [ k ] j \in[k] j ∈ [ k ] . By the Rényi Representation Theorem, c.f., Theorem 4.15, the τ \tau τ -th order statistic of k k k standard exponential random variables is equal in distribution to a linear combination of independent standard exponentials:
E D ( τ ) ∼ ∑ j = 1 τ δ j k − j + 1 , E_{D(\tau)} \sim\sum_{j=1}^{\tau} \frac{\delta_j}{k-j+1}, E D ( τ ) ∼ j = 1 ∑ τ k − j + 1 δ j ,
where δ 1 , … , δ τ ∼ Exp ( 1 ) \delta_1,\ldots,\delta_\tau\sim\operatorname{Exp}(1) δ 1 , … , δ τ ∼ Exp ( 1 ) are mutually independent standard exponential random variables. These hidden exponential random variables are generated by Algorithm 2. Since k − τ + 1 ≤ k − j + 1 ≤ k k-\tau+1 \le k-j+1 \le k k − τ + 1 ≤ k − j + 1 ≤ k , then we have
1 k ∑ j = 1 τ δ j ≤ E D ( τ ) ≤ 1 k − τ + 1 ∑ j = 1 τ δ j . (1) \frac{1}{k}\sum_{j=1}^{\tau}\delta_j \le E_{D(\tau)} \le\frac{1}{k-\tau+1}\sum_{j=1}^{\tau}\delta_j. \tag*{(1)} k 1 j = 1 ∑ τ δ j ≤ E D ( τ ) ≤ k − τ + 1 1 j = 1 ∑ τ δ j . (1)
Let S τ : = ∑ j = 1 τ δ j S_\tau:= \sum_{j=1}^{\tau}\delta_j S τ := ∑ j = 1 τ δ j be the unscaled sum of the hidden exponentials. By the additive property of independent exponentials, S τ S_\tau S τ follows an exact Gamma distribution with shape parameter τ \tau τ and rate parameter 1 1 1 , denoted S τ ∼ Gamma ( τ , 1 ) S_\tau\sim\operatorname{Gamma}(\tau,1) S τ ∼ Gamma ( τ , 1 ) , so that E [ S τ ] = τ \mathbb{E}[S_\tau] = \tau E [ S τ ] = τ .
To show concentration, we apply a standard Chernoff argument to the sum S τ S_\tau S τ . For a standard exponential random variable δ j ∼ Exp ( 1 ) \delta_j \sim\operatorname{Exp}(1) δ j ∼ Exp ( 1 ) , the moment generating function is
E [ e s δ j ] = ∫ 0 ∞ e s x e − x d x = 1 1 − s , \mathbb{E}\left[e^{s\delta_j}\right] = \int_0^\infty e^{sx}e^{-x}\,dx = \frac{1}{1-s}, E [ e s δ j ] = ∫ 0 ∞ e s x e − x d x = 1 − s 1 ,
for s < 1 s < 1 s < 1 . By independence, the MGF of S τ S_\tau S τ is E [ e s S τ ] = ( 1 − s ) − τ \mathbb{E}\left[e^{sS_\tau}\right] = (1-s)^{-\tau} E [ e s S τ ] = ( 1 − s ) − τ . For the upper tail, let δ ∈ ( 0 , 1 ) \delta\in(0,1) δ ∈ ( 0 , 1 ) and choose s ∈ ( 0 , 1 ) s \in(0,1) s ∈ ( 0 , 1 ) . By Markov’s inequality, we have
Pr [ S τ ≥ ( 1 + δ ) τ ] = Pr [ e s S τ ≥ e s ( 1 + δ ) τ ] ≤ E [ e s S τ ] e s ( 1 + δ ) τ = ( 1 − s ) − τ e s ( 1 + δ ) τ . \Pr[S_\tau\ge(1+\delta)\tau] = \Pr\left[e^{sS_\tau} \ge e^{s(1+\delta)\tau}\right] \le\frac{\mathbb{E}\left[e^{sS_\tau}\right]}{e^{s(1+\delta)\tau}} = \frac{(1-s)^{-\tau}}{e^{s(1+\delta)\tau}}. Pr [ S τ ≥ ( 1 + δ ) τ ] = Pr [ e s S τ ≥ e s ( 1 + δ ) τ ] ≤ e s ( 1 + δ ) τ E [ e s S τ ] = e s ( 1 + δ ) τ ( 1 − s ) − τ .
Observe that for the parameter s = δ 1 + δ s = \frac{\delta}{1+\delta} s = 1 + δ δ , the upper tail bound becomes
Pr [ S τ ≥ ( 1 + δ ) τ ] ≤ ( ( 1 + δ ) e − δ ) τ = exp ( − τ ( δ − ln ( 1 + δ ) ) ) . \Pr[S_\tau\ge(1+\delta)\tau] \le\left((1+\delta)e^{-\delta}\right)^\tau= \exp\left(-\tau\left(\delta-\ln(1+\delta)\right)\right). Pr [ S τ ≥ ( 1 + δ ) τ ] ≤ ( ( 1 + δ ) e − δ ) τ = exp ( − τ ( δ − ln ( 1 + δ ) ) ) .
By similarly applying Markov’s inequality to e − s S τ e^{-sS_\tau} e − s S τ , we have
Pr [ S τ ≤ ( 1 − δ ) τ ] = Pr [ e − s S τ ≥ e − s ( 1 − δ ) τ ] ≤ E [ e − s S τ ] e − s ( 1 − δ ) τ = ( 1 + s ) − τ e − s ( 1 − δ ) τ . \Pr[S_\tau\le(1-\delta)\tau] = \Pr\left[e^{-sS_\tau} \ge e^{-s(1-\delta)\tau}\right] \le\frac{\mathbb{E}\left[e^{-sS_\tau}\right]}{e^{-s(1-\delta)\tau}} = \frac{(1+s)^{-\tau}}{e^{-s(1-\delta)\tau}}. Pr [ S τ ≤ ( 1 − δ ) τ ] = Pr [ e − s S τ ≥ e − s ( 1 − δ ) τ ] ≤ e − s ( 1 − δ ) τ E [ e − s S τ ] = e − s ( 1 − δ ) τ ( 1 + s ) − τ .
By setting s = δ 1 − δ s = \frac{\delta}{1-\delta} s = 1 − δ δ , we have the lower tail bound
Pr [ S τ ≤ ( 1 − δ ) τ ] ≤ ( ( 1 − δ ) e δ ) τ = exp ( − τ ( − δ − ln ( 1 − δ ) ) ) . \Pr[S_\tau\le(1-\delta)\tau] \le\left((1-\delta)e^\delta\right)^\tau= \exp\left(-\tau\left(-\delta-\ln(1-\delta)\right)\right). Pr [ S τ ≤ ( 1 − δ ) τ ] ≤ ( ( 1 − δ ) e δ ) τ = exp ( − τ ( − δ − ln ( 1 − δ ) ) ) .
Thus, for the fixed relative deviation of δ = 1 / 2 \delta= 1/2 δ = 1/2 , the exponent constant evaluates to δ − ln ( 1 + δ ) = 0.5 − ln ( 1.5 ) ≈ 0.0945 > 0 \delta- \ln(1 + \delta) = 0.5 - \ln(1.5) \approx0.0945 > 0 δ − ln ( 1 + δ ) = 0.5 − ln ( 1.5 ) ≈ 0.0945 > 0 for the upper tail and the exponent constant evaluates to − δ − ln ( 1 − δ ) = − 0.5 − ln ( 0.5 ) ≈ 0.1931 > 0 -\delta- \ln(1 - \delta) = -0.5 - \ln(0.5) \approx0.1931 > 0 − δ − ln ( 1 − δ ) = − 0.5 − ln ( 0.5 ) ≈ 0.1931 > 0 for the lower tail. For the upper tail, the exponent constant evaluates to δ − ln ( 1 + δ ) = 0.5 − ln ( 1.5 ) ≈ 0.0945 > 0 \delta- \ln(1 + \delta) = 0.5 - \ln(1.5) \approx0.0945 > 0 δ − ln ( 1 + δ ) = 0.5 − ln ( 1.5 ) ≈ 0.0945 > 0 . For the lower tail, the exponent constant evaluates to − δ − ln ( 1 − δ ) = − 0.5 − ln ( 0.5 ) ≈ 0.1931 > 0 -\delta- \ln(1 - \delta) = -0.5 - \ln(0.5) \approx0.1931 > 0 − δ − ln ( 1 − δ ) = − 0.5 − ln ( 0.5 ) ≈ 0.1931 > 0 . Thus, for τ = c 1 ln n \tau= c_1 \ln n τ = c 1 ln n for sufficiently large c 1 c_1 c 1 , we have by a union bound that the probability that S τ S_\tau S τ deviates outside the interval [ 0.5 τ , 1.5 τ ] [0.5\tau, 1.5\tau] [ 0.5 τ , 1.5 τ ] is at most 2 n − c 2n^{-c} 2 n − c . Hence, we define the event E \mathcal{E} E to be the high-probability event that 0.5 τ ≤ S τ ≤ 1.5 τ 0.5\tau\le S_\tau\le1.5\tau 0.5 τ ≤ S τ ≤ 1.5 τ .
Conditioned on event E \mathcal{E} E , we substitute the bounds for S τ S_\tau S τ back into Equation (1) , obtaining
0.5 τ k ≤ E D ( τ ) ≤ 1.5 τ k − τ + 1 . \frac{0.5\tau}{k} \le E_{D(\tau)} \le\frac{1.5\tau}{k-\tau+1}. k 0.5 τ ≤ E D ( τ ) ≤ k − τ + 1 1.5 τ .
Because Y ( τ ) = 1 E D ( τ ) Y_{(\tau)} = \frac{1}{E_{D(\tau)}} Y ( τ ) = E D ( τ ) 1 , then it follows that we have
k − τ + 1 1.5 τ ≤ Y ( τ ) ≤ k 0.5 τ . \frac{k-\tau+1}{1.5\tau} \le Y_{(\tau)} \le\frac{k}{0.5\tau}. 1.5 τ k − τ + 1 ≤ Y ( τ ) ≤ 0.5 τ k .
Since we set R = Y ( τ ) m R = \frac{Y_{(\tau)}}{m} R = m Y ( τ ) for m = k − τ m = k-\tau m = k − τ , then we have:
k − τ + 1 1.5 τ ( k − τ ) ≤ R ≤ k 0.5 τ ( k − τ ) . \frac{k-\tau+1}{1.5\tau(k-\tau)} \le R \le\frac{k}{0.5\tau(k-\tau)}. 1.5 τ ( k − τ ) k − τ + 1 ≤ R ≤ 0.5 τ ( k − τ ) k .
Since ( k − τ + 1 ) > ( k − τ ) (k-\tau+1) > (k-\tau) ( k − τ + 1 ) > ( k − τ ) and τ = o ( k ) \tau= o(k) τ = o ( k ) , so that τ < 0.5 k \tau< 0.5k τ < 0.5 k for sufficiently large k = n c k = n^c k = n c , then for τ = c 1 ln n \tau= c_1 \ln n τ = c 1 ln n , we have
2 3 c 1 ln n < R ≤ 4 c 1 ln n , \frac{2}{3c_1 \ln n} < R \le\frac{4}{c_1 \ln n}, 3 c 1 ln n 2 < R ≤ c 1 ln n 4 ,
as desired.
The Continuous Limit and its Characteristic Function
We now analyze the limiting distribution describing the simulated tail contribution. Recall that the algorithm constructs the centered random variable
Z m = 1 m ∑ j = 1 m X j − ln m , Z_m = \frac{1}{m}\sum_{j=1}^{m} X_j - \ln m, Z m = m 1 j = 1 ∑ m X j − ln m ,
where the variables X 1 , … , X m X_1,\ldots,X_m X 1 , … , X m are independent and identically distributed with density
f X ( x ) = exp ( 1 R m ) x − 2 e − 1 / x , f_X(x) = \exp\left(\frac{1}{Rm}\right)x^{-2}e^{-1/x}, f X ( x ) = exp ( R m 1 ) x − 2 e − 1/ x ,
for x ∈ ( 0 , R m ] x \in(0,Rm] x ∈ ( 0 , R m ] . Our goal is to identify the limiting characteristic function of Z m Z_m Z m as m → ∞ m \to\infty m → ∞ .
Theorem 5.2 (Limiting characteristic function). For any parameter R > 0 R > 0 R > 0 , as m → ∞ m \to\infty m → ∞ , the random variable Z m Z_m Z m converges in distribution to a continuous random variable Z Z Z with characteristic function Ψ ( t ) = exp ( C 2 ( t ) ) \Psi(t) = \exp(C_2(t)) Ψ ( t ) = exp ( C 2 ( t )) , where
C 2 ( t ) = i t ( ln R − γ ) − e i t R − 1 − i t R R − i t Cin ( t R ) − t Si ( t R ) . (2) C_2(t) = it(\ln R-\gamma)-\frac{e^{itR}-1-itR}{R}-it\operatorname{Cin}(tR)-t\operatorname{Si}(tR). \tag*{(2)} C 2 ( t ) = i t ( ln R − γ ) − R e i tR − 1 − i tR − i t Cin ( tR ) − t Si ( tR ) . (2) Here γ \gamma γ denotes the Euler-Mascheroni constant, while Si \operatorname{Si} Si and Cin \operatorname{Cin} Cin are the standard sine and cosine integrals, c.f., Definition 4.13 .
Proof. Let Ψ Z m ( t ) = E [ e i t Z m ] \Psi_{Z_m}(t)=\mathbb{E}\left[e^{itZ_m}\right] Ψ Z m ( t ) = E [ e i t Z m ] denote the characteristic function of Z m Z_m Z m . By independence,
Ψ Z m ( t ) = E [ exp ( i t ( 1 m ∑ j = 1 m X j − ln m ) ) ] = e − i t ln m ∏ j = 1 m E [ exp ( i t X j m ) ] = e − i t ln m ( E [ exp ( i t X m ) ] ) m . \Psi_{Z_m}(t)=\mathbb{E}\left[\exp\left(it\left(\frac{1}{m}\sum_{j=1}^{m}X_j-\ln m\right)\right)\right]
= e^{-it\ln m}\prod_{j=1}^{m}\mathbb{E}\left[\exp\left(\frac{itX_j}{m}\right)\right]
= e^{-it\ln m}\left(\mathbb{E}\left[\exp\left(\frac{itX}{m}\right)\right]\right)^m. Ψ Z m ( t ) = E [ exp ( i t ( m 1 j = 1 ∑ m X j − ln m ) ) ] = e − i t l n m j = 1 ∏ m E [ exp ( m i t X j ) ] = e − i t l n m ( E [ exp ( m i tX ) ] ) m .
Then by taking logarithms of both sides,
ln Ψ Z m ( t ) = − i t ln m + m ln ( E [ exp ( i t X m ) ] ) . \ln\Psi_{Z_m}(t)=-it\ln m+m\ln\left(\mathbb{E}\left[\exp\left(\frac{itX}{m}\right)\right]\right). ln Ψ Z m ( t ) = − i t ln m + m ln ( E [ exp ( m i tX ) ] ) .
Let y m ( t ) = E [ exp ( i t X m ) ] − 1 y_m(t)=\mathbb{E}\left[\exp\left(\frac{itX}{m}\right)\right]-1 y m ( t ) = E [ exp ( m i tX ) ] − 1 . To apply the Taylor series expansion ln ( 1 + y m ) = y m + O ( ∣ y m ∣ 2 ) \ln(1+y_m)=y_m+O\left(\lvert y_m\rvert^2\right) ln ( 1 + y m ) = y m + O ( ∣ y m ∣ 2 ) , we first upper bound m ∣ y m ( t ) ∣ 2 m\lvert y_m(t)\rvert^2 m ∣ y m ( t ) ∣ 2 . Since ∣ e i θ − 1 ∣ ≤ ∣ θ ∣ \lvert e^{i\theta}-1\rvert\leq\lvert\theta\rvert ∣ e i θ − 1 ∣ ≤ ∣ θ ∣ for real θ \theta θ , we have ∣ y m ( t ) ∣ ≤ E [ ∣ e i t X / m − 1 ∣ ] ≤ E [ ∣ t X m ∣ ] = ∣ t ∣ m E [ X ] \lvert y_m(t)\rvert\leq\mathbb{E}\left[\left\lvert e^{itX/m}-1\right\rvert\right]\leq\mathbb{E}\left[\left\lvert\frac{tX}{m}\right\rvert\right]=\frac{\lvert t\rvert}{m}\mathbb{E}[X] ∣ y m ( t )∣ ≤ E [ e i tX / m − 1 ] ≤ E [ m tX ] = m ∣ t ∣ E [ X ] . Using the density of X X X , its expectation is ∫ 0 R m x ⋅ exp ( 1 R m ) x − 2 e − 1 / x d x = exp ( 1 R m ) E 1 ( 1 R m ) \int_{0}^{Rm}x\cdot\exp\left(\frac{1}{Rm}\right)x^{-2}e^{-1/x}\,dx=\exp\left(\frac{1}{Rm}\right)E_1\left(\frac{1}{Rm}\right) ∫ 0 R m x ⋅ exp ( R m 1 ) x − 2 e − 1/ x d x = exp ( R m 1 ) E 1 ( R m 1 ) . For a fixed R > 0 R>0 R > 0 , E 1 ( 1 R m ) = Θ ( ln m ) E_1\left(\frac{1}{Rm}\right)=\Theta(\ln m) E 1 ( R m 1 ) = Θ ( ln m ) as m → ∞ m\to\infty m → ∞ . Thus ∣ y m ( t ) ∣ = O ( ∣ t ∣ ln m m ) \lvert y_m(t)\rvert=O\left(\frac{\lvert t\rvert\ln m}{m}\right) ∣ y m ( t )∣ = O ( m ∣ t ∣ l n m ) , which gives m ∣ y m ( t ) ∣ 2 = O ( t 2 ln 2 m m ) → 0 m\lvert y_m(t)\rvert^2=O\left(\frac{t^2\ln^2m}{m}\right)\to0 m ∣ y m ( t ) ∣ 2 = O ( m t 2 l n 2 m ) → 0 as m → ∞ m\to\infty m → ∞ . We may therefore expand the logarithm to obtain
lim m → ∞ ln Ψ Z m ( t ) = lim m → ∞ [ m ( E [ exp ( i t X m ) ] − 1 ) − i t ln m ] . (3) \lim_{m\to\infty}\ln\Psi_{Z_m}(t)=\lim_{m\to\infty}\left[m\left(\mathbb{E}\left[\exp\left(\frac{itX}{m}\right)\right]-1\right)-it\ln m\right]. \tag*{(3)} m → ∞ lim ln Ψ Z m ( t ) = m → ∞ lim [ m ( E [ exp ( m i tX ) ] − 1 ) − i t ln m ] . (3)
We now evaluate the expectation term. Using the density of the truncated exponential random variable X X X ,
E [ exp ( i t X m ) ] − 1 = ∫ 0 R m ( e i t x / m − 1 ) f X ( x ) d x = exp ( 1 R m ) ∫ 0 R m ( e i t x / m − 1 ) x − 2 e − 1 / x d x . \mathbb{E}\left[\exp\left(\frac{itX}{m}\right)\right]-1=\int_{0}^{Rm}\left(e^{itx/m}-1\right)f_X(x)\,dx
=\exp\left(\frac{1}{Rm}\right)\int_{0}^{Rm}\left(e^{itx/m}-1\right)x^{-2}e^{-1/x}\,dx. E [ exp ( m i tX ) ] − 1 = ∫ 0 R m ( e i t x / m − 1 ) f X ( x ) d x = exp ( R m 1 ) ∫ 0 R m ( e i t x / m − 1 ) x − 2 e − 1/ x d x .
Substituting u = x m u=\frac{x}{m} u = m x ,
E [ exp ( i t X m ) ] − 1 = 1 m exp ( 1 R m ) ∫ 0 R e i t u − 1 u 2 e − 1 / ( u m ) d u . \mathbb{E}\left[\exp\left(\frac{itX}{m}\right)\right]-1=\frac{1}{m}\exp\left(\frac{1}{Rm}\right)\int_{0}^{R}\frac{e^{itu}-1}{u^2}e^{-1/(um)}\,du. E [ exp ( m i tX ) ] − 1 = m 1 exp ( R m 1 ) ∫ 0 R u 2 e i t u − 1 e − 1/ ( u m ) d u .
Multiplying by m m m ,
m ( E [ exp ( i t X m ) ] − 1 ) = exp ( 1 R m ) ∫ 0 R e i t u − 1 u 2 e − 1 / ( u m ) d u . m\left(\mathbb{E}\left[\exp\left(\frac{itX}{m}\right)\right]-1\right)=\exp\left(\frac{1}{Rm}\right)\int_{0}^{R}\frac{e^{itu}-1}{u^2}e^{-1/(um)}\,du. m ( E [ exp ( m i tX ) ] − 1 ) = exp ( R m 1 ) ∫ 0 R u 2 e i t u − 1 e − 1/ ( u m ) d u .
The integrand has a non-integrable singularity at u = 0 u=0 u = 0 , since e i t u − 1 u 2 ≈ i t u \frac{e^{itu}-1}{u^2}\approx\frac{it}{u} u 2 e i t u − 1 ≈ u i t near u = 0 u=0 u = 0 . To isolate this term, we write
e i t u − 1 = ( e i t u − 1 − i t u ) + i t u . e^{itu}-1=\left(e^{itu}-1-itu\right)+itu. e i t u − 1 = ( e i t u − 1 − i t u ) + i t u .
Accordingly,
∫ 0 R e i t u − 1 u 2 e − 1 / ( u m ) d u = ∫ 0 R ( e i t u − 1 − i t u u 2 ) e − 1 / ( u m ) d u + i t ∫ 0 R 1 u e − 1 / ( u m ) d u . \int_{0}^{R} \frac{e^{itu}-1}{u^2}e^{-1/(um)}\,du
=
\int_{0}^{R}\left(\frac{e^{itu}-1-itu}{u^2}\right)e^{-1/(um)}\,du
+it\int_{0}^{R}\frac{1}{u}e^{-1/(um)}\,du. ∫ 0 R u 2 e i t u − 1 e − 1/ ( u m ) d u = ∫ 0 R ( u 2 e i t u − 1 − i t u ) e − 1/ ( u m ) d u + i t ∫ 0 R u 1 e − 1/ ( u m ) d u .
We evaluate the second integral by substituting v = 1 u m v=\frac{1}{um} v = u m 1 and thus d u = − 1 v 2 m d v du=-\frac{1}{v^2m}\,dv d u = − v 2 m 1 d v , which gives
i t ∫ 0 R 1 u e − 1 / ( u m ) d u = i t ∫ 1 / ( R m ) ∞ e − v v d v = i t E 1 ( 1 R m ) , it\int_{0}^{R}\frac{1}{u}e^{-1/(um)}\,du
=
it\int_{1/(Rm)}^{\infty}\frac{e^{-v}}{v}\,dv
=
itE_1\left(\frac{1}{Rm}\right), i t ∫ 0 R u 1 e − 1/ ( u m ) d u = i t ∫ 1/ ( R m ) ∞ v e − v d v = i t E 1 ( R m 1 ) ,
where E 1 E_1 E 1 denotes the exponential integral, c.f., Definition 4.13 . Using the standard expansion E 1 ( z ) = − γ − ln z + Ein ( z ) E_1(z)=-\gamma-\ln z+\operatorname{Ein}(z) E 1 ( z ) = − γ − ln z + Ein ( z ) together with Ein ( z ) = O ( z ) \operatorname{Ein}(z)=O(z) Ein ( z ) = O ( z ) as z → 0 z\to0 z → 0 , we have
i t E 1 ( 1 R m ) = i t ( − γ + ln R + ln m ) + O ( t R m ) . itE_1\left(\frac{1}{Rm}\right)
=
it(-\gamma+\ln R+\ln m)+O\left(\frac{t}{Rm}\right). i t E 1 ( R m 1 ) = i t ( − γ + ln R + ln m ) + O ( R m t ) .
Substituting this back into Equation (3) , the logarithmic term i t ln m it\ln m i t ln m cancels the centering shift − i t ln m -it\ln m − i t ln m . For any fixed R > 0 R>0 R > 0 , the remaining error terms in the expansion of E 1 E_1 E 1 vanish as m → ∞ m\to\infty m → ∞ , and the scaling factor exp ( 1 R m ) → 1 \exp\left(\frac{1}{Rm}\right)\to1 exp ( R m 1 ) → 1 . To evaluate the limit of the first integral, we apply the Dominated Convergence Theorem, c.f., Theorem 4.12 . By Taylor’s theorem, the complex exponential satisfies ∣ e i t u − 1 − i t u ∣ ≤ t 2 u 2 2 \left|e^{itu}-1-itu\right|\leq\frac{t^2u^2}{2} e i t u − 1 − i t u ≤ 2 t 2 u 2 . Thus, the magnitude of the integrand is uniformly bounded by a continuous function independent of m m m :
∣ e i t u − 1 − i t u u 2 e − 1 / ( u m ) ∣ ≤ ∣ e i t u − 1 − i t u u 2 ∣ ≤ t 2 2 . \left|\frac{e^{itu}-1-itu}{u^2}e^{-1/(um)}\right|
\leq
\left|\frac{e^{itu}-1-itu}{u^2}\right|
\leq
\frac{t^2}{2}. u 2 e i t u − 1 − i t u e − 1/ ( u m ) ≤ u 2 e i t u − 1 − i t u ≤ 2 t 2 .
Since t 2 2 \frac{t^2}{2} 2 t 2 is integrable over the finite interval [ 0 , R ] [0,R] [ 0 , R ] and e − 1 / ( u m ) → 1 e^{-1/(um)}\to1 e − 1/ ( u m ) → 1 pointwise for u > 0 u>0 u > 0 , dominated convergence allows us to pass the limit inside the integral. Therefore, replacing the dummy variable u u u with x x x ,
lim m → ∞ ln Ψ Z m ( t ) = i t ( ln R − γ ) + ∫ 0 R e i t x − 1 − i t x x 2 d x . \lim_{m\to\infty}\ln\Psi_{Z_m}(t)
=
it(\ln R-\gamma)+\int_{0}^{R}\frac{e^{itx}-1-itx}{x^2}\,dx. m → ∞ lim ln Ψ Z m ( t ) = i t ( ln R − γ ) + ∫ 0 R x 2 e i t x − 1 − i t x d x .
It remains to evaluate the integral
I ( R ) = ∫ 0 R e i t x − 1 − i t x x 2 d x . I(R)=\int_{0}^{R}\frac{e^{itx}-1-itx}{x^2}\,dx. I ( R ) = ∫ 0 R x 2 e i t x − 1 − i t x d x .
Applying integration by parts with u = e i t x − 1 − i t x u=e^{itx}-1-itx u = e i t x − 1 − i t x and d v = d x x 2 dv=\frac{dx}{x^2} d v = x 2 d x , so that d u = i t ( e i t x − 1 ) d x du=it(e^{itx}-1)\,dx d u = i t ( e i t x − 1 ) d x and v = − 1 x v=-\frac{1}{x} v = − x 1 , we have
I ( R ) = − e i t R − 1 − i t R R + i t ∫ 0 R e i t x − 1 x d x . I(R)=-\frac{e^{itR}-1-itR}{R}+it\int_{0}^{R}\frac{e^{itx}-1}{x}\,dx. I ( R ) = − R e i tR − 1 − i tR + i t ∫ 0 R x e i t x − 1 d x .
Using Euler’s formula e i t x = cos ( t x ) + i sin ( t x ) e^{itx}=\cos(tx)+i\sin(tx) e i t x = cos ( t x ) + i sin ( t x ) , the remaining integral becomes
i t ∫ 0 R e i t x − 1 x d x = i t ∫ 0 R cos ( t x ) − 1 x d x − t ∫ 0 R sin ( t x ) x d x . it\int_{0}^{R}\frac{e^{itx}-1}{x}\,dx
=
it\int_{0}^{R}\frac{\cos(tx)-1}{x}\,dx
-
t\int_{0}^{R}\frac{\sin(tx)}{x}\,dx. i t ∫ 0 R x e i t x − 1 d x = i t ∫ 0 R x cos ( t x ) − 1 d x − t ∫ 0 R x sin ( t x ) d x .
Substituting y = t x y=tx y = t x gives
i t ∫ 0 R e i t x − 1 x d x = − i t ∫ 0 t R 1 − cos y y d y − t ∫ 0 t R sin y y d y = − i t Cin ( t R ) − t Si ( t R ) . it\int_{0}^{R}\frac{e^{itx}-1}{x}\,dx=-it\int_{0}^{tR}\frac{1-\cos y}{y}\,dy-t\int_{0}^{tR}\frac{\sin y}{y}\,dy
=-it\,\operatorname{Cin}(tR)-t\,\operatorname{Si}(tR). i t ∫ 0 R x e i t x − 1 d x = − i t ∫ 0 tR y 1 − cos y d y − t ∫ 0 tR y sin y d y = − i t Cin ( tR ) − t Si ( tR ) .
Combining the previous identities, we have
C 2 ( t ) = i t ( ln R − γ ) − e i t R − 1 − i t R R − i t Cin ( t R ) − t Si ( t R ) , C_{2}(t)=it(\ln R-\gamma)-\frac{e^{itR}-1-itR}{R}-it\,\operatorname{Cin}(tR)-t\,\operatorname{Si}(tR), C 2 ( t ) = i t ( ln R − γ ) − R e i tR − 1 − i tR − i t Cin ( tR ) − t Si ( tR ) ,
which gives the desired claim after exponentiating.
The Algorithmic Oracle: Sampling from Z \mathcal{Z} Z
Algorithm 3 and Algorithm 5 generate a sample z ∗ ∼ Z z^{*}\sim\mathcal{Z} z ∗ ∼ Z using inverse transform sampling applied to the cumulative distribution function F Z ( x ) F_{\mathcal{Z}}(x) F Z ( x ) . We use the analytic form of the Gil-Pelaez inversion formula [17 ] to evaluate this CDF:
F Z ( x ) = 1 2 − 1 π ∫ 0 ∞ Im ( e − i t x Ψ ( t ) ) t d t = 1 2 + 1 π ∫ 0 ∞ e i t x Ψ ( − t ) − e − i t x Ψ ( t ) 2 i t d t . F_{\mathcal{Z}}(x)=\frac{1}{2}-\frac{1}{\pi}\int_{0}^{\infty}\frac{\operatorname{Im}\left(e^{-itx}\Psi(t)\right)}{t}\,dt
=\frac{1}{2}+\frac{1}{\pi}\int_{0}^{\infty}\frac{e^{itx}\Psi(-t)-e^{-itx}\Psi(t)}{2it}\,dt. F Z ( x ) = 2 1 − π 1 ∫ 0 ∞ t Im ( e − i t x Ψ ( t ) ) d t = 2 1 + π 1 ∫ 0 ∞ 2 i t e i t x Ψ ( − t ) − e − i t x Ψ ( t ) d t .
We then use the fact that Ψ ( − t ) = Ψ ( t ) ‾ \Psi(-t)=\overline{\Psi(t)} Ψ ( − t ) = Ψ ( t ) in the oracle implementation in Algorithm 5.
Algorithm 5 Gil-Pelaez oracle for F Z F_{\mathcal{Z}} F Z
Input: x ∈ R x\in\mathbb{R} x ∈ R , truncation parameter R R R from Algorithm 2
Output: Approximation to F Z ( x ) F_{\mathcal{Z}}(x) F Z ( x )
U max = O ( log n ) U_{\max}=\mathcal{O}(\log n) U m a x = O ( log n ) , N = O ( log 2 n ) N=\mathcal{O}(\log^{2}n) N = O ( log 2 n ) , S = 0 S=0 S = 0
Retrieve Gauss-Legendre nodes { w m , v m } m ∈ [ N ] \{w_m,v_m\}_{m\in[N]} { w m , v m } m ∈ [ N ]
for each m ∈ [ N ] m\in[N] m ∈ [ N ] do
t m = U max 2 ( w m + 1 ) t_m=\frac{U_{\max}}{2}(w_m+1) t m = 2 U m a x ( w m + 1 )
ϕ m = exp ( i t m ( ln R − γ ) − e i t m R − 1 − i t m R R − i t m Cin ( t m R ) − t m Si ( t m R ) ) \phi_m=\exp\left(it_m(\ln R-\gamma)-\frac{e^{it_mR}-1-it_mR}{R}-it_m\operatorname{Cin}(t_mR)-t_m\operatorname{Si}(t_mR)\right) ϕ m = exp ( i t m ( ln R − γ ) − R e i t m R − 1 − i t m R − i t m Cin ( t m R ) − t m Si ( t m R ) )
I m = 1 2 i t m ( e i t m x ϕ m ‾ − e − i t m x ϕ m ) I_m=\frac{1}{2it_m}\left(e^{it_mx}\overline{\phi_m}-e^{-it_mx}\phi_m\right) I m = 2 i t m 1 ( e i t m x ϕ m − e − i t m x ϕ m )
S ← S + v m ⋅ U max 2 ⋅ I m S\leftarrow S+v_m\cdot\frac{U_{\max}}{2}\cdot I_m S ← S + v m ⋅ 2 U m a x ⋅ I m
return 1 2 + 1 π S \frac{1}{2}+\frac{1}{\pi}S 2 1 + π 1 S
Domain Truncation via Exponential Decay
A direct evaluation of the Gil-Pelaez integral over an unbounded domain is not computationally feasible. The algorithm therefore relies on structural decay of the characteristic function Ψ ( t ) \Psi(t) Ψ ( t ) to truncate the integration range while controlling error.
If Ψ ( t ) \Psi(t) Ψ ( t ) decayed only polynomially, any truncation achieving error ν \nu ν would typically require a polynomial integration bound U max U_{\max} U m a x , leading to a corresponding polynomial number of quadrature nodes. In contrast, the exponential decay established below permits truncation at U max = Θ ( log n ) U_{\max} = \Theta(\log n) U m a x = Θ ( log n ) , which is sufficient for the desired accuracy and preserves polylogarithmic complexity.
Lemma 6.1 (Exponential Decay and Domain Truncation). For t ∈ R t \in\mathbb{R} t ∈ R , the characteristic function satisfies the global bound
∣ Ψ ( t ) ∣ ≤ exp ( 2 R − κ ∣ t ∣ ) . |\Psi(t)| \leq\exp\left(\frac{2}{R} - \kappa|t|\right). ∣Ψ ( t ) ∣ ≤ exp ( R 2 − κ ∣ t ∣ ) . where κ = inf x ≥ 1 S i ( x ) > 0 \kappa= \inf_{x \geq1} \mathrm{Si}(x) > 0 κ = inf x ≥ 1 Si ( x ) > 0 . Consequently, truncating the Gil-Pelaez integral to U max = Θ ( log n ) U_{\max} = \Theta(\log n) U m a x = Θ ( log n ) bounds the truncation error by at most ν / 2 \nu/2 ν /2 .
Proof. Recall from Theorem 5.2 that Ψ ( t ) = exp ( C 2 ( t ) ) \Psi(t) = \exp(C_2(t)) Ψ ( t ) = exp ( C 2 ( t )) , where C 2 ( t ) = i t ( ln R − γ ) − e i t R − 1 − i t R R − i t Cin ( t R ) − t S i ( t R ) C_2(t) = it(\ln R - \gamma) - \frac{e^{itR}-1-itR}{R} - it\operatorname{Cin}(tR) - t\mathrm{Si}(tR) C 2 ( t ) = i t ( ln R − γ ) − R e i tR − 1 − i tR − i t Cin ( tR ) − t Si ( tR ) and γ \gamma γ denotes the Euler-Mascheroni constant. Also recall that for any complex number z = A + i B z = A + iB z = A + i B , ∣ e z ∣ = ∣ e A e i B ∣ = e A |e^z| = |e^A e^{iB}| = e^A ∣ e z ∣ = ∣ e A e i B ∣ = e A , since ∣ e i B ∣ = 1 |e^{iB}| = 1 ∣ e i B ∣ = 1 . Thus, ∣ Ψ ( t ) ∣ = exp ( Re ( C 2 ( t ) ) ) |\Psi(t)| = \exp(\operatorname{Re}(C_2(t))) ∣Ψ ( t ) ∣ = exp ( Re ( C 2 ( t ))) , so it suffices to bound the real part of the exponent.
For real t ∈ R t \in\mathbb{R} t ∈ R , the terms i t ( ln R − γ ) it(\ln R - \gamma) i t ( ln R − γ ) and − i t Cin ( t R ) -it\operatorname{Cin}(tR) − i t Cin ( tR ) are purely imaginary and therefore contribute nothing to Re ( C 2 ( t ) ) \operatorname{Re}(C_2(t)) Re ( C 2 ( t )) . Expanding the remaining term using Euler’s formula gives
Re ( C 2 ( t ) ) = Re ( − e i t R − 1 − i t R R ) − t S i ( t R ) = Re ( − cos ( t R ) + i sin ( t R ) − 1 − i t R R ) − t S i ( t R ) = 1 − cos ( t R ) R − t S i ( t R ) . \begin{aligned}
\operatorname{Re}(C_2(t)) = \operatorname{Re}\left(-\frac{e^{itR}-1-itR}{R}\right) - t\mathrm{Si}(tR) \\
&= \operatorname{Re}\left(-\frac{\cos(tR)+i\sin(tR)-1-itR}{R}\right) - t\mathrm{Si}(tR) \\
&= \frac{1-\cos(tR)}{R} - t\mathrm{Si}(tR).
\end{aligned} Re ( C 2 ( t )) = Re ( − R e i tR − 1 − i tR ) − t Si ( tR ) = Re ( − R cos ( tR ) + i sin ( tR ) − 1 − i tR ) − t Si ( tR ) = R 1 − cos ( tR ) − t Si ( tR ) .
Moreover, recall that S i ( x ) = ∫ 0 x sin u u d u \mathrm{Si}(x) = \int_0^x \frac{\sin u}{u}\,du Si ( x ) = ∫ 0 x u s i n u d u . Since sin u u \frac{\sin u}{u} u s i n u is even, S i \mathrm{Si} Si is odd, so t S i ( t R ) = ∣ t ∣ S i ( ∣ t ∣ R ) t\mathrm{Si}(tR) = |t|\mathrm{Si}(|t|R) t Si ( tR ) = ∣ t ∣ Si ( ∣ t ∣ R ) . We split the analysis into two regimes based on ∣ t ∣ R |t|R ∣ t ∣ R .
First, consider the regime ∣ t ∣ ≥ 1 R |t| \geq\frac{1}{R} ∣ t ∣ ≥ R 1 , i.e., ∣ t ∣ R ≥ 1 |t|R \geq1 ∣ t ∣ R ≥ 1 . Since cos ( t R ) ∈ [ − 1 , 1 ] \cos(tR) \in[-1,1] cos ( tR ) ∈ [ − 1 , 1 ] , we have
1 − cos ( t R ) R ≤ 2 R . \frac{1-\cos(tR)}{R} \leq\frac{2}{R}. R 1 − cos ( tR ) ≤ R 2 .
Over the interval [ 1 , ∞ ) [1,\infty) [ 1 , ∞ ) , the function S i ( x ) \mathrm{Si}(x) Si ( x ) remains strictly positive, so
− t S i ( t R ) ≤ − κ ∣ t ∣ , -t\mathrm{Si}(tR) \leq-\kappa|t|, − t Si ( tR ) ≤ − κ ∣ t ∣ ,
where κ : = inf x ≥ 1 S i ( x ) > 0 \kappa:= \inf_{x \geq1}\mathrm{Si}(x) > 0 κ := inf x ≥ 1 Si ( x ) > 0 . Combining the bounds, for the regime ∣ t ∣ R ≥ 1 |t|R \geq1 ∣ t ∣ R ≥ 1 we have
Re ( C 2 ( t ) ) ≤ 2 R − κ ∣ t ∣ . \operatorname{Re}(C_2(t)) \leq\frac{2}{R} - \kappa|t|. Re ( C 2 ( t )) ≤ R 2 − κ ∣ t ∣.
Alternatively, consider the complementary regime ∣ t ∣ R < 1 |t|R < 1 ∣ t ∣ R < 1 . Observe that the function f ( u ) = 1 − cos u − u S i ( u ) f(u) = 1-\cos u-u\mathrm{Si}(u) f ( u ) = 1 − cos u − u Si ( u ) satisfies f ( 0 ) = 0 f(0)=0 f ( 0 ) = 0 and f ′ ( u ) = sin u − ( S i ( u ) + u sin u u ) = − S i ( u ) f'(u) = \sin u - \left(\mathrm{Si}(u) + u\frac{\sin u}{u}\right) = -\mathrm{Si}(u) f ′ ( u ) = sin u − ( Si ( u ) + u u s i n u ) = − Si ( u ) . Since S i ( u ) ≥ 0 \mathrm{Si}(u) \geq0 Si ( u ) ≥ 0 for u ≥ 0 u \geq0 u ≥ 0 , we have f ′ ( u ) ≤ 0 f'(u) \leq0 f ′ ( u ) ≤ 0 , which implies f ( u ) ≤ 0 f(u) \leq0 f ( u ) ≤ 0 for all u ≥ 0 u \geq0 u ≥ 0 . Setting u = ∣ t ∣ R u=|t|R u = ∣ t ∣ R , we obtain
Re ( C 2 ( t ) ) = f ( ∣ t ∣ R ) R ≤ 0. \operatorname{Re}(C_2(t)) = \frac{f(|t|R)}{R} \leq0. Re ( C 2 ( t )) = R f ( ∣ t ∣ R ) ≤ 0.
Furthermore, because κ = inf x ≥ 1 S i ( x ) ≤ S i ( 1 ) = ∫ 0 1 sin u u d u < ∫ 0 1 1 d u = 1 \kappa= \inf_{x \geq1}\mathrm{Si}(x) \leq\mathrm{Si}(1) = \int_0^1 \frac{\sin u}{u}\,du < \int_0^1 1\,du = 1 κ = inf x ≥ 1 Si ( x ) ≤ Si ( 1 ) = ∫ 0 1 u s i n u d u < ∫ 0 1 1 d u = 1 , we have κ < 2 \kappa< 2 κ < 2 . Thus, for ∣ t ∣ < 1 R |t| < \frac{1}{R} ∣ t ∣ < R 1 , we have κ ∣ t ∣ < κ R < 2 R \kappa|t| < \frac{\kappa}{R} < \frac{2}{R} κ ∣ t ∣ < R κ < R 2 , which implies 2 R − κ ∣ t ∣ > 0 \frac{2}{R} - \kappa|t| > 0 R 2 − κ ∣ t ∣ > 0 . Therefore, in this regime we also trivially have
Re ( C 2 ( t ) ) ≤ 0 < 2 R − κ ∣ t ∣ . \operatorname{Re}(C_2(t)) \leq0 < \frac{2}{R} - \kappa|t|. Re ( C 2 ( t )) ≤ 0 < R 2 − κ ∣ t ∣.
Hence, the bound
∣ Ψ ( t ) ∣ ≤ exp ( 2 R − κ ∣ t ∣ ) |\Psi(t)| \le\exp\left(\frac{2}{R}-\kappa|t|\right) ∣Ψ ( t ) ∣ ≤ exp ( R 2 − κ ∣ t ∣ )
for all t ∈ R t \in\mathbb{R} t ∈ R .
We now bound the truncation error in the Gil-Pelaez inversion formula due to the integrand
1 π ∫ 0 ∞ e i t x Ψ ( − t ) − e − i t x Ψ ( t ) 2 i t d t . \frac{1}{\pi}\int_0^\infty\frac{e^{itx}\Psi(-t)-e^{-itx}\Psi(t)}{2it}\,dt. π 1 ∫ 0 ∞ 2 i t e i t x Ψ ( − t ) − e − i t x Ψ ( t ) d t .
Using the triangle inequality, ∣ e ± i t x ∣ = 1 |e^{\pm itx}| = 1 ∣ e ± i t x ∣ = 1 for real t , x t,x t , x , and the Hermitian symmetry ∣ Ψ ( − t ) ∣ = ∣ Ψ ( t ) ∣ |\Psi(-t)| = |\Psi(t)| ∣Ψ ( − t ) ∣ = ∣Ψ ( t ) ∣ , we obtain
∣ e i t x Ψ ( − t ) − e − i t x Ψ ( t ) 2 i t ∣ ≤ ∣ Ψ ( t ) ∣ t . \left|\frac{e^{itx}\Psi(-t)-e^{-itx}\Psi(t)}{2it}\right| \le\frac{|\Psi(t)|}{t}. 2 i t e i t x Ψ ( − t ) − e − i t x Ψ ( t ) ≤ t ∣Ψ ( t ) ∣ .
For sufficiently large U max ≥ 1 U_{\max} \ge1 U m a x ≥ 1 , we additionally have 1 t ≤ 1 \frac{1}{t} \le1 t 1 ≤ 1 over the integration domain, so
∫ U max ∞ ∣ Ψ ( t ) ∣ t d t ≤ ∫ U max ∞ exp ( 2 R − κ ∣ t ∣ ) t d t ≤ ∫ U max ∞ e 2 / R − κ t d t = 1 κ e 2 / R − κ ⋅ U max . \begin{aligned}
\int_{U_{\max}}^\infty\frac{|\Psi(t)|}{t}\,dt \le\int_{U_{\max}}^\infty\frac{\exp\left(\frac{2}{R}-\kappa|t|\right)}{t}\,dt \\
&\le\int_{U_{\max}}^\infty e^{2/R-\kappa t}\,dt = \frac{1}{\kappa}e^{2/R-\kappa\cdot U_{\max}}.
\end{aligned} ∫ U m a x ∞ t ∣Ψ ( t ) ∣ d t ≤ ∫ U m a x ∞ t exp ( R 2 − κ ∣ t ∣ ) d t ≤ ∫ U m a x ∞ e 2/ R − κ t d t = κ 1 e 2/ R − κ ⋅ U m a x .
By Lemma 5.1 , we have 1 R = Θ ( log n ) \frac{1}{R} = \Theta(\log n) R 1 = Θ ( log n ) , so it suffices to set U max = Θ ( log n ) U_{\max} = \Theta(\log n) U m a x = Θ ( log n ) to achieve a desired truncation bound of ν = n − c \nu= n^{-c} ν = n − c while preserving polylogarithmic complexity.
Gauss-Legendre Quadrature on a Bounded Domain
We approximate the truncated integral
∫ 0 U max g ( t ) d t , g ( t ) = e i t x Ψ ( − t ) − e − i t x Ψ ( t ) 2 i t , \int_0^{U_{\max}} g(t)\,dt,\qquad g(t)=\frac{e^{itx}\Psi(-t)-e^{-itx}\Psi(t)}{2it}, ∫ 0 U m a x g ( t ) d t , g ( t ) = 2 i t e i t x Ψ ( − t ) − e − i t x Ψ ( t ) ,
using Gauss-Legendre quadrature.
Analyticity considerations. The exponential decay from Lemma 6.1 ensures that the integrand remains well-controlled on a finite interval. This avoids the need to evaluate the characteristic function in regimes where the oscillatory term e i t R e^{itR} e i tR becomes numerically unstable. Crucially, by utilizing the algebraic continuation g ( t ) g(t) g ( t ) , the integrand is an entire function, entirely avoiding the Cauchy-Riemann violations associated with the imaginary projection. Restricting to U max = Θ ( log n ) U_{\max} = \Theta(\log n) U m a x = Θ ( log n ) ensures that ∣ t R ∣ = Θ ( 1 ) |tR| = \Theta(1) ∣ tR ∣ = Θ ( 1 ) uniformly over the complex integration domain, which keeps all special-function evaluations bounded and compatible with standard quadrature convergence theory [45 ] .
Theorem 6.2 (Polylogarithmic CDF Oracle). Given ν = n − c \nu= n^{-c} ν = n − c , the CDF F Z ( x ) F_Z(x) F Z ( x ) can be evaluated to absolute additive error ν \nu ν using N = O ( log 2 n ) N = O(\log^2 n) N = O ( log 2 n ) Gauss-Legendre nodes.
Proof. Let g ( t ) = e i t x Ψ ( − t ) − e − i t x Ψ ( t ) 2 i t g(t) = \frac{e^{itx}\Psi(-t)-e^{-itx}\Psi(t)}{2it} g ( t ) = 2 i t e i t x Ψ ( − t ) − e − i t x Ψ ( t ) , which is the analytic continuation used to compute the Gil-Pelaez integrand over the truncated interval [ 0 , U max ] [0,U_{\max}] [ 0 , U m a x ] . Because Ψ ( t ) \Psi(t) Ψ ( t ) is composed of entire functions and the quotient has a removable singularity at t = 0 t = 0 t = 0 , g ( t ) g(t) g ( t ) extends analytically to the entire complex plane. Thus, classical results for Gauss-Legendre quadrature apply [45 ] . The convergence rate is determined by how far the integrand can be analytically continued into the complex plane around the integration interval. This neighborhood is measured using a Bernstein ellipse E ρ E_\rho E ρ , i.e., an ellipse in the complex plane with foci at ± 1 \pm1 ± 1 that encloses [ − 1 , 1 ] [-1,1] [ − 1 , 1 ] , whose size controls the exponential convergence rate; its parameter ρ > 1 \rho> 1 ρ > 1 is a single scalar describing how “large” the ellipse is (larger ρ \rho ρ corresponds to a fatter ellipse and faster convergence). If g g g remains analytic inside E ρ E_\rho E ρ , then the error for the quadrature evaluation Q N ( g ) Q_N(g) Q N ( g ) satisfies
∣ ∫ 0 U max g ( t ) d t − Q N ( g ) ∣ ≤ O ( U max M g ρ 2 N ) . \left|\int_{0}^{U_{\max}} g(t)\,\mathrm{d}t-Q_N(g)\right| \le O\left(U_{\max}\frac{M_g}{\rho^{2N}}\right). ∫ 0 U m a x g ( t ) d t − Q N ( g ) ≤ O ( U m a x ρ 2 N M g ) .
where M g = sup z ∈ E ρ ∣ g ( z ) ∣ M_g=\sup_{z\in E_\rho}|g(z)| M g = sup z ∈ E ρ ∣ g ( z ) ∣ [45 ] , and the U max U_{\max} U m a x factor accounts for the affine scaling of the integration interval. We map the standard interval [ − 1 , 1 ] [-1,1] [ − 1 , 1 ] to [ 0 , U max ] [0,U_{\max}] [ 0 , U m a x ] via t = U max 2 ( w + 1 ) t=\frac{U_{\max}}{2}(w+1) t = 2 U m a x ( w + 1 ) . To keep the analytic continuation away from large imaginary values, we choose the ellipse in the t t t -plane so that its imaginary semi-axis remains bounded by a constant ∣ Im ( t ) ∣ ≤ 1 |\operatorname{Im}(t)|\le1 ∣ Im ( t ) ∣ ≤ 1 . Under the affine map above, this corresponds to a semi-minor axis b w = 2 U max b_w=\frac{2}{U_{\max}} b w = U m a x 2 in the w w w -plane. The corresponding Bernstein parameter is
ρ = 1 + b w 2 + b w = 1 + ( 2 U max ) 2 + 2 U max . \rho=\sqrt{1+b_w^2}+b_w=\sqrt{1+\left(\frac{2}{U_{\max}}\right)^2}+\frac{2}{U_{\max}}. ρ = 1 + b w 2 + b w = 1 + ( U m a x 2 ) 2 + U m a x 2 .
Since U max = Θ ( log n ) U_{\max}=\Theta(\log n) U m a x = Θ ( log n ) by Lemma 6.1 , ρ = 1 + Θ ( 1 U max ) \rho=1+\Theta\left(\frac{1}{U_{\max}}\right) ρ = 1 + Θ ( U m a x 1 ) , and therefore ln ρ = Θ ( 1 log n ) \ln\rho=\Theta\left(\frac{1}{\log n}\right) ln ρ = Θ ( l o g n 1 ) .
It remains to bound the maximum modulus M g M_g M g . Every point on the contour can be written as t = u + i v t=u+iv t = u + i v , where u ∈ [ 0 , U max ] u\in[0,U_{\max}] u ∈ [ 0 , U m a x ] and ∣ v ∣ ≤ 1 |v|\le1 ∣ v ∣ ≤ 1 . For the phase factors, we have
∣ e ± i t x ∣ = ∣ e ± i ( u + i v ) x ∣ = e ∓ v x ≤ e ∣ x ∣ . \left|e^{\pm itx}\right|=\left|e^{\pm i(u+iv)x}\right|=e^{\mp vx}\le e^{|x|}. e ± i t x = e ± i ( u + i v ) x = e ∓ v x ≤ e ∣ x ∣ .
Since x = O ( log n ) x=O(\log n) x = O ( log n ) over the bounds of the binary search interval, this complex phase factor is at most e O ( log n ) e^{O(\log n)} e O ( l o g n ) , contributing at most O ( log n ) O(\log n) O ( log n ) upon taking the logarithm. Near the removable singularity at the origin t = 0 t=0 t = 0 , the analytic continuation evaluates via L’Hôpital’s rule to lim t → 0 g ( t ) = x + i Ψ ′ ( 0 ) = x − ( ln R − γ ) = O ( log n ) \lim_{t\to0}g(t)=x+i\Psi'(0)=x-(\ln R-\gamma)=O(\log n) lim t → 0 g ( t ) = x + i Ψ ′ ( 0 ) = x − ( ln R − γ ) = O ( log n ) . Thus g ( t ) g(t) g ( t ) remains analytically bounded near the origin. For t t t bounded away from the origin, the dominant contribution to the modulus comes from the characteristic functions evaluated at complex arguments ± t \pm t ± t :
∣ Ψ ( ± t ) ∣ = exp ( Re ( C 2 ( ± t ) ) ) . |\Psi(\pm t)|=\exp(\operatorname{Re}(C_2(\pm t))). ∣Ψ ( ± t ) ∣ = exp ( Re ( C 2 ( ± t ))) .
where we recall C 2 ( t ) = i t ( ln R − γ ) − e i t R − 1 − i t R R − i t Cin ( t R ) − t Si ( t R ) C_2(t)=it(\ln R-\gamma)-\frac{e^{itR}-1-itR}{R}-it\,\operatorname{Cin}(tR)-t\,\operatorname{Si}(tR) C 2 ( t ) = i t ( ln R − γ ) − R e i tR − 1 − i tR − i t Cin ( tR ) − t Si ( tR ) by Theorem 5.2 . We now upper bound Re ( C 2 ( ± t ) ) \operatorname{Re}(C_2(\pm t)) Re ( C 2 ( ± t )) term by term.
First, consider the drift term
± i t ln R = ± i ( u + i v ) ln R = ∓ v ln R ± i u ln R . \pm it\ln R=\pm i(u+iv)\ln R=\mp v\ln R\pm iu\ln R. ± i t ln R = ± i ( u + i v ) ln R = ∓ v ln R ± i u ln R .
The imaginary component contributes only to phase, while the real component satisfies ∣ ∓ v ln R ∣ ≤ ln ( 1 / R ) |\mp v\ln R|\le\ln(1/R) ∣ ∓ v ln R ∣ ≤ ln ( 1/ R ) . By Lemma 5.1 , 1 R = Θ ( log n ) \frac{1}{R}=\Theta(\log n) R 1 = Θ ( log n ) , so this term contributes at most O ( log log n ) O(\log\log n) O ( log log n ) .
Next, consider the exponential remainder term. Since ∣ t R ∣ ≤ ( U max + 1 ) R |tR|\le(U_{\max}+1)R ∣ tR ∣ ≤ ( U m a x + 1 ) R , U max = Θ ( log n ) U_{\max}=\Theta(\log n) U m a x = Θ ( log n ) , and R = Θ ( 1 log n ) R=\Theta\left(\frac{1}{\log n}\right) R = Θ ( l o g n 1 ) , we obtain ∣ t R ∣ = Θ ( 1 ) |tR|=\Theta(1) ∣ tR ∣ = Θ ( 1 ) . Consequently,
∣ e ± i t R ∣ = ∣ e ± i u R e ∓ v R ∣ = e ∓ v R ≤ e R = O ( 1 ) . \left|e^{\pm itR}\right|=\left|e^{\pm iuR}e^{\mp vR}\right|=e^{\mp vR}\le e^R=O(1). e ± i tR = e ± i u R e ∓ v R = e ∓ v R ≤ e R = O ( 1 ) .
Thus the term − e ± i t R − 1 ∓ i t R R -\frac{e^{\pm itR}-1\mp itR}{R} − R e ± i tR − 1 ∓ i tR has real part upper bounded by O ( 1 R ) = O ( log n ) O\left(\frac{1}{R}\right)=O(\log n) O ( R 1 ) = O ( log n ) . Finally, over the bounded region ∣ t R ∣ = Θ ( 1 ) |tR| = \Theta(1) ∣ tR ∣ = Θ ( 1 ) , the entire functions Si ( ± t R ) \operatorname{Si}(\pm tR) Si ( ± tR ) and Cin ( ± t R ) \operatorname{Cin}(\pm tR) Cin ( ± tR ) remain uniformly bounded. Since ∣ t ∣ ≤ U max + 1 = Θ ( log n ) |t| \le U_{\max} + 1 = \Theta(\log n) ∣ t ∣ ≤ U m a x + 1 = Θ ( log n ) , the terms ∓ i t Cin ( ± t R ) \mp it\operatorname{Cin}(\pm tR) ∓ i t Cin ( ± tR ) and ∓ t Si ( ± t R ) \mp t\operatorname{Si}(\pm tR) ∓ t Si ( ± tR ) contribute at most O ( log n ) O(\log n) O ( log n ) to the real part.
Combining these estimates, we have
ln M g = sup t ∈ E ρ Re ( C 2 ( t ) ) = O ( log n ) . \ln M_g = \sup_{t \in E_\rho} \operatorname{Re}(C_2(t)) = O(\log n). ln M g = t ∈ E ρ sup Re ( C 2 ( t )) = O ( log n ) .
To achieve quadrature error at most n − c n^{-c} n − c , it suffices that U max M g ρ 2 N ≤ n − c U_{\max}\frac{M_g}{\rho^{2N}} \le n^{-c} U m a x ρ 2 N M g ≤ n − c . Since log ρ = Θ ( 1 log n ) \log\rho= \Theta\left(\frac{1}{\log n}\right) log ρ = Θ ( l o g n 1 ) , log U max = O ( log log n ) \log U_{\max} = O(\log\log n) log U m a x = O ( log log n ) , and log M g = O ( log n ) \log M_g = O(\log n) log M g = O ( log n ) , it suffices to set N = O ( log 2 n ) N = O(\log^2 n) N = O ( log 2 n ) quadrature node evaluations to achieve additive error n − c n^{-c} n − c .
Statistical Recovery and End-to-End Correctness
To finalize the perfect L 2 L_2 L 2 sampling framework, we formalize the protocol to extract the heavy-hitter index from the compressed linear sketch and prove that the returned index matches the target distribution.
The Dense Post-Processing Statistical Test
Let z ∈ R N z \in\mathbb{R}^N z ∈ R N represent the fully duplicated frequency vector. Recall that in a dense CountSketch, the matrix G ∈ R R × N G \in\mathbb{R}^{R \times N} G ∈ R R × N consists of independent standard Gaussian entries, c.f., Algorithm 4. To recover an estimate for any explicitly tracked virtual item z i , j z_{i,j} z i , j , the algorithm computes the scaled dot product between the sketch vector y = G z y = Gz y = G z and the explicit tracking weights G i , j G_{i,j} G i , j . To handle the variance, we partition the R R R rows into M = Θ ( log n ) M = \Theta(\log n) M = Θ ( log n ) independent blocks, each containing r = Θ ( log n ) r = \Theta(\log n) r = Θ ( log n ) rows. Let Z Z Z be a 2-approximation of ∥ z ∥ 2 \lVert z\rVert_2 ∥ z ∥ 2 .
Figure 2. Statistical test for the perfect L 2 L_2 L 2 sampler.
(1) Construct the vector z ∈ R n ′ z \in\mathbb{R}^{n'} z ∈ R n ′ with entries given by { H i , N i } \{\mathcal{H}_i, N_i\} { H i , N i } , where n ′ = O ( n log n ) n' = O(n\log n) n ′ = O ( n log n ) .
(2) Let z ~ D ( 1 ) \widetilde{z}_{D(1)} z D ( 1 ) and z ~ D ( 2 ) \widetilde{z}_{D(2)} z D ( 2 ) denote the dense CountSketch estimates of the two largest coordinates in ⋃ i = 1 n H i \bigcup_{i=1}^{n}\mathcal{H}_i ⋃ i = 1 n H i , using R R R rows.
(3) Let Z Z Z be a 2-approximation to ∥ z ∥ 2 \lVert z\rVert_2 ∥ z ∥ 2 computed from the dense CountSketch.
(4) Sample μ \mu μ uniformly from the interval [ 0.99 , 1.01 ] [0.99,1.01] [ 0.99 , 1.01 ] , where ε \varepsilon ε is a fixed parameter.
(5) If ∣ z ~ D ( 1 ) ∣ − ∣ z ~ D ( 2 ) ∣ < 100 μ ε Z |\widetilde{z}_{D(1)}| - |\widetilde{z}_{D(2)}| < 100\mu\varepsilon Z ∣ z D ( 1 ) ∣ − ∣ z D ( 2 ) ∣ < 100 μ εZ or ∣ z ~ D ( 2 ) ∣ < 50 μ ε Z |\widetilde{z}_{D(2)}| < 50\mu\varepsilon Z ∣ z D ( 2 ) ∣ < 50 μ εZ , return FAIL.
(6) Otherwise, the statistical test succeeds.
We directly leverage the statistical gap test properties proven in [43 ] . The following statements assert that the dense CountSketch gap test does not bias the output distribution, and that it succeeds with constant probability.
Lemma 7.1 (Lemma 4.2 in [43 ] ). For any constant p ∈ ( 0 , 2 ] p \in(0,2] p ∈ ( 0 , 2 ] and ν = Θ ( n − ζ / 20 ) \nu= \Theta(n^{-\zeta/20}) ν = Θ ( n − ζ /20 ) , we have
Pr [ ¬ F A I L ∣ D ( 1 ) ] = Pr [ ¬ F A I L ] ± n − O ( c ) \Pr[\neg\mathrm{FAIL} \mid D(1)] = \Pr[\neg\mathrm{FAIL}] \pm n^{-O(c)} Pr [ ¬ FAIL ∣ D ( 1 )] = Pr [ ¬ FAIL ] ± n − O ( c ) for all possible D ( 1 ) ∈ [ N ] D(1) \in[N] D ( 1 ) ∈ [ N ] .
Lemma 7.2 (Lemma 4.7 in [43 ] ). Let ε = 1 Θ ( log n ) \varepsilon= \frac{1}{\Theta(\sqrt{\log n})} ε = Θ ( l o g n ) 1 . Then with probability at least 0.75, we have both ∣ z D ( 1 ) ∣ − ∣ z D ( 2 ) ∣ = Θ ( k ∥ x ∥ 2 ) |z_{D(1)}| - |z_{D(2)}| = \Theta(\sqrt{k}\|x\|_2) ∣ z D ( 1 ) ∣ − ∣ z D ( 2 ) ∣ = Θ ( k ∥ x ∥ 2 ) and the statistical test succeeds.
Putting together Lemma 7.1 and Lemma 7.2, we have:
Lemma 7.3 (Ideal Distribution and Target Gap). Let D ( 1 ) D(1) D ( 1 ) be the coordinate that maximizes the unsketched, perfect virtual vector z z z . Then we have Pr [ D ( 1 ) = j ] = x j 2 ∥ x ∥ 2 2 \Pr[D(1) = j] = \frac{x_j^2}{\|x\|_2^2} Pr [ D ( 1 ) = j ] = ∥ x ∥ 2 2 x j 2 .
Proof. To find the maximum magnitude in the virtual vector z z z , we can equivalently look for the minimum of the squared reciprocal values. Let
M i , j : = 1 z i , j 2 = E i , j x i 2 . M_{i,j} := \frac{1}{z_{i,j}^{2}} = \frac{E_{i,j}}{x_i^2}. M i , j := z i , j 2 1 = x i 2 E i , j .
Because E i , j ∼ Exp ( 1 ) E_{i,j} \sim\operatorname{Exp}(1) E i , j ∼ Exp ( 1 ) , standard scaling of exponential random variables implies that M i , j M_{i,j} M i , j follows an exponential distribution with rate parameter λ i = x i 2 \lambda_i = x_i^2 λ i = x i 2 , denoted M i , j ∼ Exp ( x i 2 ) M_{i,j} \sim\operatorname{Exp}(x_i^2) M i , j ∼ Exp ( x i 2 ) . Moreover, the global maximum magnitude ∣ z D ( 1 ) ∣ |z_{D(1)}| ∣ z D ( 1 ) ∣ corresponds to the global minimum V 1 : = min i , j M i , j V_1 := \min_{i,j} M_{i,j} V 1 := min i , j M i , j . Since the collection { M i , j } \{M_{i,j}\} { M i , j } consists of n × k n \times k n × k mutually independent exponential random variables, the probability that the minimum belongs to a specific copy j j j of coordinate c c c is given by the ratio of its rate to the total sum of all rates:
Pr [ M c , j = V 1 ] = x c 2 ∑ i = 1 n ∑ m = 1 k x i 2 = x c 2 k ∥ x ∥ 2 2 . \Pr[M_{c,j} = V_1] = \frac{x_c^2}{\sum_{i=1}^{n}\sum_{m=1}^{k} x_i^2} = \frac{x_c^2}{k\|x\|_2^2}. Pr [ M c , j = V 1 ] = ∑ i = 1 n ∑ m = 1 k x i 2 x c 2 = k ∥ x ∥ 2 2 x c 2 .
Because each coordinate c c c is duplicated k k k times, the total probability that the global maximum corresponds to coordinate c c c is the sum of these mutually exclusive events:
Pr [ D ( 1 ) ∈ C c ] = ∑ j = 1 k x c 2 k ∥ x ∥ 2 2 = x c 2 ∥ x ∥ 2 2 . \Pr[D(1) \in C_c] = \sum_{j=1}^{k} \frac{x_c^2}{k\|x\|_2^2} = \frac{x_c^2}{\|x\|_2^2}. Pr [ D ( 1 ) ∈ C c ] = j = 1 ∑ k k ∥ x ∥ 2 2 x c 2 = ∥ x ∥ 2 2 x c 2 .
Hence, we recover the desired L 2 L_2 L 2 sampling distribution.
Bounding the Algorithmic Simulation Error
To show that the sampler is statistically close to the desired distribution, we upper bound two sources of approximation error:
Head approximation error: The discrepancy between the finite distribution governing the largest coordinates and its continuous stable limit.
Tail approximation error: The perturbation introduced by numerically evaluating the limiting tail distribution, including the resulting Kolmogorov-Smirnov (KS) error from the quadrature procedure.
Instead of directly coupling the characteristic functions of the finite and limiting constructions, we work in the point process framework developed by [43 ] , which is more stable for analyzing extreme order statistics.
Lemma 7.4 (Lemma 4.14 in [43 ] ). Let A = [ y 0 , ∞ ) A=[y_0,\infty) A = [ y 0 , ∞ ) denote the region capturing the top τ = Θ ( log n ) \tau=\Theta(\log n) τ = Θ ( log n ) normalized inverse exponential variables. Then the total variation distance between the finite point process induced by the exact construction and its limiting continuous point process, restricted to A A A , is bounded by O ( n − C / 2 ) O\left(n^{-C/2}\right) O ( n − C /2 ) .
The tail component is obtained by numerically evaluating a truncated limiting 1-stable CDF using Gauss-Legendre quadrature. This introduces a controlled additive error in the evaluations of the limiting CDF. Rather than translating this error into a point-wise perturbation of the sampled quantile or of the induced variance, we compare the resulting numerical sampler directly with the limiting distribution in total variation distance. We then propagate this guarantee through the variance transformation and the Gaussian sketch using the data processing inequality.
Lemma 7.5 (Numerical Tail Sampling in Total Variation). Fix constants 0 < a < b 0<a<b 0 < a < b . Suppose R ∈ [ a log n , b log n ] R\in\left[\frac{a}{\log n},\frac{b}{\log n}\right] R ∈ [ l o g n a , l o g n b ] . Let Z Z Z denote the limiting distribution from Theorem 5.2 , with CDF F Z F_Z F Z and density f Z f_Z f Z . Suppose Algorithm 3 performs binary search on [ − B , B ] [-B,B] [ − B , B ] , terminates when the interval width is at most h h h , and, after termination, returns a uniformly random point in the final interval. Suppose furthermore that every CDF evaluation has additive error at most η \eta η . Let Z ^ \widehat{Z} Z denote the resulting sample. Then
d T V ( Z ^ , Z ) ≤ O ( B h η ) + Pr [ ∣ Z ∣ > B ] + O ( B h ∥ f Z ′ ∥ ∞ ) . d_{TV}(\widehat{Z},Z)\leq O\left(\frac{B}{h}\eta\right)+\Pr[|Z|>B]+O\left(Bh\|f_Z'\|_\infty\right). d T V ( Z , Z ) ≤ O ( h B η ) + Pr [ ∣ Z ∣ > B ] + O ( B h ∥ f Z ′ ∥ ∞ ) . Consequently, for every fixed c > 0 c>0 c > 0 , by taking B = Θ ( log n ) B=\Theta(\log n) B = Θ ( log n ) , h = n − C b i n h=n^{-C_{\mathrm{bin}}} h = n − C bin , and η = n − C c d f \eta=n^{-C_{\mathrm{cdf}}} η = n − C cdf for sufficiently large constants C b i n , C c d f C_{\mathrm{bin}},C_{\mathrm{cdf}} C bin , C cdf , we have d T V ( Z ^ , Z ) ≤ O ( n − c ) d_{TV}(\widehat{Z},Z)\leq O(n^{-c}) d T V ( Z , Z ) ≤ O ( n − c ) .
Proof. Let Z ‾ \overline{Z} Z denote the output of the same binary-search procedure when every comparison uses the exact CDF F Z F_Z F Z , coupled to Z ^ \widehat{Z} Z using the same random variables U U U and W W W .
The binary-search tree has O ( B / h ) O(B/h) O ( B / h ) possible internal comparison points. At any such point q q q , the exact and numerical comparisons can differ only when U U U lies between F Z ( q ) F_Z(q) F Z ( q ) and its numerical approximation. Since the CDF approximation error is at most η \eta η , this occurs with probability at most η \eta η . A union bound therefore gives
d T V ( Z ^ , Z ‾ ) ≤ O ( B h η ) . d_{TV}(\widehat{Z},\overline{Z})\leq O\left(\frac{B}{h}\eta\right). d T V ( Z , Z ) ≤ O ( h B η ) .
We next compare Z ‾ \overline{Z} Z with Z Z Z . On every interior terminal interval I I I of width at most h h h , the density of Z ‾ \overline{Z} Z is the average of f Z f_Z f Z over I I I . Hence, for x ∈ I x\in I x ∈ I ,
∣ f Z ( x ) − 1 ∣ I ∣ ∫ I f Z ( y ) d y ∣ ≤ h ∥ f Z ′ ∥ ∞ . \left|f_Z(x)-\frac{1}{|I|}\int_I f_Z(y)\,\mathrm{d}y\right|\leq h\|f_Z'\|_\infty. f Z ( x ) − ∣ I ∣ 1 ∫ I f Z ( y ) d y ≤ h ∥ f Z ′ ∥ ∞ .
Summing over the intervals contained in [ − B , B ] [-B,B] [ − B , B ] gives
d T V ( Z ‾ , Z ) ≤ Pr [ ∣ Z ∣ > B ] + O ( B h ∥ f Z ′ ∥ ∞ ) . d_{TV}(\overline{Z},Z)\leq\Pr[|Z|>B]+O\left(Bh\|f_Z'\|_\infty\right). d T V ( Z , Z ) ≤ Pr [ ∣ Z ∣ > B ] + O ( B h ∥ f Z ′ ∥ ∞ ) .
Thus
d T V ( Z ^ , Z ) ≤ O ( B h η ) + Pr [ ∣ Z ∣ > B ] + O ( B h ∥ f Z ′ ∥ ∞ ) . d_{TV}(\widehat{Z},Z)\leq O\left(\frac{B}{h}\eta\right)+\Pr[|Z|>B]+O\left(Bh\|f_Z'\|_\infty\right). d T V ( Z , Z ) ≤ O ( h B η ) + Pr [ ∣ Z ∣ > B ] + O ( B h ∥ f Z ′ ∥ ∞ ) .
It remains to bound the last two terms. From the proof of Theorem 5.2 , for s ∈ { − 1 , 1 } s \in\{-1,1\} s ∈ { − 1 , 1 } ,
log E [ exp ( s Z ) ] = s ( log R − γ ) + ∫ 0 R e s u − 1 − s u u 2 d u . \log\mathbb{E}[\exp(s\mathcal{Z})] = s(\log R-\gamma) + \int_{0}^{R} \frac{e^{su}-1-su}{u^{2}}\,du. log E [ exp ( s Z )] = s ( log R − γ ) + ∫ 0 R u 2 e s u − 1 − s u d u .
Since R = Θ ( 1 / log n ) R=\Theta(1/\log n) R = Θ ( 1/ log n ) , both exponential moments are n o ( 1 ) n^{o(1)} n o ( 1 ) . Hence, by Markov’s inequality, for B = C B log n B=C_B\log n B = C B log n with C B C_B C B sufficiently large,
Pr [ ∣ Z ∣ > B ] ≤ n − c − 2 . \Pr[|\mathcal{Z}|>B]\le n^{-c-2}. Pr [ ∣ Z ∣ > B ] ≤ n − c − 2 .
Moreover, through Fourier inversion and Lemma 6.1 , we have
∥ f Z ′ ∥ ∞ ≤ 1 2 π ∫ R ∣ t ∣ ∣ Ψ Z ( t ) ∣ d t ≤ 1 2 π ∫ R ∣ t ∣ exp ( 2 R − κ ∣ t ∣ ) d t = n O ( 1 ) . \|f'_{\mathcal{Z}}\|_{\infty}\le\frac{1}{2\pi}\int_{\mathbb{R}}|t||\Psi_{\mathcal{Z}}(t)|\,dt\le\frac{1}{2\pi}\int_{\mathbb{R}}|t|\exp\left(\frac{2}{R}-\kappa|t|\right)\,dt=n^{O(1)}. ∥ f Z ′ ∥ ∞ ≤ 2 π 1 ∫ R ∣ t ∣∣ Ψ Z ( t ) ∣ d t ≤ 2 π 1 ∫ R ∣ t ∣ exp ( R 2 − κ ∣ t ∣ ) d t = n O ( 1 ) .
Taking h = n − C b i n h=n^{-C_{\mathrm{bin}}} h = n − C bin and η = n − C c d f \eta=n^{-C_{\mathrm{cdf}}} η = n − C cdf for sufficiently large constants finishes the proof. The required CDF accuracy is achievable with O ( log 2 n ) O\left(\log^{2}n\right) O ( log 2 n ) quadrature nodes by Theorem 6.2 .
Lemma 7.6 (Tail Simulation under Post-Processing). Let Z Z Z and Z ~ \widetilde{Z} Z be random variables satisfying d T V ( Z , Z ~ ) ≤ ε d_{TV}(Z,\widetilde{Z})\le\varepsilon d T V ( Z , Z ) ≤ ε . Let T ( z ) = max ( 0 , m ( z + log m ) ) T(z)=\max(0,m(z+\log m)) T ( z ) = max ( 0 , m ( z + log m )) . Then d T V ( T ( Z ) , T ( Z ~ ) ) ≤ ε d_{TV}(T(Z),T(\widetilde{Z}))\le\varepsilon d T V ( T ( Z ) , T ( Z )) ≤ ε . Furthermore, for any fixed x ∈ R x\in\mathbb{R} x ∈ R and any number s s s of sketch rows, if G ∼ N ( 0 , I s ) G\sim\mathcal{N}(0,I_s) G ∼ N ( 0 , I s ) is independent randomness, then
d T V ( x T ( Z ) G , x T ( Z ~ ) G ) ≤ ε . d_{TV}\left(x\sqrt{T(Z)}G,x\sqrt{T(\widetilde{Z})}G\right)\le\varepsilon. d T V ( x T ( Z ) G , x T ( Z ) G ) ≤ ε . The same bound holds after any subsequent deterministic or randomized post-processing of these sketch values.
Proof. The map z ↦ T ( z ) z\mapsto T(z) z ↦ T ( z ) is deterministic, so the first claim follows from the data processing inequality for total variation distance. Conditioned on T ( Z ) = v T(Z)=v T ( Z ) = v , the Gaussian sketch contribution is generated from the Markov kernel
v ↦ N ( 0 , x 2 v I s ) . v\mapsto\mathcal{N}(0,x^{2}vI_s). v ↦ N ( 0 , x 2 v I s ) .
Applying a Markov kernel cannot increase total variation distance, which proves the second claim. The final statement follows from another application of data processing.
Lemma 7.7 (Rate of convergence for tail simulation). Let Z m = 1 m ∑ j = 1 m X j − log m Z_m=\frac{1}{m}\sum_{j=1}^{m}X_j-\log m Z m = m 1 ∑ j = 1 m X j − log m , where the variables X j X_j X j are independent with probability density function f X ( x ) = C R x − 2 e − 1 / x 1 ( 0 , R m ] ( x ) f_X(x)=C_Rx^{-2}e^{-1/x}1_{(0,Rm]}(x) f X ( x ) = C R x − 2 e − 1/ x 1 ( 0 , R m ] ( x ) , where
C R = 1 Pr [ Y ≤ R m ] ≤ 2. C_R=\frac{1}{\Pr[Y\le Rm]}\le2. C R = Pr [ Y ≤ R m ] 1 ≤ 2. Suppose m = Ω ( n C ) m=\Omega(n^C) m = Ω ( n C ) and for fixed constants 0 < a < b < ∞ 0<a<b<\infty 0 < a < b < ∞ , R ∈ [ a log n , b log n ] R\in\left[\frac{a}{\log n},\frac{b}{\log n}\right] R ∈ [ l o g n a , l o g n b ] . Then for every fixed c > 0 c>0 c > 0 and for sufficiently large C > 0 C>0 C > 0 , we have
d T V ( Z m , Z ) ≤ O ( n − c ) , d_{TV}(Z_m,\mathcal{Z})\le O(n^{-c}), d T V ( Z m , Z ) ≤ O ( n − c ) , where Z \mathcal{Z} Z denotes the limiting distribution.
Proof. Let Ψ Z m \Psi_{Z_m} Ψ Z m and Ψ Z \Psi_Z Ψ Z denote the characteristic functions of Z m Z_m Z m and Z Z Z , and let f Z m f_{Z_m} f Z m and f Z f_Z f Z denote their probability density functions. By Fourier inversion,
∥ f Z m − f Z ∥ ∞ ≤ 1 2 π ∫ − ∞ ∞ ∣ Ψ Z m ( t ) − Ψ Z ( t ) ∣ d t . \|f_{Z_m}-f_Z\|_\infty\le\frac{1}{2\pi}\int_{-\infty}^{\infty}|\Psi_{Z_m}(t)-\Psi_Z(t)|\,\mathrm{d}t. ∥ f Z m − f Z ∥ ∞ ≤ 2 π 1 ∫ − ∞ ∞ ∣ Ψ Z m ( t ) − Ψ Z ( t ) ∣ d t .
We split the integral into low and high frequency regimes.
For ∣ t ∣ ≤ m 1 / 4 |t|\le m^{1/4} ∣ t ∣ ≤ m 1/4 , the calculation in the proof of Theorem 5.2 can be made quantitative. Uniformly for R ∈ [ a / log n , b / log n ] R\in[a/\log n,b/\log n] R ∈ [ a / log n , b / log n ] ,
∣ log Ψ Z m ( t ) − log Ψ Z ( t ) ∣ ≤ O ( t 2 log 2 m + ∣ t ∣ log m log n m ) . |\log\Psi_{Z_m}(t)-\log\Psi_Z(t)|\le O\left(\frac{t^2\log^2 m+|t|\log m\log n}{m}\right). ∣ log Ψ Z m ( t ) − log Ψ Z ( t ) ∣ ≤ O ( m t 2 log 2 m + ∣ t ∣ log m log n ) .
Indeed, writing
y m ( t ) = E [ exp ( i t X / m ) ] − 1 , y_m(t)=\mathbb{E}[\exp(\mathrm{i}tX/m)]-1, y m ( t ) = E [ exp ( i tX / m )] − 1 ,
we have ∣ y m ( t ) ∣ = O ( ∣ t ∣ log m / m ) |y_m(t)|=O(|t|\log m/m) ∣ y m ( t ) ∣ = O ( ∣ t ∣ log m / m ) , so the error in replacing m log ( 1 + y m ( t ) ) m\log(1+y_m(t)) m log ( 1 + y m ( t )) by m y m ( t ) my_m(t) m y m ( t ) is O ( t 2 log 2 m / m ) O(t^2\log^2 m/m) O ( t 2 log 2 m / m ) . The remaining difference follows from 1 − e − 1 / ( u m ) ≤ min { 1 , ( u m ) − 1 } 1-e^{-1/(um)}\le\min\{1,(um)^{-1}\} 1 − e − 1/ ( u m ) ≤ min { 1 , ( u m ) − 1 } together with
E 1 ( 1 / ( R m ) ) = − γ + log R + log m + O ( 1 / ( R m ) ) . E_1(1/(Rm))=-\gamma+\log R+\log m+O(1/(Rm)). E 1 ( 1/ ( R m )) = − γ + log R + log m + O ( 1/ ( R m )) .
Since ∣ t ∣ ≤ m 1 / 4 |t|\le m^{1/4} ∣ t ∣ ≤ m 1/4 , the displayed error is o ( 1 ) o(1) o ( 1 ) uniformly. Consequently,
∣ Ψ Z m ( t ) − Ψ Z ( t ) ∣ ≤ ∣ Ψ Z ( t ) ∣ O ( t 2 log 2 m + ∣ t ∣ log m log n m ) . |\Psi_{Z_m}(t)-\Psi_Z(t)|\le|\Psi_Z(t)|O\left(\frac{t^2\log^2 m+|t|\log m\log n}{m}\right). ∣ Ψ Z m ( t ) − Ψ Z ( t ) ∣ ≤ ∣ Ψ Z ( t ) ∣ O ( m t 2 log 2 m + ∣ t ∣ log m log n ) .
Using Lemma 6.1 and integrating gives
∫ ∣ t ∣ ≤ m 1 / 4 ∣ Ψ Z m ( t ) − Ψ Z ( t ) ∣ d t ≤ n O ( 1 ) m . \int_{|t|\le m^{1/4}}|\Psi_{Z_m}(t)-\Psi_Z(t)|\,\mathrm{d}t\le\frac{n^{O(1)}}{m}. ∫ ∣ t ∣ ≤ m 1/4 ∣ Ψ Z m ( t ) − Ψ Z ( t ) ∣ d t ≤ m n O ( 1 ) .
We now consider the region ∣ t ∣ > m 1 / 4 |t|>m^{1/4} ∣ t ∣ > m 1/4 . For Ψ Z \Psi_Z Ψ Z , the exponential decay immediately gives
∫ ∣ t ∣ > m 1 / 4 ∣ Ψ Z ( t ) ∣ d t ≤ exp ( − Ω ( m 1 / 4 ) ) . \int_{|t|>m^{1/4}}|\Psi_Z(t)|\,\mathrm{d}t\le\exp\left(-\Omega(m^{1/4})\right). ∫ ∣ t ∣ > m 1/4 ∣ Ψ Z ( t ) ∣ d t ≤ exp ( − Ω ( m 1/4 ) ) .
It remains to bound Ψ Z m \Psi_{Z_m} Ψ Z m . Note that Ψ Z m ( t ) = Ψ X ( t m ) m \Psi_{Z_m}(t)=\Psi_X\left(\frac{t}{m}\right)^m Ψ Z m ( t ) = Ψ X ( m t ) m and let ξ = t m \xi=\frac{t}{m} ξ = m t . We split the analysis into two further regimes.
First consider m − 3 / 4 < ∣ ξ ∣ ≤ ε m^{-3/4}<|\xi|\le\varepsilon m − 3/4 < ∣ ξ ∣ ≤ ε , where ε ∈ ( 0 , 1 / 16 ] \varepsilon\in(0,1/16] ε ∈ ( 0 , 1/16 ] is a sufficiently small constant. Since the variance of X X X diverges with R m Rm R m , a quadratic Taylor expansion is not useful here. Instead, we use the identity
1 − ∣ Ψ X ( ξ ) ∣ 2 = E [ 1 − cos ( ξ ( X 1 − X 2 ) ) ] , 1-|\Psi_X(\xi)|^2=\mathbb{E}[1-\cos(\xi(X_1-X_2))], 1 − ∣ Ψ X ( ξ ) ∣ 2 = E [ 1 − cos ( ξ ( X 1 − X 2 ))] ,
where X 1 , X 2 X_1,X_2 X 1 , X 2 are independent copies of X X X . Set A = 1 4 ∣ ξ ∣ A=\frac{1}{4|\xi|} A = 4∣ ξ ∣ 1 . Restricting to the event X 1 ∈ [ 1 , 2 ] X_1\in[1,2] X 1 ∈ [ 1 , 2 ] and X 2 ∈ [ A , 2 A ] X_2\in[A,2A] X 2 ∈ [ A , 2 A ] , we have ∣ ξ ( X 2 − X 1 ) ∣ ∈ [ 1 / 8 , 1 / 2 ] |\xi(X_2-X_1)|\in[1/8,1/2] ∣ ξ ( X 2 − X 1 ) ∣ ∈ [ 1/8 , 1/2 ] . Hence
1 − cos ( ξ ( X 2 − X 1 ) ) ≥ 1 − cos ( 1 / 8 ) = : κ ′ > 0. 1-\cos(\xi(X_2-X_1))\ge1-\cos(1/8)=:\kappa'>0. 1 − cos ( ξ ( X 2 − X 1 )) ≥ 1 − cos ( 1/8 ) =: κ ′ > 0.
We next lower bound the probability of these intervals. Since f X ( x ) ≥ x − 2 e − 1 / x f_X(x) \ge x^{-2}e^{-1/x} f X ( x ) ≥ x − 2 e − 1/ x on ( 0 , R m ] (0,Rm] ( 0 , R m ] , then Pr [ X 1 ∈ [ 1 , 2 ] ] ≥ 1 2 e \Pr[X_1 \in[1,2]] \ge\frac{1}{2e} Pr [ X 1 ∈ [ 1 , 2 ]] ≥ 2 e 1 and
Pr [ X 2 ∈ [ A , 2 A ] ] ≥ ∫ A 2 A x − 2 e − 1 / x d x ≥ e − 1 / A ( 1 A − 1 2 A ) ≥ 2 e 1 / 4 ∣ ξ ∣ . \Pr[X_2 \in[A,2A]] \ge\int_A^{2A} x^{-2}e^{-1/x}\,dx \ge e^{-1/A}\left(\frac{1}{A}-\frac{1}{2A}\right) \ge\frac{2}{e^{1/4}}|\xi|. Pr [ X 2 ∈ [ A , 2 A ]] ≥ ∫ A 2 A x − 2 e − 1/ x d x ≥ e − 1/ A ( A 1 − 2 A 1 ) ≥ e 1/4 2 ∣ ξ ∣.
Combining the two estimates gives 1 − ∣ Ψ X ( ξ ) ∣ 2 ≥ c 0 ∣ ξ ∣ 1-|\Psi_X(\xi)|^2 \ge c_0|\xi| 1 − ∣ Ψ X ( ξ ) ∣ 2 ≥ c 0 ∣ ξ ∣ for some constant c 0 > 0 c_0>0 c 0 > 0 . Using 1 − y ≤ 1 − y 2 \sqrt{1-y}\le1-\frac{y}{2} 1 − y ≤ 1 − 2 y , we obtain
∣ Ψ X ( ξ ) ∣ ≤ 1 − c 0 2 ∣ ξ ∣ . |\Psi_X(\xi)| \le1-\frac{c_0}{2}|\xi|. ∣ Ψ X ( ξ ) ∣ ≤ 1 − 2 c 0 ∣ ξ ∣.
Substituting ξ = t / m \xi=t/m ξ = t / m therefore gives
∣ Ψ Z m ( t ) ∣ = ∣ Ψ X ( t / m ) ∣ m ≤ ( 1 − c 0 ∣ t ∣ 2 m ) m ≤ exp ( − c 0 2 ∣ t ∣ ) . |\Psi_{Z_m}(t)|=|\Psi_X(t/m)|^m\le\left(1-\frac{c_0|t|}{2m}\right)^m\le\exp\left(-\frac{c_0}{2}|t|\right). ∣ Ψ Z m ( t ) ∣ = ∣ Ψ X ( t / m ) ∣ m ≤ ( 1 − 2 m c 0 ∣ t ∣ ) m ≤ exp ( − 2 c 0 ∣ t ∣ ) .
Integrating over m 1 / 4 ≤ ∣ t ∣ ≤ ε m m^{1/4}\le|t|\le\varepsilon m m 1/4 ≤ ∣ t ∣ ≤ ε m gives
∫ m 1 / 4 ≤ ∣ t ∣ ≤ ε m ∣ Ψ Z m ( t ) ∣ d t ≤ exp ( − Ω ( m 1 / 4 ) ) . \int_{m^{1/4}\le|t|\le\varepsilon m}|\Psi_{Z_m}(t)|\,dt\le\exp\left(-\Omega\left(m^{1/4}\right)\right). ∫ m 1/4 ≤ ∣ t ∣ ≤ ε m ∣ Ψ Z m ( t ) ∣ d t ≤ exp ( − Ω ( m 1/4 ) ) .
Finally, consider the regime ∣ ξ ∣ > ε |\xi|>\varepsilon ∣ ξ ∣ > ε . Let Y Y Y denote the untruncated random variable with density f Y ( y ) = y − 2 e − 1 / y f_Y(y)=y^{-2}e^{-1/y} f Y ( y ) = y − 2 e − 1/ y . Since Y Y Y has an absolutely continuous distribution, the Riemann-Lebesgue lemma implies Ψ Y ( ξ ) → 0 \Psi_Y(\xi)\to0 Ψ Y ( ξ ) → 0 as ∣ ξ ∣ → ∞ |\xi|\to\infty ∣ ξ ∣ → ∞ . By compactness, there exists δ > 0 \delta>0 δ > 0 such that ∣ Ψ Y ( ξ ) ∣ ≤ 1 − 2 δ |\Psi_Y(\xi)|\le1-2\delta ∣ Ψ Y ( ξ ) ∣ ≤ 1 − 2 δ for all ∣ ξ ∣ ≥ ε |\xi|\ge\varepsilon ∣ ξ ∣ ≥ ε . The truncated characteristic function differs from Ψ Y \Psi_Y Ψ Y by at most the discarded tail mass:
∣ Ψ X ( ξ ) − Ψ Y ( ξ ) ∣ ≤ Pr [ Y > R m ] Pr [ Y ≤ R m ] ≤ O ( 1 R m ) . |\Psi_X(\xi)-\Psi_Y(\xi)|\le\frac{\Pr[Y>Rm]}{\Pr[Y\le Rm]}\le O\left(\frac{1}{Rm}\right). ∣ Ψ X ( ξ ) − Ψ Y ( ξ ) ∣ ≤ Pr [ Y ≤ R m ] Pr [ Y > R m ] ≤ O ( R m 1 ) .
Hence for sufficiently large m m m , we have ∣ Ψ X ( ξ ) ∣ ≤ 1 − δ |\Psi_X(\xi)|\le1-\delta ∣ Ψ X ( ξ ) ∣ ≤ 1 − δ for all $|\xi|>\varepsilon. We now estimate the remaining integral:
∫ ∣ t ∣ > ε m ∣ Ψ Z m ( t ) ∣ d t = m ∫ ∣ ξ ∣ > ε ∣ Ψ X ( ξ ) ∣ m d ξ ≤ m ( 1 − δ ) m − 2 ∫ − ∞ ∞ ∣ Ψ X ( ξ ) ∣ 2 d ξ . \begin{aligned}
\int_{|t|>\varepsilon m}|\Psi_{Z_m}(t)|\,dt=m\int_{|\xi|>\varepsilon}|\Psi_X(\xi)|^m\,d\xi\\
&\le m(1-\delta)^{m-2}\int_{-\infty}^{\infty}|\Psi_X(\xi)|^2\,d\xi.
\end{aligned} ∫ ∣ t ∣ > ε m ∣ Ψ Z m ( t ) ∣ d t = m ∫ ∣ ξ ∣ > ε ∣ Ψ X ( ξ ) ∣ m d ξ ≤ m ( 1 − δ ) m − 2 ∫ − ∞ ∞ ∣ Ψ X ( ξ ) ∣ 2 d ξ .
By Parseval’s identity,
∫ − ∞ ∞ ∣ Ψ X ( ξ ) ∣ 2 d ξ = 2 π ∫ 0 R m f X ( x ) 2 d x . \int_{-\infty}^{\infty}|\Psi_X(\xi)|^2\,d\xi=2\pi\int_0^{Rm}f_X(x)^2\,dx. ∫ − ∞ ∞ ∣ Ψ X ( ξ ) ∣ 2 d ξ = 2 π ∫ 0 R m f X ( x ) 2 d x .
Since f X ( x ) 2 ≤ 4 x − 4 e − 2 / x f_X(x)^2\le4x^{-4}e^{-2/x} f X ( x ) 2 ≤ 4 x − 4 e − 2/ x , the integral is finite and bounded by an absolute constant. Therefore,
∫ ∣ t ∣ > ε m ∣ Ψ Z m ( t ) ∣ d t ≤ exp ( − Ω ( m ) ) . \int_{|t|>\varepsilon m}|\Psi_{Z_m}(t)|\,dt\le\exp(-\Omega(m)). ∫ ∣ t ∣ > ε m ∣ Ψ Z m ( t ) ∣ d t ≤ exp ( − Ω ( m )) .
Combining the low and high frequency estimates gives
∥ f Z m − f Z ∥ ∞ ≤ poly ( n ) m . \|f_{Z_m}-f_Z\|_\infty\le\frac{\operatorname{poly}(n)}{m}. ∥ f Z m − f Z ∥ ∞ ≤ m poly ( n ) .
Finally, the same cumulant formulas evaluated at t = ± i t=\pm i t = ± i show that
E [ e Z m ] + E [ e − Z m ] + E [ e Z ] + E [ e − Z ] ≤ n O ( 1 ) . \mathbb{E}\left[e^{Z_m}\right]+\mathbb{E}\left[e^{-Z_m}\right]+\mathbb{E}\left[e^Z\right]+\mathbb{E}\left[e^{-Z}\right]\le n^{O(1)}. E [ e Z m ] + E [ e − Z m ] + E [ e Z ] + E [ e − Z ] ≤ n O ( 1 ) .
Thus, for B = C B log n B = C_B \log n B = C B log n with C B C_B C B sufficiently large,
Pr [ ∣ Z m ∣ > B ] + Pr [ ∣ Z ∣ > B ] ≤ n − c − 2 . \Pr[|Z_m| > B] + \Pr[|\mathcal{Z}| > B] \le n^{-c-2}. Pr [ ∣ Z m ∣ > B ] + Pr [ ∣ Z ∣ > B ] ≤ n − c − 2 .
Therefore,
d T V ( Z m , Z ) ≤ B ∥ f Z m − f Z ∥ ∞ + n − c − 2 ≤ n O ( 1 ) m + n − c − 2 . d_{TV}(Z_m,\mathcal{Z}) \le B\|f_{Z_m} - f_{\mathcal{Z}}\|_\infty+ n^{-c-2} \le\frac{n^{O(1)}}{m} + n^{-c-2}. d T V ( Z m , Z ) ≤ B ∥ f Z m − f Z ∥ ∞ + n − c − 2 ≤ m n O ( 1 ) + n − c − 2 .
Since m = Θ ( n C ) m = \Theta(n^C) m = Θ ( n C ) , choosing C C C sufficiently large proves the claim.
Lemma 7.8. Let the target additive failure rate of the perfect L 2 L_2 L 2 sampler be n − c n^{-c} n − c . The numerical execution differs from the exact theoretical distribution by a total variation distance of at most O ( n − c ) O(n^{-c}) O ( n − c ) .
Proof. Fix the desired exponent c > 0 c > 0 c > 0 , and apply Lemmas 7.5 and 7.7 with target error n − c − 3 n^{-c-3} n − c − 3 .
Condition first on the explicit head randomness. By Lemma 5.1 , choosing the constant in τ = Θ ( log n ) \tau= \Theta(\log n) τ = Θ ( log n ) sufficiently large and taking a union bound over the n n n original coordinates, with probability at least 1 − O ( n − c − 2 ) 1 - O(n^{-c-2}) 1 − O ( n − c − 2 ) every corresponding truncation parameter satisfies
R i ∈ [ a log n , b log n ] . R_i \in\left[\frac{a}{\log n}, \frac{b}{\log n}\right]. R i ∈ [ log n a , log n b ] .
for fixed constants 0 < a < b 0 < a < b 0 < a < b .
On this event, for every coordinate i i i , let Z m , i Z_{m,i} Z m , i denote its exact finite normalized tail statistic and let Z ^ i \widehat{Z}_i Z i denote the sample generated by the numerical oracle. By the triangle inequality and Lemmas 7.5 and 7.7,
d T V ( Z m , i , Z ^ i ) ≤ d T V ( Z m , i , Z i ) + d T V ( Z i , Z ^ i ) ≤ O ( n − c − 3 ) . d_{TV}(Z_{m,i},\widehat{Z}_i) \le d_{TV}(Z_{m,i},\mathcal{Z}_i) + d_{TV}(\mathcal{Z}_i,\widehat{Z}_i) \le O(n^{-c-3}). d T V ( Z m , i , Z i ) ≤ d T V ( Z m , i , Z i ) + d T V ( Z i , Z i ) ≤ O ( n − c − 3 ) .
Conditioned on the head randomness, the tail variables are independent across the original coordinates. Hence, the total variation distance between the joint exact and simulated tail vectors is at most
∑ i = 1 n d T V ( Z m , i , Z ^ i ) ≤ O ( n − c − 2 ) . \sum_{i=1}^{n} d_{TV}(Z_{m,i},\widehat{Z}_i) \le O(n^{-c-2}). i = 1 ∑ n d T V ( Z m , i , Z i ) ≤ O ( n − c − 2 ) .
Equivalently, the two tail vectors admit a coupling under which they agree coordinate-wise except with probability O ( n − c − 2 ) O(n^{-c-2}) O ( n − c − 2 ) . By Lemma 7.6, applying the tail-variance map, generating the Gaussian sketch contributions, and running the statistical recovery procedure cannot increase this total variation distance.
Finally, Lemma 7.4 contributes O ( n − C / 2 ) O(n^{-C/2}) O ( n − C /2 ) from the head construction. Choosing the duplication constant C C C sufficiently large, and adding the probability of the bad truncation event above, gives
d T V ( D e x a c t , D a l g ) ≤ O ( n − c ) . d_{TV}(\mathcal{D}_{\mathrm{exact}},\mathcal{D}_{\mathrm{alg}}) \le O(n^{-c}). d T V ( D exact , D alg ) ≤ O ( n − c ) .
Derandomization
The preceding analysis assumes that independent exponential and normal random variables can be generated and stored efficiently. To implement this algorithm in the streaming model, we now derandomize these components of the linear sketch. We begin by recalling the pseudorandom generator of [13 ] , which fools a class of Fourier transforms.
Definition 7.9. An ( m , n ) (m,n) ( m , n ) -Fourier shape is a function f : [ m ] n → C f : [m]^n \to\mathbb{C} f : [ m ] n → C of the form
f ( x 1 , … , x n ) = ∏ j = 1 n f j ( x j ) , f(x_1,\ldots,x_n) = \prod_{j=1}^{n} f_j(x_j), f ( x 1 , … , x n ) = j = 1 ∏ n f j ( x j ) , where each f j : [ m ] → C f_j : [m] \to\mathbb{C} f j : [ m ] → C acts on a single coordinate.
The following theorem summarizes the guarantees of the Fourier-shape PRG.
Theorem 7.10. [13 ] Let f : [ m ] n → C f : [m]^n \to\mathbb{C} f : [ m ] n → C be an ( m , n ) (m,n) ( m , n ) -Fourier shape with
f ( x 1 , … , x n ) = ∏ j = 1 n f j ( x j ) , f(x_1,\ldots,x_n) = \prod_{j=1}^{n} f_j(x_j), f ( x 1 , … , x n ) = j = 1 ∏ n f j ( x j ) , where each f j : [ m ] → C f_j : [m] \to\mathbb{C} f j : [ m ] → C . Then for every ε > 0 \varepsilon> 0 ε > 0 , there exists a seed length ℓ = O ( log m n ε ⋅ ( log log m n ε ) 2 ) \ell= O\left(\log\frac{mn}{\varepsilon} \cdot\left(\log\log\frac{mn}{\varepsilon}\right)^2\right) ℓ = O ( log ε mn ⋅ ( log log ε mn ) 2 ) and a deterministic function G : { 0 , 1 } ℓ → [ m ] n G : \{0,1\}^{\ell} \to[m]^n G : { 0 , 1 } ℓ → [ m ] n such that
∣ E x ∼ [ m ] n [ f ( x ) ] − E y ∼ { 0 , 1 } ℓ [ f ( G ( y ) ) ] ∣ ≤ ε , \left|\mathbb{E}_{x\sim[m]^n}[f(x)]-\mathbb{E}_{y\sim\{0,1\}^{\ell}}[f(G(y))]\right|\leq\varepsilon, E x ∼ [ m ] n [ f ( x )] − E y ∼ { 0 , 1 } ℓ [ f ( G ( y ))] ≤ ε , i.e., all ( m , n ) (m,n) ( m , n ) -Fourier shapes are ε \varepsilon ε -fooled by G G G .
Furthermore, the PRG of [13 ] also fools half-space queries, which we now define. For each i ∈ [ λ ] i \in[\lambda] i ∈ [ λ ] , let a half-space query H i : R n → { 0 , 1 } H_i : \mathbb{R}^n \to\{0,1\} H i : R n → { 0 , 1 } on an input X = ( x 1 , … , x n ) X=(x_1,\ldots,x_n) X = ( x 1 , … , x n ) be given by
H i ( X ) = 1 [ a 1 ( i ) x 1 + ⋯ + a n ( i ) x n > θ i ] , H_i(X)=\mathbf{1}\left[a_1^{(i)}x_1+\cdots+a_n^{(i)}x_n>\theta_i\right], H i ( X ) = 1 [ a 1 ( i ) x 1 + ⋯ + a n ( i ) x n > θ i ] ,
where a ( i ) ∈ Z n \mathbf{a}^{(i)}\in\mathbb{Z}^n a ( i ) ∈ Z n and θ i ∈ Z \theta_i\in\mathbb{Z} θ i ∈ Z for all i ∈ [ λ ] i\in[\lambda] i ∈ [ λ ] .
Definition 7.11 (λ \lambda λ -half-space tester). Given an input X = ( x 1 , … , x n ) X=(x_1,\ldots,x_n) X = ( x 1 , … , x n ) , a λ \lambda λ -half-space tester is a function
σ ( H 1 ( X ) , … , H λ ( X ) ) ∈ { 0 , 1 } , \sigma\left(H_1(X),\ldots,H_\lambda(X)\right)\in\{0,1\}, σ ( H 1 ( X ) , … , H λ ( X ) ) ∈ { 0 , 1 } , where σ : { 0 , 1 } λ → { 0 , 1 } \sigma:\{0,1\}^{\lambda}\to\{0,1\} σ : { 0 , 1 } λ → { 0 , 1 } and H 1 , … , H λ H_1,\ldots,H_\lambda H 1 , … , H λ are half-space queries. We say that the λ \lambda λ -half-space tester is M M M -bounded if each coordinate x i x_i x i is sampled from an integer distribution with magnitude at most M M M , and every coefficient a j ( i ) a_j^{(i)} a j ( i ) and threshold θ i \theta_i θ i also has magnitude at most M M M .
The following theorem gives the corresponding guarantees for fooling half-space testers, c.f., Lemma 7 and Proposition 8 of [28 ] .
Theorem 7.12. [13 , 28 ] Let D D D be a distribution on { − M , … , M } \{-M,\ldots,M\} { − M , … , M } with magnitude bounded by M M M that can be sampled using at most O ( log M ) O(\log M) O ( log M ) random bits. Let x 1 , … , x n ∼ D x_1,\ldots,x_n \sim D x 1 , … , x n ∼ D and define X = ( x 1 , … , x n ) X=(x_1,\ldots,x_n) X = ( x 1 , … , x n ) . Then for any ε > 0 \varepsilon>0 ε > 0 and c ≥ 1 c\ge1 c ≥ 1 , there exists ℓ = O ( λ ( log n M ε ) ( log log n M ε ) 2 ) \ell=O\left(\lambda\left(\log\frac{nM}{\varepsilon}\right)\left(\log\log\frac{nM}{\varepsilon}\right)^2\right) ℓ = O ( λ ( log ε n M ) ( log log ε n M ) 2 ) and a deterministic function F : { 0 , 1 } ℓ → { − M , … , M } n F:\{0,1\}^{\ell}\to\{-M,\ldots,M\}^n F : { 0 , 1 } ℓ → { − M , … , M } n such that for every λ \lambda λ -half-space tester σ H \sigma_H σ H ,
∣ E X ∼ D n [ σ H ( X ) = 1 ] − E y ∼ { 0 , 1 } ℓ [ σ H ( F ( y ) ) = 1 ] ∣ ≤ ε . \left|\mathop{\mathbb{E}}_{X\sim D^n}[\sigma_H(X)=1]-\mathop{\mathbb{E}}_{y\sim\{0,1\}^{\ell}}[\sigma_H(F(y))=1]\right|\le\varepsilon. E X ∼ D n [ σ H ( X ) = 1 ] − E y ∼ { 0 , 1 } ℓ [ σ H ( F ( y )) = 1 ] ≤ ε . Moreover, if F ( y ) ∈ { − M , … , M } n F(y)\in\{-M,\ldots,M\}^n F ( y ) ∈ { − M , … , M } n , then each coordinate of F ( y ) F(y) F ( y ) can be computed using O ( ℓ ) O(\ell) O ( ℓ ) space and polylog ( n M ) \operatorname{polylog}(nM) polylog ( n M ) time.
Theorem 7.13. [28 ] Let S S S be a streaming algorithm that, given a stream vector f ∈ { − M , … , M } n f\in\{-M,\ldots,M\}^n f ∈ { − M , … , M } n and a fixed matrix X ∈ R t × n k X\in\mathbb{R}^{t\times nk} X ∈ R t × nk , whose entries lie in { − M , … , M } \{-M,\ldots,M\} { − M , … , M } for some M = poly ( n ) M=\operatorname{poly}(n) M = poly ( n ) , produces an output that depends only on the sketches A f Af A f and X A ⃗ X\vec{A} X A . Suppose that the random matrix A ∈ R k × n A\in\mathbb{R}^{k\times n} A ∈ R k × n has i.i.d. entries, each of which can be sampled using O ( log n ) O(\log n) O ( log n ) random bits. Let σ : R k × R t → { 0 , 1 } \sigma:\mathbb{R}^k\times\mathbb{R}^t\to\{0,1\} σ : R k × R t → { 0 , 1 } be a tester for the success of S S S , i.e., σ ( A f , X A ⃗ ) = 1 \sigma\left(Af,X\vec{A}\right)=1 σ ( A f , X A ) = 1 whenever S S S succeeds. Then for every fixed constant c ≥ 1 c\ge1 c ≥ 1 , there exists an implementation of S S S using a random matrix A ′ A' A ′ generated from a seed of length O ( ( k + t ) log n ( log log n ) 2 ) O\left((k+t)\log n(\log\log n)^2\right) O ( ( k + t ) log n ( log log n ) 2 ) such that
∣ Pr [ σ ( A f , X A ⃗ ) = 1 ] − Pr [ σ ( A ′ f , X A ′ ⃗ ) = 1 ] ∣ < n − c ( k + t ) . \left|\Pr\left[\sigma\left(Af,X\vec{A}\right)=1\right]-\Pr\left[\sigma\left(A'f,X\vec{A'}\right)=1\right]\right|<n^{-c(k+t)}. Pr [ σ ( A f , X A ) = 1 ] − Pr [ σ ( A ′ f , X A ′ ) = 1 ] < n − c ( k + t ) . Moreover, every entry of A ′ A' A ′ can be computed in polylog ( n ) \operatorname{polylog}(n) polylog ( n ) time using working space proportional to the seed length.
Lemma 7.14 (Derandomizing the dense Gaussian sketch). Let s s s be the number of rows of the dense Gaussian CountSketch. Suppose all inputs and Gaussian entries have O ( log n ) O(\log n) O ( log n ) bits of precision. Then, for every fixed constant c > 0 c>0 c > 0 , the Gaussian randomness used by the dense CountSketch and its recovery procedure can be replaced by pseudorandomness generated from a seed of length O ( s log n ( log log n ) 2 ) O(s\log n(\log\log n)^2) O ( s log n ( log log n ) 2 ) such that the probability of every output of the recovery procedure changes by at most n − c n^{-c} n − c . Moreover, every required Gaussian entry can be generated from the seed in polylog ( n ) \operatorname{polylog}(n) polylog ( n ) time.
Proof. This is the Gaussian-sketch derandomization in the proof of Theorem 5.13 in [43 ] , with the number of sketch rows left as a parameter. That argument further applies Theorem 7.13 of [28 ] to the dense linear sketch and uses the GKM half-space PRG. If the dense sketch has s s s rows, the quantities denoted k + t k+t k + t in that argument are O ( s ) O(s) O ( s ) , and hence the seed length is O ( s log n ( log log n ) 2 ) O(s\log n(\log\log n)^2) O ( s log n ( log log n ) 2 ) . The argument is otherwise independent of p p p . In our application s = O ( log 2 n ) s=O(\log^2 n) s = O ( log 2 n ) , giving seed length O ( log 3 n ( log log n ) 2 ) O(\log^3 n(\log\log n)^2) O ( log 3 n ( log log n ) 2 ) .
Theorem 7.15. Suppose the input frequency vector x ∈ Z n x\in\mathbb{Z}^n x ∈ Z n has integer entries bounded in magnitude by poly ( n ) \operatorname{poly}(n) poly ( n ) . Then Algorithm 1 can be derandomized to use O ( log 3 n ( log log n ) 2 ) O(\log^3 n(\log\log n)^2) O ( log 3 n ( log log n ) 2 ) bits of space and uses polylog ( n ) \operatorname{polylog}(n) polylog ( n ) update time per arriving element in expectation.
Proof. We separate the randomness into the Gaussian randomness R g R_g R g used by the dense CountSketch and the randomness R e R_e R e used to generate the exponential head variables and the simulated tail variables. We first reduce to finite precision. As in the analysis of [43 , 28 ] , we condition on the high-probability event that every continuous random variable used by the algorithm has magnitude at most poly ( n ) \operatorname{poly}(n) poly ( n ) and retain C d i s c log n C_{\mathrm{disc}}\log n C disc log n bits of precision, for a sufficiently large constant C d i s c C_{\mathrm{disc}} C disc . The resulting perturbation of each maintained sketch value is n − Ω ( C d i s c ) n^{-\Omega(C_{\mathrm{disc}})} n − Ω ( C disc ) . Hence, the change in each output probability is at most n − c − 10 n^{-c-10} n − c − 10 , and so we can take values form discrete set of poly ( n ) \operatorname{poly}(n) poly ( n ) -bit magnitude, having O ( log n ) O(\log n) O ( log n ) bit complexity.
We next derandomize R g R_g R g . The dense CountSketch used here has s = O ( log 2 n ) s = O\left(\log^2 n\right) s = O ( log 2 n ) rows. Therefore, by Lemma 7.14, its Gaussian matrix can be generated from a seed y 1 y_1 y 1 of length O ( log 3 n ( log log n ) 2 ) O\left(\log^3 n(\log\log n)^2\right) O ( log 3 n ( log log n ) 2 ) , while changing every output probability by at most n − c − 10 n^{-c-10} n − c − 10 . Every entry of this pseudorandom matrix can be recomputed from y 1 y_1 y 1 in polylog ( n ) \operatorname{polylog}(n) polylog ( n ) time. Fixing y 1 y_1 y 1 , let G ′ = F 1 ( y 1 ) G' = F_1(y_1) G ′ = F 1 ( y 1 ) denote the resulting pseudorandom sketch matrix.
Now, consider any fixed seed F 1 ( y 1 ) F_1(y_1) F 1 ( y 1 ) and corresponding tester B i , F 1 ( y 1 ) ( R e ) \mathcal{B}_{i,F_1(y_1)}(R_e) B i , F 1 ( y 1 ) ( R e ) . Note that this determines the sketch matrix G ′ = F 1 ( y 1 ) G' = F_1(y_1) G ′ = F 1 ( y 1 ) and so it suffices to consider the residual tester B i ( R e ) : = A i ( G ′ , R e ) \mathcal{B}_i(R_e) := \mathcal{A}_i(G', R_e) B i ( R e ) := A i ( G ′ , R e ) . It remains to derandomize the randomness R e R_e R e used to generate the exponential random variables. Because we truncate and round each of the coordinates to ν d i s c \nu_{\mathrm{disc}} ν disc granularity, it suffices to focus on the discrete exponential random variables on a set with bounded support poly ( n ) \operatorname{poly}(n) poly ( n ) .
Instead of decomposing R e R_e R e into separate head and tail components, observe that the turnstile stream updates are linear. The simulated randomness r j r_j r j used for any single stream coordinate j ∈ [ n ] j \in[n] j ∈ [ n ] operates completely independently of the randomness used for other coordinates. For each coordinate j j j , the algorithm uses the local seed r j r_j r j to generate both its head order statistics and its simulated tail variance, which deterministically constructs a vector v j ( r j ) ∈ R n ′ v_j(r_j) \in\mathbb{R}^{n'} v j ( r j ) ∈ R n ′ representing the sketch updates for that coordinate.
The final virtual vector z ( R e ) z(R_e) z ( R e ) is exactly the sum of these independent contributions: z ( R e ) = ∑ j = 1 n x j v j ( r j ) z(R_e) = \sum_{j=1}^{n} x_jv_j(r_j) z ( R e ) = ∑ j = 1 n x j v j ( r j ) . Consequently, the sketch vector Y ( R e ) = G ′ ⋅ z ( R e ) Y(R_e) = G' \cdot z(R_e) Y ( R e ) = G ′ ⋅ z ( R e ) has a characteristic function that completely factorizes over the coordinates. Specifically, for any α ∈ R R \alpha\in\mathbb{R}^{R} α ∈ R R , we have
Φ Y ( α ) = E R e [ exp ( 2 π i ⟨ α , Y ( R e ) ⟩ ) ] = ∏ j = 1 n E r j [ exp ( 2 π i ⟨ ( G ′ ) T α , x j v j ( r j ) ⟩ ) ] . \Phi_Y(\alpha) = \mathbb{E}_{R_e}\left[\exp\left(2\pi i\langle\alpha,Y(R_e)\rangle\right)\right] = \prod_{j=1}^{n}\mathbb{E}_{r_j}\left[\exp\left(2\pi i\left\langle(G')^{\mathsf{T}}\alpha,x_jv_j(r_j)\right\rangle\right)\right]. Φ Y ( α ) = E R e [ exp ( 2 π i ⟨ α , Y ( R e )⟩ ) ] = j = 1 ∏ n E r j [ exp ( 2 π i ⟨ ( G ′ ) T α , x j v j ( r j ) ⟩ ) ] .
This matches the exact definition of an ( M , n ) (M,n) ( M , n ) -Fourier shape, where F α ( R e ) = ∏ j = 1 n f j ( r j ) F_\alpha(R_e) = \prod_{j=1}^{n} f_j(r_j) F α ( R e ) = ∏ j = 1 n f j ( r j ) and each f j f_j f j maps into the complex unit disk. We apply the GKM PRG to fool this Fourier shape. For each coordinate j j j , simulating its updates requires drawing O ( log n ) O(\log n) O ( log n ) discrete exponential random variables and two discrete uniform random variables, which takes O ( log 2 n ) O(\log^2 n) O ( log 2 n ) bits, giving a domain size M = 2 O ( log 2 n ) M = 2^{O(\log^2 n)} M = 2 O ( l o g 2 n ) .
The vector Y Y Y has R = O ( log 2 n ) R = O(\log^2 n) R = O ( log 2 n ) coordinates, each discretized to L = O ( log n ) L = O(\log n) L = O ( log n ) bits, giving a support size N s u p p ≤ n O ( log 2 n ) N_{\mathrm{supp}} \le n^{O(\log^2 n)} N supp ≤ n O ( l o g 2 n ) . By the Cauchy-Schwarz inequality and Plancherel’s theorem, the total variation distance between two probability distributions over a finite support is bounded by 1 2 N s u p p \frac{1}{2}\sqrt{N_{\mathrm{supp}}} 2 1 N supp times their maximum difference in the Fourier domain. Thus to guarantee the total variation distance changes by at most n − O ( 1 ) poly ( n ) \frac{n^{-O(1)}}{\operatorname{poly}(n)} poly ( n ) n − O ( 1 ) , it suffices to have Fourier error ε F T ≤ n − O ( 1 ) N s u p p = n − O ( log 2 n ) \varepsilon_{FT} \le\frac{n^{-O(1)}}{\sqrt{N_{\mathrm{supp}}}} = n^{-O(\log^2 n)} ε F T ≤ N supp n − O ( 1 ) = n − O ( l o g 2 n ) . By Theorem 7.10 , with N = n N = n N = n , M = 2 O ( log 2 n ) M = 2^{O(\log^2 n)} M = 2 O ( l o g 2 n ) , and ε = ε F T \varepsilon= \varepsilon_{FT} ε = ε F T , the corresponding seed length is r 2 = O ( log N M ε ( log log N M ε ) 2 ) r_2 = O\left(\log\frac{NM}{\varepsilon}\left(\log\log\frac{NM}{\varepsilon}\right)^2\right) r 2 = O ( log ε N M ( log log ε N M ) 2 ) .
Since log ( N M / ε F T ) = O ( log n ) + O ( log 2 n ) + O ( log 3 n ) = O ( log 3 n ) \log(NM/\varepsilon_{FT}) = O(\log n) + O(\log^2 n) + O(\log^3 n) = O(\log^3 n) log ( N M / ε F T ) = O ( log n ) + O ( log 2 n ) + O ( log 3 n ) = O ( log 3 n ) , the required seed length evaluates to exactly r 2 = O ( log 3 n ( log log n ) 2 ) r_2 = O\left(\log^3 n(\log\log n)^2\right) r 2 = O ( log 3 n ( log log n ) 2 ) . This pseudorandom generator F 2 F_2 F 2 ensures
d T V ( P Y , P Y ′ ) ≤ 1 poly ( n ) . d_{TV}(P_Y,P'_Y) \le\frac{1}{\operatorname{poly}(n)}. d T V ( P Y , P Y ′ ) ≤ poly ( n ) 1 .
Consequently,
∣ E y 1 , R e [ A i ( F 1 ( y 1 ) , R e ) ] − E y 1 , y 2 [ A i ( F 1 ( y 1 ) , F 2 ( y 2 ) ) ] ∣ ≤ 1 poly ( n ) . \left|\mathbb{E}_{y_1,R_e}[\mathcal{A}_i(F_1(y_1),R_e)]-\mathbb{E}_{y_1,y_2}[\mathcal{A}_i(F_1(y_1),F_2(y_2))]\right| \le\frac{1}{\operatorname{poly}(n)}. ∣ E y 1 , R e [ A i ( F 1 ( y 1 ) , R e )] − E y 1 , y 2 [ A i ( F 1 ( y 1 ) , F 2 ( y 2 ))] ∣ ≤ poly ( n ) 1 .
End-to-End Correctness
Finally, we have the end-to-end correctness of our algorithm, combined with the statistical test and the derandomization.
Theorem 7.16 (End-to-End Correctness for Perfect L 2 L_2 L 2 Sampling). Given a dynamic turnstile stream defining a frequency vector x ∈ R n x \in\mathbb{R}^n x ∈ R n , there exists an algorithm using expected polylog ( n ) \operatorname{polylog}(n) polylog ( n ) update time and O ~ ( log 3 n ) \widetilde{O}(\log^3 n) O ( log 3 n ) bits of space such that, conditioned on returning an index (i ∗ ≠ ⊥ i^* \ne\bot i ∗ = ⊥ ),
Pr [ i ∗ = j ∣ i ∗ ≠ ⊥ ] = x j 2 ∥ x ∥ 2 2 ± O ( ν e r r ) , \Pr[i^*=j \mid i^*\ne\bot] = \frac{x_j^2}{\lVert x\rVert_2^2} \pm O(\nu_{\mathrm{err}}), Pr [ i ∗ = j ∣ i ∗ = ⊥ ] = ∥ x ∥ 2 2 x j 2 ± O ( ν err ) , where ν e r r = n − c \nu_{\mathrm{err}}=n^{-c} ν err = n − c for any fixed constant c > 0 c>0 c > 0 .
Proof. Let D i d e a l \mathcal{D}_{\mathrm{ideal}} D ideal denote the distribution induced by the exact discrete construction, and let D a l g \mathcal{D}_{\mathrm{alg}} D alg denote the distribution produced by the implemented algorithm. Let E p a s s \mathcal{E}_{\mathrm{pass}} E pass denote the event that the statistical test succeeds and the algorithm returns an index.
Under D i d e a l \mathcal{D}_{\mathrm{ideal}} D ideal , the dense CountSketch recovers the unique maximum coordinate of the duplicated vector z ∈ R N z\in\mathbb{R}^N z ∈ R N except with probability n − O ( c ) n^{-O(c)} n − O ( c ) . Since the gap test only accepts when the top coordinate is separated from the remainder of the vector, conditioning on E p a s s \mathcal{E}_{\mathrm{pass}} E pass implies that the returned coordinate agrees with the true maximizer D ( 1 ) D(1) D ( 1 ) with high probability. Fix a virtual coordinate v ∈ [ N ] v\in[N] v ∈ [ N ] . By Lemma 7.1 ,
Pr [ E p a s s ∣ D ( 1 ) = v ] = Pr [ E p a s s ] ± n − O ( c ) . \Pr[\mathcal{E}_{\mathrm{pass}}\mid D(1)=v]=\Pr[\mathcal{E}_{\mathrm{pass}}]\pm n^{-O(c)}. Pr [ E pass ∣ D ( 1 ) = v ] = Pr [ E pass ] ± n − O ( c ) .
By Lemma 7.2 , we have that Pr [ E p a s s ] ≥ 0.75 \Pr[\mathcal{E}_{\mathrm{pass}}]\ge0.75 Pr [ E pass ] ≥ 0.75 . Therefore,
Pr [ E p a s s ∩ { D ( 1 ) = v } ] = Pr D i d e a l [ D ( 1 ) = v ] ⋅ ( Pr [ E p a s s ] ± n − O ( c ) ) . \Pr[\mathcal{E}_{\mathrm{pass}}\cap\{D(1)=v\}]=\Pr_{\mathcal{D}_{\mathrm{ideal}}}[D(1)=v]\cdot\left(\Pr[\mathcal{E}_{\mathrm{pass}}]\pm n^{-O(c)}\right). Pr [ E pass ∩ { D ( 1 ) = v }] = D ideal Pr [ D ( 1 ) = v ] ⋅ ( Pr [ E pass ] ± n − O ( c ) ) .
Let C j C_j C j denote the collection of virtual copies associated with coordinate j ∈ [ n ] j\in[n] j ∈ [ n ] . Summing over all such copies gives
Pr [ i ∗ = j ] = ∑ v ∈ C j Pr [ E p a s s ∩ { D ( 1 ) = v } ] ± n − O ( c ) = ∑ v ∈ C j Pr D i d e a l [ D ( 1 ) = v ] ( Pr [ E p a s s ] ± n − O ( c ) ) ± n − O ( c ) . \begin{aligned}
\Pr[i^*=j]=\sum_{v\in C_j}\Pr[\mathcal{E}_{\mathrm{pass}}\cap\{D(1)=v\}]\pm n^{-O(c)} \\
&=\sum_{v\in C_j}\Pr_{\mathcal{D}_{\mathrm{ideal}}}[D(1)=v]\left(\Pr[\mathcal{E}_{\mathrm{pass}}]\pm n^{-O(c)}\right)\pm n^{-O(c)}.
\end{aligned} Pr [ i ∗ = j ] = v ∈ C j ∑ Pr [ E pass ∩ { D ( 1 ) = v }] ± n − O ( c ) = v ∈ C j ∑ D ideal Pr [ D ( 1 ) = v ] ( Pr [ E pass ] ± n − O ( c ) ) ± n − O ( c ) .
By Lemma 7.3 ,
∑ v ∈ C j Pr D i d e a l [ D ( 1 ) = v ] = x j 2 ∥ x ∥ 2 2 . (4) \sum_{v\in C_j}\Pr_{\mathcal{D}_{\mathrm{ideal}}}[D(1)=v]=\frac{x_j^2}{\lVert x\rVert_2^2}. \tag*{(4)} v ∈ C j ∑ D ideal Pr [ D ( 1 ) = v ] = ∥ x ∥ 2 2 x j 2 . (4)
Substituting this identity gives
Pr [ i ∗ = j ] = x j 2 ∥ x ∥ 2 2 ( Pr [ E p a s s ] ± n − O ( c ) ) ± n − O ( c ) . \Pr[i^* = j] = \frac{x_j^2}{\lVert x\rVert_2^2}\left(\Pr[\mathcal{E}_{pass}] \pm n^{-O(c)}\right) \pm n^{-O(c)}. Pr [ i ∗ = j ] = ∥ x ∥ 2 2 x j 2 ( Pr [ E p a ss ] ± n − O ( c ) ) ± n − O ( c ) .
Conditioning on E p a s s \mathcal{E}_{pass} E p a ss and using Pr [ E p a s s ] ≥ 0.75 \Pr[\mathcal{E}_{pass}] \ge0.75 Pr [ E p a ss ] ≥ 0.75 ,
Pr D i d e a l [ i ∗ = j ∣ E p a s s ] = x j 2 ∥ x ∥ 2 2 ± O ( n − c ) . \Pr_{D_{\mathrm{ideal}}}[i^* = j \mid\mathcal{E}_{pass}] = \frac{x_j^2}{\lVert x\rVert_2^2} \pm O\left(n^{-c}\right). D ideal Pr [ i ∗ = j ∣ E p a ss ] = ∥ x ∥ 2 2 x j 2 ± O ( n − c ) .
We now compare D i d e a l D_{\mathrm{ideal}} D ideal and D a l g D_{\mathrm{alg}} D alg . By Lemma 7.8 , the total variation distance between the ideal distribution D i d e a l D_{\mathrm{ideal}} D ideal and the algorithmic distribution D a l g D_{\mathrm{alg}} D alg is at most O ( n − c ) O\left(n^{-c}\right) O ( n − c ) . Finally, the GKM18 pseudorandom generator ν e r r \nu_{\mathrm{err}} ν err -fools both the dense CountSketch queries and the Fourier evaluations used by the oracle while using only O ( log 3 n ( log log n ) 2 ) O\left(\log^3 n(\log\log n)^2\right) O ( log 3 n ( log log n ) 2 ) random bits, contributing at most ν e r r / 3 \nu_{\mathrm{err}}/3 ν err /3 additional variation distance.
Combining the three bounds gives
d T V ( D i d e a l , D a l g ) ≤ ν e r r . d_{TV}(D_{\mathrm{ideal}},D_{\mathrm{alg}}) \le\nu_{\mathrm{err}}. d T V ( D ideal , D alg ) ≤ ν err .
It follows that
Pr D a l g [ i ∗ = j ∣ i ∗ ≠ ⊥ ] = x j 2 ∥ x ∥ 2 2 ± O ( ν e r r ) . \Pr_{D_{\mathrm{alg}}}[i^* = j \mid i^* \ne\perp] = \frac{x_j^2}{\lVert x\rVert_2^2} \pm O(\nu_{\mathrm{err}}). D alg Pr [ i ∗ = j ∣ i ∗ = ⊥ ] = ∥ x ∥ 2 2 x j 2 ± O ( ν err ) .
Finally, the dense CountSketch uses M = Θ ( log n ) M = \Theta(\log n) M = Θ ( log n ) blocks with r = Θ ( log n ) r = \Theta(\log n) r = Θ ( log n ) rows each, for a total of Θ ( log 2 n ) \Theta(\log^2 n) Θ ( log 2 n ) sketch rows. Each row stores a single counter using O ( log n ) O(\log n) O ( log n ) bits, giving overall space complexity O ( log 3 n ) O(\log^3 n) O ( log 3 n ) bits. Each update involves O ( log 2 n ) O(\log^2 n) O ( log 2 n ) rows and performs only polylogarithmic additional work for the explicitly tracked head coordinates and simulated tail contribution, giving expected update time polylog( n ) (n) ( n ) .
Acknowledgments
Google DeepThink contributed the main ideas underlying the technical proofs in this work, and several other AI models assisted with verification.