Two days ago (or yesterday depending on your timezone) was π-day. So I thought it was a good day to calculate π.
I used Machin-like formula to calculate π, in homage of William Shanks, who calculated 527 correct digits of π well before electronic computers. Though I used Newton's Accelerated Arctangent Series and I got my terms from here.
I rewrote the arctangent series to make it do everything in integer domain.
And it works. See this Stack Overflow question for an earlier iteration of my implementation.
Now I have re-implemented it again so that I can get as many correct digits of π as I want without using any libraries, and using these terms: ((44, 57), (7, 239), (-12, 682), (24, 12943))
, I was able to get the first 1024 decimal places of π in 292 iterations:
In [139]: Machin_Pi.get_n_places(4, 1024)
Out[139]:
(292,
'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788')
But I haven't been able to accelerate the convergence of the series further, I have tried to make it converge faster by using binary split (though if I understand correctly it gets the same result in less iterations?), but I cannot make it work, my math is very rusty, I am a high-school dropout and the last year I attended school was 2017...
Would such a question be on topic if I am asking to make the series converge faster?
1 Answer 1
Improving Performance
But I haven't been able to accelerate the convergence of the series further, I have tried to make it converge faster
Improving the performance of code is on-topic. However, the any or all rule as stated in our help center means answers don't need to improve the performance to be deemed good by the community.
Do I want feedback about any or all facets of the code?
Feel free to call attention to specific areas you are concerned about (performance, formatting, etc). However, any aspect of the code posted is fair game for feedback and criticism.
Fixing the Binary Split
I have tried to make it converge faster by using binary split (though if I understand correctly it gets the same result in less iterations?), but I cannot make it work
We require code to be working as intended. Since you've said you can't get the binary split working then any questions about the algorithm would be off-topic.
Conclusion
You can't ask about the binary split, you can ask about the existing code and ask for us to improve the performance. However, we're a site focused on reviewing code, not improving the performance of code. So you may not get what you want.
-
3\$\begingroup\$ Okay, I will post the existing code asking for decreasing the execution time. And I will ask another question on Math Stack Exchange about improving the convergence then. \$\endgroup\$Ξένη Γήινος– Ξένη Γήινος2025年03月15日 18:46:51 +00:00Commented Mar 15 at 18:46
-
1\$\begingroup\$ @ΞένηΓήινος I don't know Math.SE's rules. But your game plan is the one I'd follow. \$\endgroup\$2025年03月15日 19:44:50 +00:00Commented Mar 15 at 19:44