Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upBbp formula #1989
Bbp formula #1989
Conversation
I didn't intend to include aliquot_sum.py in the pull request but it was added for some reason. Is there a way to make my pull request only include the addition of bbp_formula.py? |
This is pretty cool! One issue with this implementation however: Currently it is limited to Python’s standard double precision calculation. Which means regardless of how many iterations you supply you function with it will not get any more precise than that. To get around this we can use Python’s builtin module One note about the formula itself: This is mainly used for finding the n-th number of pi without needing to calculate any of the previous digits! Which means we can efficiently calculate the 1 billionth digit of pi without needing to know the digits leading up to that one. So maybe another PR can be opened using with this same file but implements a new function called |
# num_iterations + 1 because sum notation includes the last term | ||
for index in range(num_iterations + 1): |
This comment has been minimized.
This comment has been minimized.
TheSuperNoob
May 16, 2020
Contributor
I'm not sure the + 1 part actually is needed. By definition this is an infinite sum which just gets more and more accurate with each iteration, so anytime you stop is technically the last iteration :)
And it might fit better to how you define num_iterations
as well. As an example, default value for num_iterations
is 1000, and starting with 0 and ending with 999 gives you a total of 1000 iterations.
Very minor detail though and shouldn't affect the final result.
This comment has been minimized.
This comment has been minimized.
ken437
May 17, 2020
Author
Contributor
I tried to design it so that num_iterations represented the number on top of the sigma expression in the formula. Now that I think about it, though, it might have been better to name the variable something like upper_limit_of_summation rather than num_iterations
Rebase this branch on master. |
The first paragraph definitely sounds like a good idea. Maybe I could even let the user input the number of digits after the decimal point to round to (e.g. if they input "2" they get 3.14). As for the second paragraph, I could definitely do that in another pull request; I think it would be cool if our repository had an efficient general pi algorithm in one file and a digit extraction algorithm in another file. |
Yes you can do this! From what i can tell each iteration of this formula gives 1 digit of pi so theres not a whole lot you need to change, only update the calculations to be of type
I have already in the past implemented Chudnovsky's algorithm which is as far as im aware the most efficiant method of calculating many digits of pi. chudnovsky_algorithm.py |
I assume this revision is abandoned in favor of #1996? |
ken437 commentedMay 16, 2020
Describe your change:
Adds an algorithm that approximates pi using the Bailey-Borwein-Plouffe formula, described at https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula
Checklist:
Fixes: #{$ISSUE_NO}
.