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

You are not logged in.

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

Agnishom
Real Member

Online

### Pi

#### Code:

```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'
'The whole person changes, why can't a habit?' -Alokananda

## #2 2012-08-29 03:46:24

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #3 2012-08-29 14:06:31

Agnishom
Real Member

Online

### 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'
'The whole person changes, why can't a habit?' -Alokananda

## #4 2012-08-29 19:58:25

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #5 2012-08-29 19:59:46

anonimnystefy
Real Member

Offline

### Re: Pi

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

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #6 2012-08-29 20:02:13

bobbym

Online

### 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.

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.

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

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

Agnishom
Real Member

Online

### Re: Pi

#### 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'
'The whole person changes, why can't a habit?' -Alokananda

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

bobbym

Online

### Re: Pi

Hi;

I heard of ones for binary too.

In mathematics, you don't understand things. You just get used to them.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #9 2012-08-30 01:31:31

anonimnystefy
Real Member

Offline

### Re: Pi

The limit operator is just an excuse for doing something you know you can't.
“It's the subject that nobody knows anything about that we can all talk about!” ― Richard Feynman
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment

## #10 2012-09-20 15:16:01

Agnishom
Real Member

Online

### 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'
'The whole person changes, why can't a habit?' -Alokananda

## #11 2012-09-20 17:02:10

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #12 2012-09-21 11:39:01

noelevans
Full Member

Offline

### 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.

## #13 2012-09-21 12:46:47

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #14 2012-09-23 05:25:26

noelevans
Full Member

Offline

### 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
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.

## #15 2012-09-23 10:55:00

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #16 2012-09-23 14:54:39

noelevans
Full Member

Offline

### 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.

## #17 2012-09-23 19:43:22

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

Agnishom
Real Member

Online

### 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'
'The whole person changes, why can't a habit?' -Alokananda

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

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

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

noelevans
Full Member

Offline

### 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.

## #21 2012-09-24 00:05:47

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.

## #22 2012-09-24 01:14:30

Agnishom
Real Member

Online

### 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'
'The whole person changes, why can't a habit?' -Alokananda

## #23 2012-09-24 01:20:20

bobbym

Online

### 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.
Some cause happiness wherever they go; others, whenever they go.
If you can not overcome with talent...overcome with effort.