本文优化 Bombelli 整数平方根算法,用浮点运算生成逐位初始猜测,并通过 Java 实验证明其快于标准库中的 Newton 法。
摘要:
本文提出了经典 Bombelli 整数平方根计算算法的优化版本。具体而言,该算法采用浮点运算来计算根中每一位数字的初始猜测值,其思路类似于《计算机程序设计艺术》第2卷第4.3.1节中用于除法的思想。文中还给出了用 Java 实现该算法的程序,并将其运行时间与 Java 标准库所提供的、使用 Newton 法的算法进行比较。测试表明,本文提出的算法要快得多。
英文摘要:
In this paper, an optimized version of classical Bombelli's algorithm for computing integer square roots is presented. In particular, floating-point arithmetic is used to compute the initial guess of each digit of the root, following similar ideas to those used in "The Art of Computer Programming" Vol. 2, p. 4.3.1 for division. A program with an implementation of the algorithm in Java is also presented, and its running time is compared with that of the algorithm provided by the Java standard library, which uses the Newton's method. From tests, the algorithm presented here turns out to be much faster.
Verificarlo: checking floating point accuracy through Monte Carlo Arithmetic
CMLA - Centre de Mathématiques et de Leurs Applications, ENS Cachan Université Paris-Saclay et CNRS UMR 8536(CMLA - 数学及其应用中心,巴黎萨克雷大学卡尚分校及法国国家科学研究中心);Université de Versailles Saint-Quentin-en-Yvelines Université Paris-Saclay(凡尔赛圣康坦昂伊夫林大学,巴黎萨克雷大学)
Analysis of Floating-Point Matrix Multiplication Computed via Integer Arithmetic
Innovative Computing Laboratory, University of Tennessee, Knoxville(田纳西大学诺克斯维尔分校创新计算实验室);Department of Mathematics, University of Manchester(曼彻斯特大学数学系);School of Computer Science, University of Leeds(利兹大学计算机科学学院)
在这里,我提出了C和C++接口和实验实现的双重算法。我在上一篇题为"Twofold fast arithmetic"的文章中介绍了Twofold,用于跟踪浮点不准确性。测试表明,普通C实现了高性能计算的双重功能。C++接口使编码像普通的浮点数一样容易。我的目标是说服你尝试两次;我认为确保数学计算的准确性是值得的。代码和使用的例子可以在我的网站上找到,里面有参考资料。