一句话:提出从有限精度 CDF 数值程序自动合成精确随机变量生成器的方法,兼具形式化保证与熵最优性。
随机变量生成是现代编程语言的基础操作,但传统库基于理想化 Real-RAM 模型,假设可访问均匀实数并做无限精度运算;物理计算机只能读取随机比特并用有限精度算术,导致实际分布未知甚至与目标任意偏离。本文提出具有形式化保证的方法:先用定义累积分布函数(CDF)的有限精度数值程序指定目标分布,再据此生成精确随机变量。作者给出通用全自动合成方法,可为浮点、定点、posit 等二进制格式的数值 CDF 构造精确生成器,保证与 CDF 同精度、不溢出且避免任意精度算术;核心是达到 Knuth-Yao 熵率信息论最优的生成器类的时空最优实现。作者用 C 实现库并在连续与离散分布上评估,运行时间与 GSL 相当,精度与熵效率更高。
Generating random variates is a fundamental operation in diverse areas of computer science and is supported in almost all modern programming languages. Traditional software libraries for random variate generation are grounded in the idealized “Real-RAM” model of computation, where algorithms are assumed to be able to access uniformly distributed real numbers from the unit interval and compute with infinite-precision real arithmetic. These assumptions are unrealistic, as any software implementation of a Real-RAM algorithm on a physical computer can instead access a stream of individual random bits and computes with finite-precision arithmetic. As a result, existing libraries have few theoretical guarantees in practice. For example, the actual distribution of a random variate generator is generally unknown, intractable to quantify, and arbitrarily different from the desired distribution; causing runtime errors, unexpected behavior, and inconsistent APIs. This article introduces a new approach to principled and practical random variate generation with formal guarantees. The key idea is to first specify the desired probability distribution in terms of a finite-precision numerical program that defines its cumulative distribution function (CDF), and then generate exact random variates according to this CDF. We present a universal and fully automated method to synthesize exact random variate generators given any numerical CDF implemented in any binary number format, such as floating-point, fixed-point, and posits. The method is guaranteed to operate with the same precision used to specify the CDF, does not overflow, avoids expensive arbitrary-precision arithmetic, and exposes a consistent API. The method rests on a novel space-time optimal implementation for the class of generators that attain the information-theoretically optimal Knuth and Yao entropy rate, consuming the least possible number of input random bits per output variate. We develop a random variate generation library using our method in C and evaluate it on a diverse set of “continuous” and “discrete” distributions, showing competitive runtime with the state-of-the-art GNU Scientific Library while delivering higher accuracy, entropy efficiency, and automation.