Papers
Topics
Authors
Recent
Search
2000 character limit reached

Gaussian Generator Contract

Updated 10 December 2025
  • Gaussian Generator Contract is a finite-precision specification that guarantees generated samples exactly match the cumulative probabilities of a user-supplied Gaussian CDF.
  • It employs the Knuth-Yao scheme for optimal, unbiased coin-flip mapping, significantly reducing entropy usage compared to traditional methods.
  • The contract provides a robust API with formal guarantees on precision, overflow-avoidance, and reproducibility, making it suitable for high-performance sampling.

A Gaussian Generator Contract, as realized in the universal framework described by "Random Variate Generation with Formal Guarantees" (Saad et al., 17 Jul 2025), is an explicit, finite-precision specification and implementation of a random variate generator targeting the Gaussian distribution. It enforces that generated outputs strictly realize the exact cumulative probabilities prescribed by a user-supplied Gaussian CDF, with guarantees on precision, overflow-avoidance, and entropy-optimality. The contract encapsulates both mathematical formalism and a low-level software API, yielding a reproducible and auditable method for exact random sampling in floating-point, fixed-point, or posits-based systems.

1. Formal Specification of the Target Distribution

The contract is constructed upon a finite-precision CDF program defined over a binary number format B=(n,γB,ϕB)B = (n, \gamma_B, \phi_B), where bit-strings of length nn encode real values in R∩[0,1]\mathbb{R} \cap [0, 1]. Monotonicity and strict endpoint requirements (F(ϕB(0n))=0F(\phi_B(0^n)) = 0, F(ϕB(1n))=1F(\phi_B(1^n)) = 1) guarantee well-formedness. For the Gaussian case, F(x)F(x) is realized as

F(x)=12 erfc(−xσ2)F(x) = \frac{1}{2} \, \mathrm{erfc}\left(-\frac{x}{\sigma \sqrt{2}}\right)

with all operations implemented in IEEE-754 binary64, including correct clipping and NaN-handling. This discrete mapping defines a probability mass function on the set of representable floats, fully characterizing the desired generator's output law in terms of CDF differences F(b)−F(pred(b))F(b) - F(\text{pred}(b)) for each bit-string bb.

2. Construction of Entropy-Optimal Generator

Given a finite-precision CDF FF, the generator algorithm (denoted "Opt") operates using unbiased coin-flips (RandBit()), mapping entropy directly onto output via the information-theoretically optimal Knuth-Yao scheme:

  • For each prefix nn0 of length nn1, the binary-coded distribution nn2 is computed as

nn3

where nn4 and nn5 decomposes as nn6 (see Prop. 4.6).

  • The algorithm iteratively refines the output prefix, querying the leading bits of the relevant probability differences; the search proceeds down an implicit DDG (Discrete Distribution Generation) tree with expected coin-flip cost bounded by entropy nn7 plus two bits (Theorem 2.1).
  • Fast integer operations extract bitfields corresponding to floating-point subtractions, entirely avoiding arbitrary-precision arithmetic (Prop. 4.8).

The procedure realizes exact sampling for any distribution specified by a numerical CDF, restricted to the precision used in its definition, maintaining strict resource bounds per output sample.

3. Instantiation for the Gaussian Distribution

Within double precision (nn8), the contract is instantiated by providing:

  • A CDF Program: F(Ï•B(0n))=0F(\phi_B(0^n)) = 04
  • Generator Invocation: The macro GENERATE_FROM_CDF(gaussian_cdf, sigma) synthesizes the optimal generator via the above algorithm. Each sample requires only the precision and arithmetic already present in the CDF code.
  • Accuracy Guarantee: The output distribution matches the induced discrete law exactly; there is no added error from the generator itself. The output float nn9 fulfills

R∩[0,1]\mathbb{R} \cap [0, 1]0

even for subnormal and boundary values.

4. Contractual API and Operational Semantics

The contract exposes a consistent API—typically in C—enabling direct use in high-performance contexts:

F(ϕB(0n))=0F(\phi_B(0^n)) = 05 Where:

  • R serves as a source of unbiased random bits,
  • sigma is required to be positive,
  • The output R∩[0,1]\mathbb{R} \cap [0, 1]1 in binary64 satisfies the exact cumulative probability constraint as per the provided CDF,
  • Entropy utilization is theoretically bounded (R∩[0,1]\mathbb{R} \cap [0, 1]2 bits per sample for double, Cor. 4.15); buffer and alignment strategies can be tuned further.

Preconditions:

  • Input CDF must be strictly monotonic, return values only in R∩[0,1]\mathbb{R} \cap [0, 1]3, and be robust to NaN inputs.

Postconditions:

  • Each output is distributed precisely according to the finite-precision CDF, with no error introduced in the sampling process.

5. Performance and Entropy Efficiency

Empirical evaluations (Table 5 in (Saad et al., 17 Jul 2025)) demonstrate:

  • Entropy Utilization:
    • The OPT (optimal) sampler uses R∩[0,1]\mathbb{R} \cap [0, 1]4 bits per Gaussian sample, with the minimum possible bound R∩[0,1]\mathbb{R} \cap [0, 1]5 bits for R∩[0,1]\mathbb{R} \cap [0, 1]6 mantissa bits in binary64.
    • Standard routines such as Box-Muller or Ziggurat typically consume two uniform samples (each R∩[0,1]\mathbb{R} \cap [0, 1]7 bits), totaling R∩[0,1]\mathbb{R} \cap [0, 1]8 bits—thus the contract achieves more than double the entropy efficiency.
  • Throughput:
    • The C prototype generator achieves R∩[0,1]\mathbb{R} \cap [0, 1]9 samples/sec on 3 GHz x86_64; with optimized CDF and inlined bit-extraction, rates approach one million samples/sec while retaining exactness.
    • For comparison, GSL's Ziggurat implementation reaches F(Ï•B(0n))=0F(\phi_B(0^n)) = 00 samples/sec but does not enforce strict CDF fidelity.
  • Theoretical Bounds:
    • With F(Ï•B(0n))=0F(\phi_B(0^n)) = 01, the expected coin-flips per sample satisfy F(Ï•B(0n))=0F(\phi_B(0^n)) = 02 (Cor. 4.15), matching information-theoretic lower bounds.

6. Theoretical Guarantees and Correctness Arguments

The generator's soundness and optimality are rigorously established:

  • Correctness:
    • By explicit carry analysis (Props. 3.9, 3.10), the generated samples realize exactly the target probability mass function (Thm 3.14).
  • Optimality:
    • Each generated path matches the DDG tree predicted by Knuth-Yao (Thm 3.17); resource consumption is bounded as F(Ï•B(0n))=0F(\phi_B(0^n)) = 03 per sample in both time and space, with all operations confined to machine word sizes.
  • Overflow and Precision:
    • Bit-extraction and arithmetic for CDF differences never exceed the width of an input word (Prop. 4.8), precluding overflows or loss of fidelity.
  • Automation and Universality:
    • The contract and methods are universal; any finite-precision CDF (floating-point, fixed-point, posit) can be used as input, enabling fully automated generator synthesis.

The contract for a Gaussian generator thereby encapsulates a precise, entropy-optimal, and formally auditable mechanism for sampling, distinguished by both its exactness (w.r.t. user-specified CDF) and its efficient resource profile (Saad et al., 17 Jul 2025).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Gaussian Generator Contract.