3

the idea is to implement RFC3091 ("Pi Digit Generation Protocol") over HTTP. I've been having trouble finding a streaming (and/or spigot) algorithm that actually yields the correct decimal expansion.

Yes, there are a lot of implementations out there, but most require the allocation of a buffer upfront, the size of which is equal to the number of digits requested. Clearly, this does not work for generating an endless stream of digits.

An implementation in C/Py/PHP/etc would be ideal.

Thanks!

  • Are you asking me to do you homework for you? Is that the question? – Brian Tompsett - 汤莱恩 Feb 01 '15 at 10:51
  • This is just out of general interest, and surprise that I could not find it with a good hour of googling around. Note that I'm not a mathematician, so did not really go into the primary literature. I figured reaching out to the collective intelligence of SO would be a good way to get a good hint or link to a working method. Not too lazy to turn a formula into code, however. – sockdrawer999 Feb 01 '15 at 14:05

1 Answers1

-2

This question would be typical of the kind of exercise set in class, because it would make the student work for an answer, and an answer could not be downloaded by a simple internet search, which was why I made the comment I did. However, I also suspect that the OP is not skilled at searching because I found much helpful material quite quickly, which I'll refer to shortly.

StackOverflow is not a site for people to write code for you. A question of this nature is considered off-topic here. We help you with the code you have, but we do not give you code for nothing. At the moment you do not have an algorithm, or code or math, which is expecting quite a lot of SO. You have to give more yourself to get something back.

If you do not understand the math of generating infinite digit sequences of Pi you can ask in https://math.stackexchange.com/ which is more suited to this task. If you want to discuss class exercises like this one, perhaps go here https://matheducators.stackexchange.com/. If you want a more general chat with programmers go here: https://softwareengineering.stackexchange.com/

OK. Now to answers.

A quick google sent me here:

Su, Francis E., et al. "Finding the N-th digit of Pi." Math Fun Facts.

This cites:

  1. David Bailey, Peter Borwein, and Simon Plouffe. "On the rapid computation of various polylogarithmic constants", Math. Comp. 66(1997), 903-913.
  2. Victor Adamchik and Stan Wagon, "A simple formula for pi", Amer. Math. Monthly 104(1997), 852-855.

And uses the formula:

Pi = SUMk=0 to infinity 16-k [ 4/(8k+1) - 2/(8k+4) - 1/(8k+5) - 1/(8k+6) ].

To calculate hexadecimal digits of Pi without storing any previous digits. This is then easy to code with a simple persistent storage of the current hex digit and a digit count.....

See also related discussion in Efficiently computing the first 20-digit substring to repeat in the decimal expansion of Pi

Community
  • 1
  • 1
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129