Pi Approximation Day
|
07-24-2022, 11:30 AM
(This post was last modified: 07-24-2022 11:32 AM by Thomas Klemm.)
Post: #21
|
|||
|
|||
RE: Pi Approximation Day
(07-22-2022 11:47 PM)Gerson W. Barbosa Wrote: \( I tried to convert \(2222_{4}\) in my head: \( \begin{align} 2222_{4} &= 2 \cdot 1111_{4} \\ &= 2 \cdot (4^3 + 4^2 + 4 + 1) \\ &= 2 \cdot \frac{4^4 - 1}{4 - 1} \\ &= 2 \cdot \frac{17 \cdot 15}{3} \\ &= 170 \\ \end{align} \) And similarly \(1111_{7}\): \( \begin{align} 1111_{7} &= 7^3 + 7^2 + 7 + 1 \\ &= \frac{7^4 - 1}{7 - 1} \\ &= \frac{50 \cdot 48}{6} \\ &= 400 \\ \end{align} \) The other numbers were easy, so I ended up with: 3.141592653589793212117310511154447 ----------------------------------- 3.141592653589793238462643383279503 You never cease to amaze me with your approximations of \(\pi\). Today I learned how to enter the base of a number in the Wolfram language: E^Surd[(4^^2222 - 1/(9^^22^2 + 16^^22^2 + 1/7^^1111))/99, 3^^11] |
|||
07-24-2022, 11:59 AM
Post: #22
|
|||
|
|||
RE: Pi Approximation Day
(07-23-2022 05:18 PM)C.Ret Wrote: \( \sqrt{10-\frac{1}{\left ( 10^2+10 \right )^3}-\frac{1}{\left ( 9^2+9 \right )^3}-\frac{1}{\left ( 8^2+8 \right )^3}-\cdots -\frac{1}{\left ( 2^2+2 \right )^3}-\frac{1}{\left ( 1^2+1 \right )^3}} = \sqrt{ \frac{2\,780\,722\,699}{281\,746\,080} } \approx \pi \) Interesting. Using that equation with a summation of 1-10 approximates Pi to 7 digits. Using it with a summation of 1-87 approximates Pi to 12 digits. |
|||
07-24-2022, 01:28 PM
Post: #23
|
|||
|
|||
RE: Pi Approximation Day
(07-24-2022 11:30 AM)Thomas Klemm Wrote: Today I learned how to enter the base of a number in the Wolfram language:I tested it in Maple and was amaized of accuracy of this approximation too Code:
|
|||
07-24-2022, 03:52 PM
Post: #24
|
|||
|
|||
RE: Pi Approximation Day
(07-24-2022 11:59 AM)Steve Simpkin Wrote: Using that equation with a summation of 1-10 approximates Pi to 7 digits. Looking at the table in this previous post we can see that we gain about 5 digits if n is multiplied by 10. Which is really bad. Compare it with this program to calculate the Taylor series of the \(\arctan(x)\) function: \( \begin{align} \arctan(x)=x-\frac{x^{3}}{3}+\frac{x^{5}}{5}-\frac{x^{7}}{7}+\cdots =\sum _{n=0}^{\infty}\frac {(-1)^{n}x^{2n+1}}{2n+1} \end{align} \) And then use: \( \begin{align} \frac{\pi}{4}=\arctan \frac{1}{2} + \arctan \frac{1}{3} \end{align} \) Code: 00 { 23-Byte Prgm } Example Make sure we're at the beginning of the program: RTN Calculate \(\arctan \frac{1}{2}\): 2 1/X 53 R/S STO 01 4.636476090008061162142562314612144e-1 Calculate \(\arctan \frac{1}{3}\): 3 1/X 33 R/S 3.217505543966421934014046143586614e-1 Calculate \(\pi=4\left(\arctan \frac{1}{2} + \arctan \frac{1}{3}\right)\): RCL 01 + 4 × 3.141592653589793238462643383279503 Which is correct to all places. (07-23-2022 11:31 PM)Valentin Albillo Wrote: it converges very fast (order 6), the general term is extremely simple to program needing just 6 steps, and this makes for speedy looping and very short running times The code in the loop of this program isn't much more complicated but instead of using 1000000 terms to get 33 correct digits we only need 53 + 33 = 86 terms to get 34 correct digits of \(\pi\). And there are ways to even reduce this further e.g. by using Machin's formula: \( \begin{align} \frac{\pi}{4}=4 \arctan \frac{1}{5} - \arctan \frac{1}{239} \end{align} \) References |
|||
07-24-2022, 06:39 PM
(This post was last modified: 07-24-2022 07:25 PM by pauln.)
Post: #25
|
|||
|
|||
RE: Pi Approximation Day
In particular, in Python it is trivial to compute \(\pi\) (with no library, just integer arithmetic) and other constants with any number of decimals. For example this program computes 10,000 digits of \(\pi\) (The first 9,995 digits being correct). Takes 0.3 seconds on my laptop.
Code:
Result: Code: 10000 digits of pi: |
|||
07-24-2022, 07:13 PM
Post: #26
|
|||
|
|||
RE: Pi Approximation Day
(07-24-2022 03:52 PM)Thomas Klemm Wrote: Calculate \(\arctan \frac{1}{3}\): atan(1/3) ≈ 18.4° ≈ pi/10 We might as well get exactly pi/10, by adjusting atan argument. pi/10 = 18° = sin(1/(2ϕ)) tan(pi/10) = 1/√((2ϕ)²-1) = 1/√(4ϕ+3) = 1/√(5+√20)) 20 SQRT 5 + SQRT 1/X // 3.249196962329063261558714122151344e-1 33 R/S 3.141592653589793238462643383279503e-1 |
|||
07-24-2022, 09:10 PM
Post: #27
|
|||
|
|||
RE: Pi Approximation Day
That's rather a good idea Albert!
About these various offerings for more efficient calculation of pi - I feel they miss the point a little bit. I think - for me - the appeal of Valentin's offering comes from the rather small number of terms to get the recognisable first few digits, and the clever hiding of the 10 as a loop counter. I've run this formula of Ramanujan on various systems with various kinds of floats... the long double precision on Raspberry Pi 4 takes some 275000 terms to converge, giving about 30 digits of pi. |
|||
07-24-2022, 10:16 PM
Post: #28
|
|||
|
|||
RE: Pi Approximation Day | |||
07-24-2022, 11:27 PM
Post: #29
|
|||
|
|||
RE: Pi Approximation Day
(07-24-2022 09:10 PM)EdS2 Wrote: [...] I think - for me - the appeal of Valentin's offering comes from the rather small number of terms to get the recognisable first few digits, and the clever hiding of the 10 as a loop counter. [...] I will add that the solution has a nice "binary" feeling. The only digits used are 0's and 1's: "10", "LBL 00", "1/X" and "GTO 00". And the sequence with the different variants of RCL, lines 5 through 9, is also quite pleasing. |
|||
07-25-2022, 12:03 AM
Post: #30
|
|||
|
|||
RE: Pi Approximation Day
(07-24-2022 10:16 PM)Thomas Klemm Wrote: \( Assumed x in first quadrant, to avoid cancellation errors, we can use cotangent cot(x/2) = cot(x) + √(1 + cot(x)^2) cot(pi/6) = √3 → cot(pi/12) = √3 + √(1+3) = 2 + √3 3 SQRT 2 + // cot(pi/12) ≈ 3.732 ENTER X^2 1 + SQRT + // cot(pi/24) ≈ 7.596 ENTER X^2 1 + SQRT + // cot(pi/48) ≈ 15.26 ENTER X^2 1 + SQRT + // cot(pi/96) ≈ 30.55 1/X 11 R/S 96 * 3.141592653589793238462643383279503 |
|||
07-25-2022, 12:26 AM
Post: #31
|
|||
|
|||
RE: Pi Approximation Day
.
Hi, EdS2, (07-24-2022 09:10 PM)EdS2 Wrote: About these various offerings for more efficient calculation of pi - I feel they miss the point a little bit. I think - for me - the appeal of Valentin's offering comes from the rather small number of terms to get the recognisable first few digits, and the clever hiding of the 10 as a loop counter. Thanks for your appreciation, and that also applies to pauln's aesthetic appreciation as well. I also think Mr. Klemm et al. really did miss the point, turning this Pi Approximation Day thread into yet another Pi Day thread. Getting Pi to 1,000 or 10,000 or whatever high number of places isn't proper for an approximation (like 22/7), which surely should never exceed the 10-12 digits available in our vintage HP calculators (as my 14-step code did), and has been done and redone and re-redone to death countless times in this forum and others. Also, getting said 1,000 digits on a laptop or using Matlab or something similar utterly detracts from the purpose here. This is the Museum of HP calculators, after all. There are plenty of places where you can show off your proficiency with Matlab or Mathematica or Python in your laptop if for the umpteen time you can't resist the urge to show off your abilities using such. Best regards. V out. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
07-25-2022, 06:38 AM
Post: #32
|
|||
|
|||
RE: Pi Approximation Day
(07-25-2022 12:03 AM)Albert Chan Wrote: 3 SQRT 2 + // cot(pi/12) ≈ 3.732 Now we're close enough to 0 that using only the first two terms of the Taylor series of the \(\arctan(x)\) function gives a good approximation for \(\pi\): \( \begin{align} \arctan(x)\approx x-\frac{x^{3}}{3} \end{align} \) So we can continue with: ENTER ENTER X↑2 × 3 ÷ - 96 × 3.14159193225 Instead of: ENTER X^2 1 + SQRT + we could also use: 1 X<>Y →POL LASTX + |
|||
07-25-2022, 09:28 PM
(This post was last modified: 07-26-2022 01:47 PM by Thomas Klemm.)
Post: #33
|
|||
|
|||
RE: Pi Approximation Day
(07-23-2022 02:20 AM)Thomas Klemm Wrote: It uses Ramanujan's formula: As I wondered why this should be the case I came up with the following derivation: \( \begin{align} \frac{1}{n} - \frac{1}{n+1} &= \frac{n+1 - n}{n(n+1)} \\ &= \frac{1}{n(n+1)} \\ \end{align} \) Plug this into the infinite sum to get: \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{n^3(n+1)^3} &= \sum_{n=1}^{\infty} \frac{1}{[n(n+1)]^3} \\ &= \sum_{n=1}^{\infty} \left[\frac{1}{n} - \frac{1}{n+1}\right]^3 \\ \end{align} \) That's a bit like a telescoping sum. It is of the form: \( \begin{align} [a-b]^3 + [b-c]^3 + [c-d]^3 + \cdots &= a^3 - 3a^2b + 3ab^2 - b^3 \\ &+ b^3 - 3b^2c + 3bc^2 - c^3 \\ &+ c^3 - 3c^2d + 3cd^2 - d^3 \\ &+ \cdots \end{align} \) We notice that \(b^3\), \(c^3\), \(d^3\), \(\cdots\) all cancel. Also we can extract the common factors of the residual terms: \( \begin{align} [a-b]^3 + [b-c]^3 + [c-d]^3 + \cdots = a^3 &- 3ab(a-b) \\ &- 3bc(b-c) \\ &- 3cd(c-d) \\ &+ \cdots \end{align} \) This leaves us with: \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{n^3(n+1)^3} &= 1 - 3 \sum_{n=1}^{\infty} \frac{1}{n} \frac{1}{n+1} \left[\frac{1}{n} - \frac{1}{n+1}\right] \\ &= 1 - 3 \sum_{n=1}^{\infty} \frac{1}{n} \frac{1}{n+1}\frac{1}{n(n+1)} \\ &= 1 - 3 \sum_{n=1}^{\infty} \frac{1}{[n(n+1)]^2} \\ \end{align} \) A quick sanity check shows: Sum[1/(n(n+1))^2,{n,1,∞}] \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{[n(n+1)]^2} = \frac{1}{3}\left(\pi^2-9\right) \end{align} \) It appears that we're on track. We can do the same as before but now the squares don't cancel: \( \begin{align} [a-b]^2 + [b-c]^2 + [c-d]^2 + \cdots &= a^2 - 2ab + b^2 \\ &+ b^2 - 2bc + c^2 \\ &+ c^2 - 2cd + d^2 \\ &+ \cdots \end{align} \) Instead they are added twice (except for the first) and so we get: \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{[n(n+1)]^2} &= 2 \sum_{n=1}^{\infty} \frac{1}{n^2} - 1 \\ &- 2 \sum_{n=1}^{\infty} \frac{1}{n(n+1)} \\ \end{align} \) But the second sum is a telescoping sum: \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{n(n+1)} &= \sum_{n=1}^{\infty} \frac{1}{n} - \frac{1}{n+1} \\ &= 1 \end{align} \) And thus we end up with: \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{[n(n+1)]^2} &= 2 \sum_{n=1}^{\infty} \frac{1}{n^2} - 3 \\ \end{align} \) But now we're in well known territory since: \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6} \\ \end{align} \) This leads to: \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{[n(n+1)]^2} &= 2 \frac{\pi^2}{6} - 3 \\ &= \frac{\pi^2}{3} - 3 \\ &= \frac{1}{3}\left(\pi^2-9\right) \\ \end{align} \) Plug this into the formula above and we get: \( \begin{align} \sum_{n=1}^{\infty} \frac{1}{n^3(n+1)^3} &= 1 - 3 \sum_{n=1}^{\infty} \frac{1}{[n(n+1)]^2} \\ &= 1 - 3 \frac{1}{3}\left(\pi^2-9\right) \\ &= 1 - \pi^2 + 9 \\ &= 10 - \pi^2 \\ \end{align} \) References |
|||
07-26-2022, 12:51 AM
Post: #34
|
|||
|
|||
RE: Pi Approximation Day
(07-23-2022 02:20 AM)Thomas Klemm Wrote: It uses Ramanujan's formula: We can adjust numerator, to speed up partial fraction decomposition. 1 = ((n+1)-n)^2 = (n+1)^2 - 2*n*(n+1) + n^2 1 = ((n+1)-n)^3 = (n+1)^3 - 3*n*(n+1) - n^3 1 = (n+1)^3 - n^3 - 3*n*(n+1) * ((n+1)^2 - 2*n*(n+1) + n^2) Divide both side by (n*(n+1))^3, we have: \(\displaystyle \frac{1}{n^3\;(n+1)^3} = \left(\frac{1}{n^3}-\frac{1}{(n+1)^3} \right) - 3×\left( \frac{1}{n^2} + \frac{1}{(n+1)^2}\right) + 6×\left( \frac{1}{n} - \frac{1}{n+1}\right) \) \(\displaystyle \sum_{n=1}^{\infty} \frac{1}{n^3(n+1)^3} = 1 - 3×(\frac{\pi^2}{6} + \frac{\pi^2}{6} - 1) + 6 = 10 - \pi^2\) |
|||
07-26-2022, 01:27 AM
(This post was last modified: 07-26-2022 02:20 AM by pauln.)
Post: #35
|
|||
|
|||
RE: Pi Approximation Day
(07-26-2022 12:51 AM)Albert Chan Wrote:(07-23-2022 02:20 AM)Thomas Klemm Wrote: It uses Ramanujan's formula: Thanks, I believe there is a typo in: 1 = ((n+1)-n)^3 = (n+1)^3 - 3*n*(n+1) - n^3 but, otherwise, the proof is extremely easy to read. Edit: actually, there is no typo, somehow I was expecting an additional term |
|||
07-26-2022, 05:24 AM
Post: #36
|
|||
|
|||
RE: Pi Approximation Day
(07-26-2022 12:51 AM)Albert Chan Wrote: partial fraction decomposition Link for the lazy: Apart[1/(n(n+1))^3] |
|||
07-26-2022, 12:27 PM
(This post was last modified: 06-20-2024 07:42 PM by Albert Chan.)
Post: #37
|
|||
|
|||
RE: Pi Approximation Day
Perhaps a simpler way to do partial fraction decomposition of (1/n - 1/(n+1))^3
Let a = 1/n, b = -1/(n+1) --> a+b = -a*b (a+b)^3 = a^3 + b^3 + 3*a*b*(a+b) = (a^3+b^3) - 3*(a+b)^2 (a+b)^2 = a^2 + b^2 + 2*a*b = (a^2+b^2) - 2*(a+b) --> (a+b)^3 = (a^3+b^3) - 3*(a^2+b^2) + 6*(a+b) We can generalize, for positive integer powers p (proof welcome) \(\displaystyle \left( \frac{1}{n} + \frac{-1}{n+1} \right) ^p = \sum_{k=0}^{p-1}\;(-1)^k \binom{p-1+k}{p-1} \left( \left(\frac{1}{n}\right)^{p-k} + \left(\frac{-1}{n+1}\right)^{p-k} \right) \) Update: Many proofs |
|||
07-26-2022, 01:38 PM
Post: #38
|
|||
|
|||
RE: Pi Approximation Day
For \(p=5\) we get:
\( \begin{align} \sum_{n=1}^{\infty} \frac{1}{(n (n + 1))^5} = 126 - \frac{35 \pi^2}{3} - \frac{\pi^4}{9} \end{align} \) Depending on the number of terms used on the left-hand side, we get the following approximations for \(\pi\). \(0\): \( \begin{align} \sqrt{\frac{3}{2} \left(\sqrt{1729} - 35 \right)} \approx 3.14195300074 \end{align} \) \(\frac{1}{2^5}\): \( \begin{align} \sqrt{\frac{3}{8} \left(\sqrt{27662} - 140 \right)} \approx 3.14159418065 \end{align} \) \(\frac{1}{2^5}+\frac{1}{6^5}\): \( \begin{align} \frac{1}{6} \sqrt{\sqrt{5041398} - 1890} \approx 3.14159270392 \end{align} \) |
|||
08-03-2022, 04:53 PM
Post: #39
|
|||
|
|||
RE: Pi Approximation Day
Here's a short and sweet Basic variation on Valentin's offering:
Code: FORN=1TO19:S=S+(N*N+N)^-3:NEXT:PRINTSQR(N/2-S) |
|||
08-07-2022, 11:42 AM
Post: #40
|
|||
|
|||
RE: Pi Approximation Day | |||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: