You are not logged in.

- Topics: Active | Unanswered

- Index
- » Coder's Corner
- »
**Pi**

Pages: **1**

```
def calcPi():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
while True:
if 4*q+r-t < n*t:
yield n
nr = 10*(r-n*t)
n = ((10*(3*q+r))//t)-10*n
q *= 10
r = nr
else:
nr = (2*q+r)*l
nn = (q*(7*k)+2+(r*l))//(t*l)
q *= k
t *= l
l += 2
k += 1
n = nn
r = nr
import sys
pi_digits = calcPi()
i = 0
for d in pi_digits:
sys.stdout.write(str(d))
i += 1
if i == 40: print(""); i = 0
```

Above was a python code for displaying the digits of π endlessly from RosettaCode.

However, would anyone explain it and its algorithm to me?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

Hi;

You are aware of the AGM formula of Borwein. Do you understand what a spigot algorithm is?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

No Please explain it to me

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

A spigot algorithm can compute a specific digit of a constant without computing any of the others.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,015

Is there a BBP-type series for computing decimal digits of pi?

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

I do not remember the answer to that. I read the paper a long time ago. I remember I was working on one...

It is not known for every base and every constant whether there is that type of algorithm.

Here is the link to the paper I am talking about.

http://crd.lbl.gov/~dhbailey/dhbpapers/bbp-alg.pdf

Update:

Is there a BBP-type series for computing decimal digits of pi?

It appears that is an open question.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

bobbym wrote:

A spigot algorithm can compute a specific digit of a constant without computing any of the others.

Only in the hexadecimals?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

Hi;

I heard of ones for binary too.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,015

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

Is there a way of increasing the precision in C++?

So that I could use the AM-GM method?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

Hi;

Isn't there a multi precision oackage for C++?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

**noelevans****Member**- Registered: 2012-07-20
- Posts: 236

Hi!

Is there a spigot algorithm for calculating a particular digit in a division problem? For example,

what is the 53rd digit of the division 117/331 without calculating all those before it?

Writing "pretty" math (two dimensional) is easier to read and grasp than LaTex (one dimensional).

LaTex is like painting on many strips of paper and then stacking them to see what picture they make.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

Hi;

There aren't spigot algorithms for every constant and some are just not known. There are spigot algorithms for the computation of cube and square roots but I do not know of one for division.

But that does not mean there is not a simple way to do that problem, I am just not sure it is a spigot algorithm.

Using the algorithm the 53 digit after the decimal is an 8.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

**noelevans****Member**- Registered: 2012-07-20
- Posts: 236

Hi bobbym!

Is use Maple to do most of my novice number theory calculations. But it is limited to 268,435,448

digit numbers. So it should be able to handle little problems like what is the 260 millionth digit after

the decimal in the division (10^900+3)/(2^3000+1), eh? (I think it is a "5", but I wouldn't stake my

life on it!)

Searching on the internet, I couldn't find a spigot algorithm for these kinds of problems. Have you

had any luck finding such?

What mathematics package do you use for big number crunching?

Have a boukamendous day!

Writing "pretty" math (two dimensional) is easier to read and grasp than LaTex (one dimensional).

LaTex is like painting on many strips of paper and then stacking them to see what picture they make.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

Hi;

I use Maple, Mathematica, Derive and Geogebra for all my needs. You are correct it is a 5. There is a spigot algorithm of sorts for this.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

**noelevans****Member**- Registered: 2012-07-20
- Posts: 236

Hi!

For the kth digit after the decimal point in the division M/N in base b: I think this works:

x:=M*b^(k-1) mod N and then y:=iquo(b*x,N) is the kth digit after the decimal in base b.

I vaguely remember finding something like this some years ago. Now I'm trying to reconstruct the

rational behind it. I think it had something to do with finding the kth digit for 1/N and then changing

it appropriately for M*(1/N).

Does Mathematica or Maple have a function to directly produce this? I'm not familiar with

Mathematica. Does Mathematica handle more digits than Maple? Is its progamming language

similar to Maple?

But I'm getting too sleepy to think straight now, so off to bed I go.

Have a good night's sleep!

Writing "pretty" math (two dimensional) is easier to read and grasp than LaTex (one dimensional).

LaTex is like painting on many strips of paper and then stacking them to see what picture they make.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

Hi;

That is pretty close to the idea. I am not aware of any built in command to

do that in either language.

Does Mathematica handle more digits than Maple?

They are both very good numerically. I do not know offhand who handles more digits.

Is its progamming language

similar to Maple?

Maple has a procedural language while Mathematica a functional one. But Mathematica has enough procedural commands to get by as a procedural clone.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

Are Maple and Mathematica languages?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

No, they are CAS. But each of them has a built in language.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

**noelevans****Member**- Registered: 2012-07-20
- Posts: 236

Hi Agnishom!

They have "programming languages" that allow you to write programs to explore math and

science using graphs, simulations, calculations (some quite massive) and whatever else you can

find to do with it.

Hi bobbym! Top o' the mornin' to you!

Since I'm not very "functional" but more of a "procedural" type of individual I think that perhaps

I should stick with Maple. I'm having enough trouble trying to get a bit familiar with LaTex.

I've got too many "irons in the fire" to learn new languages unless I just can't get around it. At my

age I probably don't have too many good years left so I'm wanting to make the most of them trying

to write articles about my passion (making math "user friendly") and putting them on my web site.

For many years I though that division was the only "unforgiving" operation out of +,-,*,/ in the

sense that any mistake in the calculation trashed everything following it. But this spigot approach

doesn't have that problem so one can make a mistake in one place and not affect those following

just like for +, - and *.

Thanks for the input! Have a super day today!

LaTex is like painting on many strips of paper and then stacking them to see what picture they make.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

Hi;

I've got too many "irons in the fire" to learn new languages unless I just can't get around it.

Whenever you have too many irons in that fire just throw a few more on. You never know when you may need an extra hot iron.

At my

age I probably don't have too many good years left

Maybe you don't and maybe you do. But I am willing to bet a big bucket of wet armadillo hair ( very valuable in these parts ) that you do. You young people have got to start thinking optimistically.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

Again, Is latex a language?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,337

Hi;

Latex is a computer language for generating scientific documentation that is camera-ready.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

Pages: **1**

- Index
- » Coder's Corner
- »
**Pi**