Riemann's Zeta Function - another approach (RPL)
|
08-07-2017, 08:52 AM
(This post was last modified: 08-08-2017 06:48 PM by Dieter.)
Post: #81
|
|||
|
|||
RE: Riemann's Zeta Function - another approach (RPL)
(08-04-2017 07:26 PM)Dieter Wrote: Edit: here is the current version. It addresses the x~0 problem in a ...err... "creative" way in that the smallest |x| is set to 1E–20. #-) There is a better solution. Since \(\zeta '(0) = -\ln\sqrt{2 \pi}\), for x close to zero \(\zeta(x)\ \approx -(0.5+x\cdot\ln\sqrt{2 \pi})\). So the program may simply switch to this as soon as |x| is sufficiently small. For the given program a good threshold is at 2 E–11. So if |x| is larger than this, use the regular method, and all |x| up to this limit may use the simple formula above. This is what I now have implemented in my Free42 program. Here is the modified listing. The changes are in the first lines before the XEQ 77 call, and the STO 00 after LBL 77 has been omitted. Edit: changed the threshold in line 08 from 1E–11 to 2E–11. Code: 00 { 434-Byte Prgm } And again: please note that this version is intended for high-precision environments like Free42 and may not perform well on a regular 42s. Dieter |
|||
08-08-2017, 04:05 AM
Post: #82
|
|||
|
|||
RE: Riemann's Zeta Function - another approach (RPL)
(08-07-2017 08:52 AM)Dieter Wrote:(08-04-2017 07:26 PM)Dieter Wrote: Edit: here is the current version. It addresses the x~0 problem in a ...err... "creative" way in that the smallest |x| is set to 1E–20. #-) Very nice! I would only make a minor modification. Not that one less square root evaluation really might make a difference in execution time in Free42: Code:
Gerson. |
|||
08-08-2017, 06:46 PM
(This post was last modified: 08-08-2017 06:58 PM by Dieter.)
Post: #83
|
|||
|
|||
RE: Riemann's Zeta Function - another approach (RPL)
(08-08-2017 04:05 AM)Gerson W. Barbosa Wrote: Very nice! Wait, it even gets a tiny bit nicer. ;-) (08-08-2017 04:05 AM)Gerson W. Barbosa Wrote: I would only make a minor modification. Not that one less square root evaluation really might make a difference in execution time in Free42: Ah, great. It's not beause of the sqrt, but I love this elegant stack content reuse of the 0.5 that still sits in T. ;-) But there even is one more tweak. The second term of the Zeta Taylor series is quite exactly –x², i.e. \(\zeta(x)\ \approx -(0.5+x^2+x\cdot\ln\sqrt{2 \pi})\). And this can be implemented with just one more step: Code: … This way the threshold in line 08 should be somewhere near 1 E–8. The perfect value differs slightly for negative resp. positive x, but 8 E–9 works very nicely for both. BTW, if you want to stick to the original implementation the perfect switchpoint seems to be close to 2 E–11, so this value should be used there. I edited my original post accordingly. But we're talking about differences beyond the 20th digit here. ;-) Dieter |
|||
08-12-2017, 07:03 PM
Post: #84
|
|||
|
|||
RE: Riemann's Zeta Function - another approach (RPL)
(08-04-2017 07:26 PM)Dieter Wrote: [quote='Gerson W. Barbosa' pid='76831' dateline='1501861065'] Just for the record, here is the new HP-41 listing with your suggestions: Code:
The primitive Gamma implementation I've been using is slightly faster: Code:
And here is the new table: 41 XEQ ZETA --> 1.000000000 ( 8.24 s) 25 R/S --> 1.000000030 ( 8.28 s) 3 R/S --> 1.202056903 (17.89 s) 2.001 R/S --> 1.643997513 (2) (22.33 s) 2 R/S --> 1.644934067 ( 4.04 s) 1.5 R/S --> 2.612375349 ( 4.08 s) 0.5 R/S --> -1.460354509 ( 4.74 s) 0 R/S --> -0.500000000 ( 4.03 s) -0.5 R/S --> -0.2078862450 (250) ( 9.72 s) -1 R/S --> -0.08333333384 (33) (10.07 s) -1.001 R/S --> -0.08316803696 (723) (28.32 s) -1.5 R/S --> -0.02548520436 (190) (25.38 s) -2 R/S --> 0.00000000000 (24.84 s) -3 R/S --> 0.008333333384 (33) (22.09 s) -5 R/S --> -0.003968253990 (68) (20.24 s) -7 R/S --> 0.004166666686 (67) (19.39 s) -15.16 R/S --> 0.4964873534 (85) (18.99 s) -33.34 R/S --> -1.924684098E10 (152) (22.15 s) -41.42 R/S --> -3.506595602E16 (584) (24.03 s) -48.49 R/S --> -3.653091058E22 (22) (25.98 s) -58.59 R/S --> 1.136304829E32 (792) (28.54 s) -67.97 R/S --> 1.832460467E40 (1182) (31.02 s) Times obtained from the HP-41CX built-in stopwatch |
|||
05-08-2020, 04:41 PM
(This post was last modified: 05-17-2020 01:53 PM by Gerson W. Barbosa.)
Post: #85
|
|||
|
|||
RE: Riemann's Zeta Function - another approach (RPL)
Same as before, except for the shorter (90 bytes, the other verstion was 191 bytes long and a bit inaccurate near zero) and more accurate Gamma funcion.
To Dieter, who surely would improve this "improved" Gamma program as he did to Zeta, were he still among us. This nice Zeta implementation is mostly his accomplishment. HP-41CV/CX ζ(x) Code:
Γ(x), x ≥ 0 Code:
41 XEQ ZETA --> 1.000000000 ( 8.3 s) 25 R/S --> 1.000000030 ( 8.3 s) 3 R/S --> 1.202056903 (17.5 s) 2.001 R/S --> 1.643997513 (2) (21.7 s) 2 R/S --> 1.644934067 ( 5.0 s) 1.5 R/S --> 2.612375349 ( 4.3 s) 0.5 R/S --> -1.460354509 ( 4.3 s) 0 R/S --> -0.500000000 ( 4.3 s) -0.5 R/S --> -0.2078862256 (0) (10.3 s) -1 R/S --> -0.08333333344 (33) ( 9.8 s) -1.001 R/S --> -0.08316803746 (46) (27.4 s) -1.5 R/S --> -0.02548520190 (24.6 s) -2 R/S --> 0.00000000000 (23.0 s) -3 R/S --> 0.008333333350 (33) (20.9 s) -5 R/S --> -0.003968253966 (8) (17.7 s) -7 R/S --> 0.004166666668 (7) (16.4 s) -15.16 R/S --> 0.4964873582 (2) (14.5 s) -33.34 R/S --> -1.924684152E10 (13.1 s) -41.42 R/S --> -3.506595630E16 (584) (13.1 s) -48.49 R/S --> -3.653091072E22 (22) (13.2 s) -58.59 R/S --> 1.136304789E32 (92) (13.2 s) -67.97 R/S --> 1.832461183E40 (2) (13.3 s) Times on my HP-41CV ———— P.S.: For a full-range Γ(x+1) implementation please refer to Γ(x+1) [HP-41C]. ———— |
|||
05-08-2020, 04:47 PM
Post: #86
|
|||
|
|||
RE: Riemann's Zeta Function - another approach (RPL)
(05-08-2020 04:41 PM)Gerson W. Barbosa Wrote: ...To Dieter, who surely would improve this "improved" Gamma program as he did to Zeta, were he still among us. This nice Zeta implementation is mostly his accomplishment. Nice callout Gerson. I think of Dieter every time I see a post of someone improve and shorten their own code... I guess he knows all the tricks now... --Bob Prosperi |
|||
05-09-2020, 12:11 AM
Post: #87
|
|||
|
|||
RE: Riemann's Zeta Function - another approach (RPL)
Agreed, a nice eulogy. I miss Dieter's insightful and erudite input.
Pauli |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 16 Guest(s)