I need a method for calculating π, but I also need to be able to stop it after, say, 'x' digits, and get retrieve those digits. Also, I need it to be in TI-Basic, and reasonably fast.

I have looked up (and remembered a few), but none of the algorithms I found (I didn't look too long though) seemed applicable to my needs. Thanks!
What you are looking for is called a spigot algorithm. I think I remember seeing a calculator implementation of such an algorithm somewhere, but I can't seem to find it. I think Jwinslow23 was working with those a while back, but my memory might be faulty (this was over a year ago).
mr womp womp wrote:
What you are looking for is called a spigot algorithm. I think I remember seeing a calculator implementation of such an algorithm somewhere, but I can't seem to find it. I think Jwinslow23 was working with those a while back, but my memory might be faulty (this was over a year ago).

Thanks!

I just remembered the Gregory-Leibniz series, which may be usable, but it will require a lot of wrangling.
EDIT:
I will use this:
http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf
EDIT^2
I found a method, with source, but it's in Python, a language in witch I have little experience. Could someone give me some help/lead me in the right direction?
Python Source
I tried, with my basic understanding, to port it, but it gave me a steadily incrementing number which overflowed after 5 (incorrect) digits.
Time for some pi!
Here are two implementations of the Leibniz formula for π. However, be advised that this is not a spigot algorithm, and in fact exhibits increasingly slower convergence.

Code:
//method 1
1->X
4->W
While 1
   X+2->X
   W-4/X->W
   Output(5,8,W
   X+2->X
   W+4/X->W
   Output(5,8,W
End


//method 2
Pause 4Sigma(((~1)^A)/(2A+1),A,0,X
//where X is some big number that determines the accuracy.

If you want to get pi to the accuracy of the calculator w/o using pi for some reason, then you can just do 4tan⁻¹(1). If you want a fast formula, I'd recommend the Ramanujan-Sato series, from which the popular Ramanujan pi formula can be obtained, which is on the order of the fastest known formulas.
Ramanujan-Sato series:

The famous Ramanujan pi formula of this form:

After 1 iteration, you already have more digits of accuracy than the calculator can display. Here it is in code:

Code:
99^^2/(2sqrt(2)Sigma(((4A)!(1103+26390A))/(((A!)^4)396^(4A)),A,0,X
//where X is the accuracy paramenter, but setting it to just 1 is enough to have all digits displayed be accurate.

For reference, the fastest converging series currently known is the Chudnovsky algorithm however, it is only marginally faster than the regular ramanujan formula, but is bigger in terms of bytes, and therefore undesireable in this case.
For quick computation, you may want to have a look at rational approximations of pi. Here are a few of my favorites in order of decimal places of accuracy:
    7 decimal places: 355/113 //it takes less digits to write out than the number of digits it produces
    9 decimal places: 3+(1-(9-8^(-5))^(-6))/(7+2^(-4 //a satisfying pandigital approach
    17 decimal places: (ln(396^4-104))/√58
    30 decimal places: ln(640320³+744)/√163
mr womp womp wrote:
Time for some pi!
Here are two implementations of the Leibniz formula for π. However, be advised that this is not a spigot algorithm, and in fact exhibits increasingly slower convergence.

Code:
//method 1
1->X
4->W
While 1
   X+2->X
   W-4/X->W
   Output(5,8,W
   X+2->X
   W+4/X->W
   Output(5,8,W
End


//method 2
Pause 4Sigma(((~1)^A)/(2A+1),A,0,X
//where X is some big number that determines the accuracy.

If you want to get pi to the accuracy of the calculator w/o using pi for some reason, then you can just do 4tan⁻¹(1). If you want a fast formula, I'd recommend the Ramanujan-Sato series, from which the popular Ramanujan pi formula can be obtained, which is on the order of the fastest known formulas.
Ramanujan-Sato series:

The famous Ramanujan pi formula of this form:

After 1 iteration, you already have more digits of accuracy than the calculator can display. Here it is in code:

Code:
99^^2/(2sqrt(2)Sigma(((4A)!(1103+26390A))/(((A!)^4)396^(4A)),A,0,X
//where X is the accuracy paramenter, but setting it to just 1 is enough to have all digits displayed be accurate.

For reference, the fastest converging series currently known is the Chudnovsky algorithm however, it is only marginally faster than the regular ramanujan formula, but is bigger in terms of bytes, and therefore undesireable in this case.
For quick computation, you may want to have a look at rational approximations of pi. Here are a few of my favorites in order of decimal places of accuracy:
    7 decimal places: 355/103 //it takes less digits to write out than the number of digits it produces
    9 decimal places: 3+(1-(9-8^(-5))^(-6))/(7+2^(-4 //a satisfying pandigital approach
    17 decimal places: (ln(396^4-104))/√58
    30 decimal places: ln(640320³+744)/√163

Thanks!
I feel like some of the rational approximations you included are incorrect. For example, for 7 decimal places the equation should be 355/113 instead of 355/103.

See this link for reference.
CHill wrote:
I feel like some of the rational approximations you included are incorrect. For example, for 7 decimal places the equation should be 355/113 instead of 355/103.

See this link for reference.

Yeah. I remember that fraction from an Isaac Asimov essay...
[edit]
This is really nitpicky, but for the pandigital approach to be pandigital, don't you need to include 0? (By adding it, in this case)

[edit^2]
Also, are there any formulae to figure out when the Leibniz series will produce another "stable" digit? There's probably a simple one that I have not tried, but I didn't try everything...
I found this which is of immense help! (posting it for people wanting to do similar things in the future)
Not sure what's going on with this discussion. Are there 2 discussions with the exact same title. I wrote a 21 line program to calculate Pi in a discussion with this same title. _iPhoenix_ Do a search on my user name, dave1707, and find the discussion with this title. Look in that discussion and scroll down until you find my program. That might be something you can use. So are there 2 discussions with the same title or am I imagining things.
dave1707 wrote:
Not sure what's going on with this discussion. Are there 2 discussions with the exact same title. I wrote a 21 line program to calculate Pi in a discussion with this same title. _iPhoenix_ Do a search on my user name, dave1707, and find the discussion with this title. Look in that discussion and scroll down until you find my program. That might be something you can use. So are there 2 discussions with the same title or am I imagining things.

You're not going crazy, I remember your post going by a while back, and it did ring a bell when I saw this post, but I went back and checked, _IPhoenix_ wasn't around when your post went through the feeds, so he probably wasn't aware.
Alright, time for me to speak out on this (I did a project with the same title a long time ago).

One, don't calculate pi. Calculate tau. Very Happy

Two, what I did to calculate pi was I used a spigot algorithm (more properly called a "streaming algorithm" to give digits one by one through running it successive times. If you want, I can give a writeup of it, in pseudo-code form, but you'll have to ask (I don't wanna do it on my own Razz ).

Three, even if you have the right algorithm, it's not that simple. In fact, it's not that simple on ANY computer implementation. Especially with the calculator's limitations, if you wanna go any farther than 14 digits (which is how many the calculator stores internally for all numbers), you'll need lists upon lists upon lists to keep track of much of the mathematics. The algorithm I used, luckily, uses no decimals, and only uses arbitrary-precision integers, so even that math was simplified by a huge factor, but just know that this will be a difficult undertaking.

Also, I'd just like to point out my favorite (deterministic) way to calculate tau thus far:

Code:
2→A
Ans⁻¹→B
While 1
A+Ans⁻¹→A
B+Ans⁻¹→B
Disp A/B
End

I'll leave adapting this for pi as an exercise to the reader Wink
JWinslow23 wrote:

Code:
2→A
Ans⁻¹→B
While 1
A+Ans⁻¹→A
B+Ans⁻¹→B
Disp A/B
End

I'll leave adapting this for pi as an exercise to the reader Wink


Code:
2→A
Ans⁻¹→B
While 1
A+Ans⁻¹→A
B+Ans⁻¹→B
Disp A/B/2
End

lol
Nope.

Code:
√(2→A
Ans⁻¹→B
While 1
A+Ans⁻¹→A
B+Ans⁻¹→B
Disp A/B
End
JWinslow23 wrote:
Alright, time for me to speak out on this (I did a project with the same title a long time ago).

One, don't calculate pi. Calculate tau. Very Happy

Two, what I did to calculate pi was I used a spigot algorithm (more properly called a "streaming algorithm" to give digits one by one through running it successive times. If you want, I can give a writeup of it, in pseudo-code form, but you'll have to ask (I don't wanna do it on my own Razz ).

Three, even if you have the right algorithm, it's not that simple. In fact, it's not that simple on ANY computer implementation. Especially with the calculator's limitations, if you wanna go any farther than 14 digits (which is how many the calculator stores internally for all numbers), you'll need lists upon lists upon lists to keep track of much of the mathematics. The algorithm I used, luckily, uses no decimals, and only uses arbitrary-precision integers, so even that math was simplified by a huge factor, but just know that this will be a difficult undertaking.

Also, I'd just like to point out my favorite (deterministic) way to calculate tau thus far:

Code:
2→A
Ans⁻¹→B
While 1
A+Ans⁻¹→A
B+Ans⁻¹→B
Disp A/B
End

I'll leave adapting this for pi as an exercise to the reader Wink

I didn't know that you had made a program of the same name, I guess we both picked it for the same reasons! And thanks for the code!
_iPhoenix_ wrote:
JWinslow23 wrote:
Alright, time for me to speak out on this (I did a project with the same title a long time ago).

One, don't calculate pi. Calculate tau. Very Happy

Two, what I did to calculate pi was I used a spigot algorithm (more properly called a "streaming algorithm" to give digits one by one through running it successive times. If you want, I can give a writeup of it, in pseudo-code form, but you'll have to ask (I don't wanna do it on my own Razz ).

Three, even if you have the right algorithm, it's not that simple. In fact, it's not that simple on ANY computer implementation. Especially with the calculator's limitations, if you wanna go any farther than 14 digits (which is how many the calculator stores internally for all numbers), you'll need lists upon lists upon lists to keep track of much of the mathematics. The algorithm I used, luckily, uses no decimals, and only uses arbitrary-precision integers, so even that math was simplified by a huge factor, but just know that this will be a difficult undertaking.

Also, I'd just like to point out my favorite (deterministic) way to calculate tau thus far:

Code:
2→A
Ans⁻¹→B
While 1
A+Ans⁻¹→A
B+Ans⁻¹→B
Disp A/B
End

I'll leave adapting this for pi as an exercise to the reader Wink

I didn't know that you had made a program of the same name, I guess we both picked it for the same reasons! And thanks for the code!

You're welcome.

Oh, and reminder, the code I gave is just a weird method to get to the value. It does not go fast, nor more accurate than can be stored in one calculator real.

And it's kinda cool that the word lengths are the digits of pi, "How I wish I could calculate pi." But this is better:

"Cheers to constant tau, a constant turny tau." Good Idea
JWinslow23 wrote:
_iPhoenix_ wrote:
JWinslow23 wrote:
Alright, time for me to speak out on this (I did a project with the same title a long time ago).

One, don't calculate pi. Calculate tau. Very Happy

Two, what I did to calculate pi was I used a spigot algorithm (more properly called a "streaming algorithm" to give digits one by one through running it successive times. If you want, I can give a writeup of it, in pseudo-code form, but you'll have to ask (I don't wanna do it on my own Razz ).

Three, even if you have the right algorithm, it's not that simple. In fact, it's not that simple on ANY computer implementation. Especially with the calculator's limitations, if you wanna go any farther than 14 digits (which is how many the calculator stores internally for all numbers), you'll need lists upon lists upon lists to keep track of much of the mathematics. The algorithm I used, luckily, uses no decimals, and only uses arbitrary-precision integers, so even that math was simplified by a huge factor, but just know that this will be a difficult undertaking.

Also, I'd just like to point out my favorite (deterministic) way to calculate tau thus far:

Code:
2→A
Ans⁻¹→B
While 1
A+Ans⁻¹→A
B+Ans⁻¹→B
Disp A/B
End

I'll leave adapting this for pi as an exercise to the reader Wink

I didn't know that you had made a program of the same name, I guess we both picked it for the same reasons! And thanks for the code!

You're welcome.

Oh, and reminder, the code I gave is just a weird method to get to the value. It does not go fast, nor more accurate than can be stored in one calculator real.

And it's kinda cool that the word lengths are the digits of pi, "How I wish I could calculate pi." But this is better:

"Cheers to constant tau, a constant turny tau." Good Idea


I prefer this.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement