Computing Ο€ to "infinite" binary precision in C #

It still looks like the Basr 2 equation of Fabrice Bellard is the way to go

alt text

Ironically, this would require a BigReal type; do we have it for .Net? .Net 4.0 has BigInteger.

Does anyone have a version of Haskell?

+6
c # haskell pi
source share
4 answers

Since you are requesting a version of Haskell, here is an article by Jerzy Karchmarchuk entitled "The Most Unreliable Technique in the World" for calculating & pi; ":

This document is an atypical exercise in lazy functional coding, written for fun and learning. It can be read and understood by anyone who understands the Haskell programming language. We show how to implement the Bailey-Borwain-Pluet Formula for & pi; in a core-recursive, incremental way that produces the numbers 3, 1, 4, 1, 5, 9 .. until memory is depleted. This is not a way if someone needs many numbers! Our coding strategy is vicious and dangerous, and it breaks provably. It is based on arithmetic in the field of infinite sequences of numbers representing proper fractions in an integer base. We show how to manipulate: add, multiply by an integer, etc. sequences from left to right endlessly that obviously cannot work in all cases due to ambiguities. Some deep philosophical implications are discussed in the findings.

It really does not solve the problem in an effective or very practical way, but entertains and shows some problems with lazy infinite arithmetic of accuracy.

Then there is also this article by Jeremy Gibbons .

+6
source share

To date, my favorite Haskell finger for pi comes from Jeremy Gibbons:

pi = g(1,0,1,1,3,3) where g(q,r,t,k,n,l) = if 4*q+rt<n*t then n : g(10*q,10*(rn*t),t,k,div(10*(3*q+r))t-10*n,l) else g(q*k,(2*q+r)*l,t*l,k+1,div(q*(7*k+2)+r*l)(t*l),l+2) 

The mathematical background that justifies this implementation can be found in:

Spigot Algorithm for Pi Digits

+5
source share

Wikipedia describes in detail how to obtain numerical approximations of pi here . They also give some pseudo-code example.

Edit: if you are interested in such mathematical problems without having problems with real reality (this is certainly a good relationship to IMHO), you can visit the Euler Project Page

+2
source share

There is such an opportunity to process large rational numbers in DLR based on dynamic languages ​​(for example, IronPython ). Or you can use any portable C / C ++ implementation of large real numbers through P / Invoke .

+2
source share

All Articles