Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫  π  -¹ ² ³ °

You are not logged in.

## #1 2012-08-26 01:19:25

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,775
Website

### Pi

``````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

## #2 2012-08-28 05:46:24

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #3 2012-08-28 16:06:31

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,775
Website

### Re: Pi

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

## #4 2012-08-28 21:58:25

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #5 2012-08-28 21:59:46

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

### Re: Pi

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

## #6 2012-08-28 22:02:13

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.

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.

http://www.andrews.edu/~calkins/physics/Miracle.pdf

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #7 2012-08-29 01:00:38

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,775
Website

### Re: Pi

bobbym wrote:

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

'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

## #8 2012-08-29 01:43:56

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #9 2012-08-29 03:31:31

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

### Re: 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

## #10 2012-09-19 17:16:01

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,775
Website

### Re: Pi

Is there a way of increasing the precision in C++?
So that I could use the AM-GM method?

'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

## #11 2012-09-19 19:02:10

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #12 2012-09-20 13:39:01

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

### Re: Pi

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

## #13 2012-09-20 14:46:47

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #14 2012-09-22 07:25:26

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

### Re: Pi

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

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

## #15 2012-09-22 12:55:00

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #16 2012-09-22 16:54:39

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

### Re: Pi

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

## #17 2012-09-22 21:43:22

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #18 2012-09-22 23:07:32

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,775
Website

### Re: Pi

Are Maple and Mathematica languages?

'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

## #19 2012-09-23 01:13:43

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #20 2012-09-23 01:57:41

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

### Re: Pi

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!

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

## #21 2012-09-23 02:05:47

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #22 2012-09-23 03:14:30

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,775
Website

### Re: Pi

Again, Is latex a language?

'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

## #23 2012-09-23 03:20:20

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Pi

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.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline