Pi Approximation Day - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: Not HP Calculators (/forum-7.html) +--- Forum: Not remotely HP Calculators (/forum-9.html) +--- Thread: Pi Approximation Day (/thread-18584.html) Pages: 1 2 |
Pi Approximation Day - Gerson W. Barbosa - 07-22-2022 11:47 PM Since today is Pi Approximation Day, just another one for the collection. Not an outstanding approximation, but this might fit into the Exotic Ones category: \(e^{\sqrt[11_{3}]{\frac{2222_{4}-\frac{1}{22_{9}^{2}+22_{16}^{2}+\frac{1}{1111_{7}}}}{99_{10}}}}\) RE: Pi Approximation Day - Valentin Albillo - 07-23-2022 01:20 AM . Hi, all, I can't let Pi Approximation Day (22/7) pass by without my humble contribution, so here you are. Set FIX 6 and then run on your HP-42S (physical or virtual) this little piece of mystery code I've hastily concocted and see what you get: 01 LBL "?" 02 10 03 STO ST Y 04 LBL 00 05 RCL ST Y 06 RCL× ST Z 07 RCL+ ST Z 08 RCLx ST X 09 RCL× ST L 10 1/X 11 - 12 DSE ST Y 13 GTO 00 14 SQRT 15 END See if you can fathom how/why it works. Regards. V. RE: Pi Approximation Day - Thomas Klemm - 07-23-2022 02:20 AM Nice. (07-23-2022 01:20 AM)Valentin Albillo Wrote: See if you can fathom how/why it works. It uses Ramanujan's formula: \( \begin{align} \pi^2 = 10 - \sum_{n=1}^{\infty} \frac{1}{n^3(n+1)^3} \end{align} \) RE: Pi Approximation Day - J-F Garnier - 07-23-2022 07:00 AM (07-23-2022 02:20 AM)Thomas Klemm Wrote:(07-23-2022 01:20 AM)Valentin Albillo Wrote: See if you can fathom how/why it works.It uses Ramanujan's formula: Can't you let others have a chance to play? J-F RE: Pi Approximation Day - Albert Chan - 07-23-2022 10:56 AM (07-22-2022 11:47 PM)Gerson W. Barbosa Wrote: \(e^{\sqrt[11_{3}]{\frac{2222_{4}-\frac{1}{22_{9}^{2}+22_{16}^{2}+\frac{1}{1111_{7}}}}{99_{10}}}}\) What is subscript / superscript notation mean? RE: Pi Approximation Day - vaklaff - 07-23-2022 11:26 AM (07-23-2022 10:56 AM)Albert Chan Wrote:(07-22-2022 11:47 PM)Gerson W. Barbosa Wrote: \(e^{\sqrt[11_{3}]{\frac{2222_{4}-\frac{1}{22_{9}^{2}+22_{16}^{2}+\frac{1}{1111_{7}}}}{99_{10}}}}\) My wife says they are the radix (for example 16 as a subscript indicates a hexadecimal number) and the good old exponent. RE: Pi Approximation Day - Gerson W. Barbosa - 07-23-2022 11:36 AM (07-23-2022 11:26 AM)vaklaff Wrote:(07-23-2022 10:56 AM)Albert Chan Wrote: What is subscript / superscript notation mean? Yes, they are base and exponent, respectively. In order to avoid confusion I should have written (22₉)² instead, for instance. That’s 20² = 400. RE: Pi Approximation Day - J-F Garnier - 07-23-2022 11:44 AM (07-23-2022 01:20 AM)Valentin Albillo Wrote: Set FIX 6 and then run on your HP-42S (physical or virtual) this little piece of mystery code I've hastily concocted and see what you get: Wonderful little program! It uses the specific HP-42S stack capability, running it on my trusty 32S would require a few more steps. Of course the interest is in this 42S version. Thank you Valentin, it's a pleasure to read you again. J-F RE: Pi Approximation Day - Gerson W. Barbosa - 07-23-2022 11:59 AM (07-23-2022 07:00 AM)J-F Garnier Wrote:(07-23-2022 02:20 AM)Thomas Klemm Wrote: It uses Ramanujan's formula: I had found the general term 1/(x^2 + x)^3 when I saw Thomas Klemm’s post. After driving almost 400 km during the day, I was glad he was that fast :-) Not as fun, but we can still rewrite Valentin’s intentionally slightly obfuscated program: Code:
1E1 -> 3,141592850081697528137175603520803 1E2 -> 3,141592653592821635772340191552596 1E3 -> 3,141592653589793270134930833666846 1E6 -> 3,141592653589793238462643383279535 pi —-> 3,141592653589793238462643383279503 Edited to fix a typo RE: Pi Approximation Day - C.Ret - 07-23-2022 03:18 PM (07-23-2022 11:44 AM)J-F Garnier Wrote:(07-23-2022 01:20 AM)Valentin Albillo Wrote: Set FIX 6 and then run on your HP-42S (physical or virtual) this little piece of mystery code I've hastily concocted and see what you get:Wonderful little program! I'm trying to fit it to my HP-41C, but I must have missed something. Especially at step 09 RCL× ST L; where is the LAST register initialized on the first pass? Why isn't this a problem regardless of what is previously stored in the LAST register? Is this a specific HP-42S trick, does memory recall arithmetic modify the LAST register? I'm stuck; need a little more beers to drink and any good advice to hear ! RE: Pi Approximation Day - Gerson W. Barbosa - 07-23-2022 03:41 PM (07-23-2022 03:18 PM)C.Ret Wrote: Is this a specific HP-42S trick, does memory recall arithmetic modify the LAST register? Yes, it does, unlike memory store arithmetic: 05 RCL ST Y (T 10 10 10) 06 RCL× ST Z (… 100) 07 RCL+ ST Z (… 110) 08 RCL× ST X (… 12100) 09 RCL× ST L (… 1331000) RE: Pi Approximation Day - C.Ret - 07-23-2022 05:18 PM (07-23-2022 03:41 PM)Gerson W. Barbosa Wrote:(07-23-2022 03:18 PM)C.Ret Wrote: Is this a specific HP-42S trick, does memory recall arithmetic modify the LAST register?Yes, it does, unlike memory store arithmetic: Thank you for your quick response; this is a different behavior from the HP-15C memory recall arithmetic logic. That explain why I was so lost. 001 LBL "WLP 002 10 003 ENTER^ 004 LBL 00 005 RCL Y 006 X^2 007 LASTX 008 + 009 -3 010 Y^X 011 - 012 DSE Y 013 GTO 00 014 SQRT 015 END With FIX 7 display format, this little program give a better approximation of PI than 22/07. Surprisingly, the number of instructions is the same as Valentin Albillo's original code. \( \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 \) RE: Pi Approximation Day - Thomas Klemm - 07-23-2022 06:46 PM (07-23-2022 11:59 AM)Gerson W. Barbosa Wrote: Not as fun, but we can still rewrite Valentin’s intentionally slightly obfuscated program Without recall-arithmetic it uses even fewer bytes: Code: 00 { 27-Byte Prgm } Using a register we can translate it for other HP calculators as well. HP-15C: Code: 001 { 44 0 } STO 0 HP-25: Code: 01: 23 00 : STO 0 We can even do it on the HP-35 if we consider the following manual steps a program. Initialize: Code: CLR Repeat until 0: Code: ENTER↑ ENTER↑ × + Finalize: Code: R↓ While we could start subtracting the terms from an initial value of 10, it is better to start the summation from 0 to avoid cancellation. RE: Pi Approximation Day - Didier Lachieze - 07-23-2022 09:09 PM (07-23-2022 06:46 PM)Thomas Klemm Wrote: We can even do it on the HP-35 if we consider the following manual steps a program. For this, back in the days, you would have used an HP-35 Key Sequence Form. RE: Pi Approximation Day - Gerson W. Barbosa - 07-23-2022 10:08 PM (07-23-2022 06:46 PM)Thomas Klemm Wrote: Without recall-arithmetic it uses even fewer bytes: Thanks. I tend to value least number of steps over least number of bytes on the HP-42S where memory is not a concern, but I’ve just noticed there’s no reason at all to use recall arithmetic in my step 05 above when a simple X↑2 instruction suffices. RE: Pi Approximation Day - Valentin Albillo - 07-23-2022 11:31 PM . Hi, Jean-François, (07-23-2022 11:44 AM)J-F Garnier Wrote:(07-23-2022 01:20 AM)Valentin Albillo Wrote: Set FIX 6 and then run on your HP-42S (physical or virtual) this little piece of mystery code I've hastily concocted and see what you get: Thank you very much for your appreciation. Quote:It uses the specific HP-42S stack capability, running it on my trusty 32S would require a few more steps. Of course the interest is in this 42S version. The little code I gave was intentionally obfuscated and particularized to add just 10 terms, to try and hide the "10" as if it were only the loop counter. My general non-obfuscated version which will add N terms is this 14-step, 26-byte HP-42S program: 01 LBL "?" 02 10 03 LBL 00 04 RCL ST Y 05 X↑2 06 RCL+ ST L 07 X↑2 08 RCL× ST L 09 1/X 10 - 11 DSE ST Y 12 GTO 00 13 SQRT 14 END Key in N and XEQ "?". Running it on Free42 Decimal produces the following results for N=100, 1000, 10000 and 100000 terms: PI 3.14159 26535 89793 23846 26433 83279 502 ------------------------------------------------- 100 3.14159 26535 92821 63577 23401 91552 596 (13 digits save 3 ulp) 1000 3.14159 26535 89793 27013 49308 33666 846 (18 digits save 4 ulp) 10000 3.14159 26535 89793 23846 29615 34056 207 (23 digits save 3 ulp) 100000 3.14159 26535 89793 23846 26433 86462 443 (28 digits save 3 ulp) ------------------------------------------------- PI 3.14159 26535 89793 23846 26433 83279 502 I like this series for Pi very much: 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, e.g. using as little as 100 terms gets you better than 12-digit accuracy and on Free42 it runs instantly. Quote:Thank you Valentin, it's a pleasure to read you again. Thank you, J-F, your feedback is most appreciated and if more people would do likewise that would surely motivate me to post again. Best regards. V. RE: Pi Approximation Day - Thomas Klemm - 07-24-2022 07:03 AM (07-23-2022 11:31 PM)Valentin Albillo Wrote: Running it on Free42 Decimal produces the following results for N=100, 1000, 10000 and 100000 terms: This is the table I got using Valentin's program with the additional value for 1000000: PI 3.14159 26535 89793 23846 26433 83279 502 ------------------------------------------------- 100 3.14159 26535 92821 63577 23401 91552 596 (13 digits save 3 ulp) 1000 3.14159 26535 89793 27013 49308 33666 845 (18 digits save 4 ulp) 10000 3.14159 26535 89793 23846 29615 34056 207 (23 digits save 3 ulp) 100000 3.14159 26535 89793 23846 26433 86462 453 (28 digits save 3 ulp) 1000000 3.14159 26535 89793 23846 26433 83283 745 (31 digits save 4 ulp) ------------------------------------------------- PI 3.14159 26535 89793 23846 26433 83279 502 Please note the slight differences for 1000 and 100000. This is the table I got using Gerson's program that adds 10 at the end: PI 3.14159 26535 89793 23846 26433 83279 502 ------------------------------------------------- 100 3.14159 26535 92821 63577 23401 91552 596 (13 digits save 3 ulp) 1000 3.14159 26535 89793 27013 49308 33666 846 (18 digits save 4 ulp) 10000 3.14159 26535 89793 23846 29615 34056 207 (23 digits save 3 ulp) 100000 3.14159 26535 89793 23846 26433 86462 443 (28 digits save 3 ulp) 1000000 3.14159 26535 89793 23846 26433 83279 535 (33 digits save 3 ulp) ------------------------------------------------- PI 3.14159 26535 89793 23846 26433 83279 502 Interestingly it agrees exactly with Valentin's table. For 1000000 it shows the effect of cancellation when starting with 10. Somewhat related: Programming Exercise (HP-15C, 15C LE - and others) RE: Pi Approximation Day - Dan C - 07-24-2022 09:37 AM I'm curious about the PI number... How many decimals in the PI are needed to get acceptable results in practical everyday calculations? Is 3.14 enough ? Or do you have to use more? ( i think you have, but how many?) RE: Pi Approximation Day - Maximilian Hohmann - 07-24-2022 10:58 AM Hello! (07-24-2022 09:37 AM)Dan C Wrote: How many decimals in the PI are needed to get acceptable results in practical everyday calculations? Is 3.14 enough ? Or do you have to use more? ( i think you have, but how many?) For my own personal everyday applications involving Pi (like tinkering around the house and garden) 3.0 is a good enough approximation :-) At work, many years ago, we were doing microvave imaging measurements and calculations. These involved propagation models with many e^i*Pi terms. Even using (then) state-of-the art measuring equipment (mostly from Hp of course, Agilent had not been sourced out then) no more then 4 (or maybe 5 for theoretical calculations) decimal places were required. Everything else would have been drowned in the noise anyway. Regards Max RE: Pi Approximation Day - Dan C - 07-24-2022 11:29 AM (07-24-2022 10:58 AM)Maximilian Hohmann Wrote: Hello! Thanks for your input! So in real life calculations you are fine with PI at 3.1415, and that will do in most situations. |