Creating digits of pi
|
02-06-2018, 12:24 AM
Post: #1
|
|||
|
|||
Creating digits of pi
Yes, this old chestnut again. Except my guugle-foo has foo'ed and I can't find anything in HP-50g that's relevant. Put simply, I want to have a procedure that generates x digits of PI starting from an offset, i.e. 1:offset, 2:digit_count. An example would be ten digits of PI starting from the 49,238th position.
I don't know of good programs that can generate only a subset of digits, only of programs that can generate x digits of PI as a string (PI50G being one example I came across). Does anyone have a good pointer to what I'd like? (Need is a strong word, perhaps desire just for the sake of it). (Post 168) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
02-06-2018, 01:38 AM
Post: #2
|
|||
|
|||
RE: Creating digits of pi
There *is* a way of directly calculating the Nth digit of pi (without generating all the previous digits) but only in hex. Nobody to date has discovered a way of doing it for pi in base 10.
<0|ɸ|0> -Joe- |
|||
02-06-2018, 09:24 PM
Post: #3
|
|||
|
|||
RE: Creating digits of pi
(02-06-2018 01:38 AM)Joe Horn Wrote: There *is* a way of directly calculating the Nth digit of pi (without generating all the previous digits) but only in hex. Nobody to date has discovered a way of doing it for pi in base 10. Why not just convert the hex to decimal? Tom L Cui bono? |
|||
02-06-2018, 10:38 PM
Post: #4
|
|||
|
|||
RE: Creating digits of pi
(02-06-2018 09:24 PM)toml_12953 Wrote: Why not just convert the hex to decimal? That's not the easiest thing in the world for an inexperienced user like me. I can certainly convert integers, but converting stuff to the right of the hexadecimal point is quite a bit beyond me; though I do understand it uses powers of two, it uses them in a fractional way, i.e. a^½ (SQR()), a^(¼) (fourth root) and so on. The problem actually goes deeper than this though. Converting a fractional power of 16 is only half the issue, and would still result in multiple decimal digits as a result, not the single digit sequence I was after. Let's consider the second hex digit as an example: \[ \{ 1/256 .. 255/256 \} \notin \{ 1/16 .. 15/16 \} \] 1/256 = 3.90625E-3, 2/256 = 7.8125E-3 … That's six digits and a decimal point, just for the first hex decimal. (Post 169) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
02-07-2018, 10:30 PM
Post: #5
|
|||
|
|||
RE: Creating digits of pi
LOL, this topic makes my brain hurt.
Thanx !!! 2speed HP41CX,int2XMEM+ZEN, HPIL+DEVEL, HPIL+X/IO, I/R, 82143, 82163, 82162 -25,35,45,55,65,67,70,80 |
|||
02-08-2018, 02:59 AM
(This post was last modified: 02-08-2018 03:13 AM by Valentin Albillo.)
Post: #6
|
|||
|
|||
RE: Creating digits of pi
(02-06-2018 01:38 AM)Joe Horn Wrote: There *is* a way of directly calculating the Nth digit of pi (without generating all the previous digits) but only in hex. Nope. It also works for base 2 as well. Quote: Nobody to date has discovered a way of doing it for pi in base 10. It can be proved that there's no formula in base 10 for Pi like the one for bases 16 and 2. There are base-10 formulas for many other constants but not for Pi. See A compendium of BBP-type formulas. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
02-08-2018, 04:22 AM
Post: #7
|
|||
|
|||
RE: Creating digits of pi
(02-07-2018 10:30 PM)TASP Wrote: LOL, this topic makes my brain hurt. And I thought I had it tough! I had to google for the set theory symbols for "not in a set", I haven't done this sort of thing since 1984! So far, the only way I've found to partially solve my problem is: generate all N digits of pi with PI50G from 3.14...., keeping the last x digits. I think that's the only feasible way to do it, and is infeasible after a certain number of N, at least on a 50G. It would be larger for calculators with more storage such as the Prime—assuming a PI50G equivalent on that platform, but would still eventually run into problems. (Post 171) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
02-08-2018, 01:02 PM
Post: #8
|
|||
|
|||
RE: Creating digits of pi
(02-08-2018 02:59 AM)Valentin Albillo Wrote:(02-06-2018 01:38 AM)Joe Horn Wrote: There *is* a way of directly calculating the Nth digit of pi (without generating all the previous digits) but only in hex. So what good is it in base 16? What use does it have? Can you calculate areas or volumes with it? Tom L Cui bono? |
|||
02-08-2018, 03:50 PM
Post: #9
|
|||
|
|||
RE: Creating digits of pi
(02-08-2018 03:39 PM)Mike (Stgt) Wrote:(02-08-2018 01:02 PM)toml_12953 Wrote: So what good is it in base 16? What use does it have? Can you calculate areas or volumes with it? Fun? I just don't see fun in calculating something useless. Of course I'm an engineer, not a mathematician so anything theoretical has little or no interest for me. Tom L Cui bono? |
|||
02-08-2018, 07:33 PM
Post: #10
|
|||
|
|||
RE: Creating digits of pi
(02-08-2018 06:58 PM)Mike (Stgt) Wrote: Fun is something emotional, and emotions are known to lower the IQ fast and considerable to 50 or so. Strange enough, as for humans the drive to understand something is stronger than sex drive, it is said. So the mainly motivation for many scientists could be just the joy of "now I know", quite possible that an engineer is trained diversely, think and think different nothing but slogans, fun at work something useless. With hindsight worthles 'trouble and sorrow'. Now when I see one of my circuits in a spacecraft perform perfectly, I do find that fun so I'm not criticizing how anyone finds fun but just saying that for me, calculating for it's own sake isn't fun. À chacun ses goûts! Tom L Cui bono? |
|||
02-08-2018, 09:25 PM
Post: #11
|
|||
|
|||
RE: Creating digits of pi
(02-08-2018 03:50 PM)toml_12953 Wrote: Of course I'm an engineer, not a mathematician so anything theoretical has little or no interest for me.I have no intention to be polemic, anyway the above sentence sounds to me like "I'm a driver I don't need to know how the engine in my car or drivetrain in my bike works." And while that is completely legit, knowing the tools that one uses a bit better is nothing bad, rather it should improve the results at the end. Wikis are great, Contribute :) |
|||
02-08-2018, 11:48 PM
(This post was last modified: 02-08-2018 11:49 PM by Gerson W. Barbosa.)
Post: #12
|
|||
|
|||
RE: Creating digits of pi
(02-08-2018 12:26 PM)Mike (Stgt) Wrote:(02-08-2018 04:22 AM)brickviking Wrote: ... on that platform, but would still eventually run into problems. Madhava-Leibniz is interesting, especially because it's from the XIVth century. And yet we can use it on the HP-50g to compute 500 digits, if we are not in a hurry: 500 « PUSH RAD -105 CF -3 CF DUP .653 * 1.74 + IP R->I DUP 2 MOD + DUP 4 * OVER DUPDUP 1 - 1 FOR i i SQ SWAP / PICK3 + ROT SWAP -1 STEP INV NIP UNROT + 1 - 3 0 UNROT FOR i i INV i 2 - INV - + -4 STEP - 4 * EXPAND FXND DUP SIZE R->I ALOG OVER - PICK3 * SWAP IQUOT + ->STR DUP HEAD -51 FC? { "." } { "," } IFTE + SWAP TAIL + 1 ROT 2 + SUB POP » TEVAL --> 2: "3. 1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 8214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196 4428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273 7245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094 3305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912" 1: s:21533.1807 21533 seconds on my HP-50g (almost 6 hours!) This is much longer than it should be, as I am using no external long-float library (only the built-in Long Int in UserRPL). By using an arbitrary precision library, the running time might be significantly decreased. Quoting from the Wikipedia article on Madhava of Sangamagrama: Quote:This text attributes most of the expansions to Madhava, and gives the following infinite series expansion of π, now known as the Madhava-Leibniz series: Perhaps that Wikipedia article should be updated. The next correction terms are Rn = (4n^3 + 13n)/(16n^4 + 56n^2 +9), Rn = (4n^4 + 29n^2 + 16)/(16n^5 + 120n^3 + 89n) and Rn = (16n^5 + 216n^3 + 389n)/(64n^6 + 880n^4 + 1756n^2 + 225) Madhava's correction terms are simply the first three approximants to the continued fraction in the following expression, from an old thread: \[\frac{\pi }{4}= 1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\cdots +\frac{1}{2n-3}-\frac{1}{2n-1}+\frac{1}{4n+\frac{1^{2}}{n+\frac{2^{2}}{4n+\frac{3^{2}}{n+\frac{4^{2}}{4n+... }}}}}\] From observation, 2*d/3 terms of the series and the corresponding correction term (or the evaluation of the same number of terms of the continued fraction) are necessary to obtain d correct decimal places of π. |
|||
02-09-2018, 02:42 AM
Post: #13
|
|||
|
|||
RE: Creating digits of pi
(02-09-2018 02:01 AM)Mike (Stgt) Wrote:(02-08-2018 11:48 PM)Gerson W. Barbosa Wrote: Madhava-Leibniz is interesting, [...] You're still limited to the precision of a variable (Pi), right? How would you go beyond 12 or 13 digits? If you can't, why go to all that trouble to get a number you can get with a single command. That's not a rhetorical question, I'd really like to know. Tom L Cui bono? |
|||
02-09-2018, 12:43 PM
Post: #14
|
|||
|
|||
RE: Creating digits of pi
(02-09-2018 12:08 PM)Mike (Stgt) Wrote:(02-09-2018 02:42 AM)toml_12953 Wrote: You're still limited to the precision of a variable (Pi), right? How would you go beyond 12 or 13 digits? Ah! That explains it. Please excuse my obtuseness. Tom L Cui bono? |
|||
02-09-2018, 12:54 PM
(This post was last modified: 02-09-2018 01:13 PM by toml_12953.)
Post: #15
|
|||
|
|||
RE: Creating digits of pi
(02-09-2018 12:08 PM)Mike (Stgt) Wrote:(02-09-2018 02:42 AM)toml_12953 Wrote: You're still limited to the precision of a variable (Pi), right? How would you go beyond 12 or 13 digits? Here's a version in Decimal BASIC interpreter that returns 1000 digits before you can remove your finger from the Enter key on a 4.2 GHz Core i7: (PI is a reserved word in Decimal BASIC) Wait a second. That was fun. I didn't just have fun did I? No, not me. I refuse to have fun. Code: OPTION ARITHMETIC DECIMAL_HIGH ! 1000 digits precision Tom L Cui bono? |
|||
02-09-2018, 01:40 PM
Post: #16
|
|||
|
|||
RE: Creating digits of pi
(02-09-2018 12:54 PM)toml_12953 Wrote:(02-09-2018 12:08 PM)Mike (Stgt) Wrote: Sorry, I did not mention that you should take it as pseudocode only. Well, it is REXX what I boiled down to the essential loop. So a 'minor' detail went up in smoke: Or the equivalent in bc: Code: scale = 1000 Greetings, Massimo -+×÷ ↔ left is right and right is wrong |
|||
02-09-2018, 02:59 PM
(This post was last modified: 02-09-2018 02:59 PM by pier4r.)
Post: #17
|
|||
|
|||
RE: Creating digits of pi
wait a moment. REXX for the little that I know should have been designed as a sort of bash (or vbscript & co). How come that it has such a library for arbitrary precision? Or did you add a library yourself?
Edit: nice the equivalent in bc. This let me remember to ask something in another thread. Wikis are great, Contribute :) |
|||
02-09-2018, 03:35 PM
Post: #18
|
|||
|
|||
RE: Creating digits of pi
(02-09-2018 02:03 PM)Mike (Stgt) Wrote:(02-09-2018 12:54 PM)toml_12953 Wrote:And OPTION ARITHMETIC DECIMAL_double_HIGH will get you the next 1000 decimals? With REXX the decimals setting is only limited by available storage. No, Decimal BASIC only has up to 1000 digits. Not bad considering most versions of BASIC only have single precision (about 7 digits) or double precision (about 16 digits) Tom L Cui bono? |
|||
02-09-2018, 07:27 PM
(This post was last modified: 02-10-2018 01:33 AM by Gerson W. Barbosa.)
Post: #19
|
|||
|
|||
RE: Creating digits of pi
(02-09-2018 12:54 PM)toml_12953 Wrote: Here's a version in Decimal BASIC interpreter that returns 1000 digits before you can remove your finger from the Enter key on a 4.2 GHz Core i7: Perhaps a little more fun here, having written my own code using my own algorithm. Well, actually Madhava's since it was probably known to him, given his exact correction terms. Three digits per iteration, but noticeably slower. Code:
\[\frac{\pi }{4}= 1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\cdots +\frac{1}{2n-3}-\frac{1}{2n-1}+\frac{1}{4n+\frac{1^{2}}{n+\frac{2^{2}}{4n+\frac{3^{2}}{n+\frac{4^{2}}{4n+... }}}}}\] Edited to improve code (removed 2 multiplications out of the loop), but I am not familiar with this BASIC to try other optimizations. Edited again to include a somewhat more optimized code: Code:
334 iterations (but 327 would have sufficed for 1000 decimal places), 342 ms (average of 5 runs). Still slower than Tom's version (243 ms here, Intel E4700 @ 2.6 GHz), but about 130 % faster when compared to my previous version above). |
|||
02-09-2018, 08:03 PM
Post: #20
|
|||
|
|||
RE: Creating digits of pi
(02-09-2018 02:01 AM)Mike (Stgt) Wrote: BTW, instead of tantalizing your real machine for 6 hrs, I suggest a well known emulator of it. Recently I set it to authentic speed for some reason, and I am so glad I can switch it back to full speed. Could help in this case too. I certainly tried it on Debug4x first (Emu-50g @ 2.6 GHz, 555.7218 seconds). I had estimated it would take 5 or 6 hours on the real 50g, but I wanted to get the exact factor as I was not so sure about that. Regards, Gerson. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)