Quantcast
Channel: Hacker News 50
Viewing all articles
Browse latest Browse all 9433

c++ - How to determine if my calculation of pi is accurate? - Stack Overflow

$
0
0

Comments:"c++ - How to determine if my calculation of pi is accurate? - Stack Overflow"

URL:http://stackoverflow.com/questions/14283270/how-to-determine-if-my-calculation-of-pi-is-accurate


Since I'm the current world record holder for the most digits of pi, I'll add my two cents:

Unless you're actually setting a new world record, the common practice is just to verify the computed digits against the known values. So that's simple enough.

In fact, I have a webpage that lists snippets of digits for the purpose of verifying computations against them: http://www.numberworld.org/digits/Pi/

But when you get into world-record territory, there's nothing to compare against.

Historically, the standard approach for verifying that computed digits are correct is to recompute the digits using a second algorithm. So if either computation goes bad, the digits at the end won't match.

This does typically more than double the amount of time needed (since the second algorithm is usually slower). But it's the only way to verify the computed digits once you've wandered into the uncharted territory of never-before-computed digits and a new world record.

Back in the days where supercomputers were setting the records, two different AGM algorithms were commonly used:

These are both O(N log(N)^2) algorithms that were fairly easy to implement.

However, nowadays, things are a bit different. In the last three world records, instead of performing two computations, we performed only one computation using the fastest known formula (Chudnovsky Formula):

This algorithm is much harder to implement, but it is a lot faster than the AGM algorithms.

Then we verify the binary digits using the BBP formulas for digit extraction.

This formula allows you to compute arbitrary binary digits without computing all the digits before it. So it is used to verify the last few computed binary digits. Therefore it is much faster than a full computation.

The advantage of this is:

Only one expensive computation is needed.

The disadvantage is:

An implementation of the Bailey–Borwein–Plouffe (BBP) formula is needed. An addition step is needed to verify the radix conversion from binary to decimal.

I've glossed over some details of why verifying the last few digits implies that all the digits are correct. But it is easy to see this since any computation error will propagate to the last digits.

Now this last step (verifying the conversion) is actually fairly important. One of the previous world record holders actually called us out on this because, initially, I didn't give a sufficient description of how it worked.

So I've pulled this snippet from my blog:

N = # of decimal digits desired
p = 64-bit prime number

Compute A using base 10 arithmetic and B using binary arithmetic.

If A = B, then with "extremely high probability", the conversion is correct.

For further reading, see my blog post Pi - 5 Trillion Digits.


Viewing all articles
Browse latest Browse all 9433

Trending Articles