I was trying various methods to implement a program that gives the digits of pi sequentially. I tried the Taylor series method, but it proved to converge extremely slowly (when I compared my result with the online values after some time). Anyway, I am trying better algorithms.

So, while writing the program I got stuck on a problem, as with all algorithms: How do I know that the `n`

digits that I've calculated are accurate?

more of a mathematical problem. good algorithms also give an estimate of the error.

**2018年07月23日12分24秒**

Compare against pi?

**2018年07月23日12分24秒**

chris: "Literally everywhere"?

**2018年07月23日12分24秒**

I can check for you up to 3.141592653589793238462643383279502, beyond that, why do you need such a big number of digits? (That's something like atomic level accuracy with a circle the size of the universe.)

**2018年07月23日12分24秒**

Why don't you just divide by pi and check if the result is 1? (just kidding)

**2018年07月23日12分24秒**

And to answer the other question about how to know when a specific algorithm has converged to N digits: This requires that you know the convergence behavior of the algorithm. The Taylor Series of ArcTan(1) is logarithmically converging. So you'd need an exponentially large number of terms to converge - in short, don't use it.

**2018年07月23日12分24秒**

Yes, Chudnovsky's formula converges at a steady 14.18 digits per term. So you can divide the total number of digits by that to get how many terms you need. (Exact value is: Log(151931373056000)/Log(10) = 14.181647462725477655...)

**2018年07月23日12分24秒**

erikb85 Kinda. The BBP formula (to some extent) counts as a second algorithm. But by itself it isn't enough since it doesn't verify the conversion to base 10. The idea of using BBP + conversion check to eliminate the need for a second computation wasn't mine. It was first done by Fabrice Bellard in his 2009 world record. It was such a good idea that we did the same and improved upon it.

**2018年07月23日12分24秒**

FunsukWangadu I can only speak for myself, but here it goes: I never actually cared about Pi itself. To me, it's just another number. The value isn't in the number itself or the 10 terabytes of useless digits, it's the methods that are used to achieve it. The centuries of math, and the decades of computer/programming research that contributed to this feat are applicable to many other fields and thus are MUCH more valuable than a hard drive of digits. To put it simply: Computing the digits of Pi is more of a sport.

**2018年07月23日12分24秒**

Mystical, just stumbled on your Pi calculation site from another stackoverflow question and couldn't help but gawk and giggle at what you guys did. Loved the harddrive failures/earthquakes in the logs :) pure amazing!

**2018年07月23日12分24秒**

That last formula (Leibniz formula, iirc) actually alternates addition and subtraction.

**2018年07月23日12分24秒**

Reduces the chances but I still cannot be sure with multiple approach solution, what if both are wrong. Checking on net doesn't hold validity, then why not take values off net itself. I am thinking about bbp which one is more suited ?

**2018年07月23日12分24秒**

IshanSharma If the two algorithms are independent, than the chances that both computations are wrong with identical results is pretty much zero. If anything goes wrong in either computation, the final results won't match - so you know at least one of them is wrong.

**2018年07月23日12分24秒**

Seconded. I think most of the answers here are just not putting nearly enough weight on the concept of mathematical proof. Whatever your program is for calculating digits of pi, it's never going to be any more convincing than the most convincing mathematical proof that your program's method does indeed calculate pi. Which suggests a different constraint on programs that pi calculate pi: that they ought to aim as much for understandability as performance and correctness.

**2018年07月23日12分24秒**

I don't quite see how it would help spot that the 1000th digit is off by 1. You would need very precise values of sin(pi/2) wouldn't you ?

**2018年07月23日12分24秒**

I'm not sure what to say about the previous answer, unless it is a joke or something. sin(pi/2) = 1 cos(pi/2) = 0 So, I'd say those sure converge fast.

**1970年01月01日00分03秒**

I guess it's not obvious to everyone that evaluating sin(x) and cos(x) to high precision is in fact much more difficult than computing Pi itself.

**2018年07月23日12分24秒**

For obvious reasons, you shouldn't use sin(pi/2) for this. Better to instead use sin(pi/6) and make sure it comes out as exactly 1/2.

**2018年07月23日12分24秒**

- Why is it faster to process a sorted array than an unsorted array?
- What is the fastest way to get the value of π?
- Fast algorithm to calculate Pi in parallel
- Leibniz formula for π/4
- Can a Monte Carlo pi calculation be used for a world record?
- Calculate PI using sum of inverse squares
- Is there a more efficient way to calculate pi?

ADS