hn.today

A faster algorithm for extracting hexadecimal digits of π

stylewarning.com78 points5 comments
Screenshot of A faster algorithm for extracting hexadecimal digits of π

The piece presents a method for extracting hexadecimal digits of π at a distant offset without calculating the digits before it. It begins with a series whose terms group four powers of two over the same odd denominator, allowing their remainders to be combined before a single division. The remainders are related by exponent differences that are small multiples of the index, so a starting modular power and the step \(2^k \bmod (2k+1)\) generate the rest with ordinary multiplications. Pairing an odd modulus \(M\) with \(3M\) reduces the work further: calculations modulo \(3M\) serve both denominators, and their contributions can be combined in one division. The derivation connects Euler’s series and an arctangent identity to this grouped formula.

The operation-count analysis estimates about \(7d/27\) divisions and \(56d/135\) full modular exponentiations for an offset of \(d\) bits, compared with roughly \(2d/3\) of each for Huvent’s formula. That corresponds to about 61% fewer divisions and 38% fewer exponentiations at large offsets. An AVX-512 IFMA implementation was tested against Huvent’s: for single-threaded runs, it was about 65% faster at offsets of one million and one hundred million hex digits; with 32 threads, improvements ranged from about 11% to 62% across offsets up to a trillion digits. The discussion also describes implementation techniques, including batching moduli with matching computation patterns and reducing Montgomery-arithmetic overhead.

Read on stylewarning.com5 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Science

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.