Post Reply 
Riemann's Zeta Function - another approach (RPL)
08-04-2017, 03:37 PM
Post: #77
RE: Riemann's Zeta Function - another approach (RPL)
(08-02-2017 11:19 AM)Dieter Wrote:  
(08-01-2017 04:54 PM)Gerson W. Barbosa Wrote:  I remember I had to hard-code Zeta(0) = -1/2 here (line 116).

The problem is any x sufficiently close to zero as 1–x may round to 1. This also seems to be a problem on the WP34s, cf. my post in the other forum. Here the polynomial approximation that goes down to x=0 has an advantage.

It appears the problem has been fixed on the WP34S. Without your testings, probably it would remain unnoticed for a long time.

Back to the HP-41:

Code:


 01▸LBL "ZETA"
 02 X>0?
 03 GTO 00
 04 X=0?
 05 GTO 00
 06 CHS
 07 1
 08 +
 09 STO 02
 10 XEQ "GAMMA"
 11 STO 03
 12 RCL 02
 13 XEQ 00
 14 RCL 03
 15 *
 16 PI
 17 ST+ X
 18 RCL 02
 19 Y^X
 20 /
 21 1
 22 ASIN
 23 RCL 02
 24 *
 25 COS
 26 *
 27 ST+ X
 28 GTO 99
 29▸LBL 00
 30 STO 00
 31 -1
 32 +
 33 1/X
 34 LASTX
 35 X<0?
 36 GTO 97
 37 2
 38 RCL 00
 39 X>Y?
 40 GTO 96
 41 LASTX
 42 LASTX
 43 LASTX
 44 -1.276E -8
 45 *
 46 7.05133E -6
 47 -
 48 *
 49 9.721157E -5
 50 +
 51 *
 52 3.4243368E -4
 53 -
 54 *
 55 4.84515482E -3
 56 -
 57 *
 58 7.281584288E -2
 59 +
 60 *
 61 7.21566498E -3
 62 +
 63 GTO 98
 64▸LBL 96
 65 24
 66 RCL 00
 67 /
 68 2
 69 +
 70 INT
 71 ST+ X
 72 22
 73 X>Y?
 74 X<>Y
 75 STO 01
 76 RCL 00
 77 CHS
 78 STO 00
 79 CLX
 80▸LBL 01
 81 RCL Y
 82 RCL 00
 83 Y^X
 84 -
 85 CHS
 86 DSE Y
 87 GTO 01
 88 RCL 00
 89 ST+ X
 90 1
 91 -
 92 RCL 01
 93 X^2
 94 24
 95 *
 96 /
 97 1
 98 RCL 00
 99 -
100 8
101 /
102 RCL 01
103 /
104 +
105 .5
106 +
107 RCL 01
108 +
109 RCL 00
110 Y^X
111 2
112 /
113 +
114 1
115 RCL 00
116 +
117 2
118 LN
119 *
120 E^X-1
121 CHS
122 /
123 GTO 99
124▸LBL 97
125 ENTER^
126 ENTER^
127 ENTER^
128 -8.4715E -7
129 *
130 7.51334E -6
131 -
132 *
133 9.609657E -5
134 +
135 *
136 3.42683396E -4
137 -
138 *
139 4.84527616E -3
140 -
141 *
142 7.281583446E -2
143 +
144 *
145 7.215664464E -3
146 +
147▸LBL 98
148 RDN
149 1/X
150 INT
151 ST* Z
152 SIGN
153 STO/ X
154 STO- Z
155 X<> L
156 RDN
157 /
158 -
159 R^
160 .57
161 +
162 +
163▸LBL 99
164 END

Code:

 01▸LBL "GAMMA"
 02 -1
 03 X<>Y
 04 +
 05 1
 06 STO 00
 07 X>Y?
 08 GTO 01
 09 ST- L
 10 LASTX
 11 STO 00
 12 INT
 13 1
 14▸LBL 00
 15 RCL 00
 16 *
 17 1
 18 ST- 00
 19 RDN
 20 DSE Y
 21 GTO 00
 22 STO 00
 23▸LBL 01
 24 LASTX
 25 ENTER^
 26 ENTER^
 27 ENTER^
 28 1.604589926 E-2
 29 *
 30 2.641400819 E-1
 31 -
 32 *
 33 1.96580515
 34 +
 35 *
 36 8.729327662
 37 -
 38 *
 39 25.69590147
 40 +
 41 *
 42 52.63472435
 43 -
 44 *
 45 76.53826433
 46 +
 47 *
 48 78.92639573
 49 -
 50 *
 51 56.50761084
 52 +
 53 *
 54 26.37243835
 55 -
 56 *
 57 7.203398486
 58 +
 59 RCL 00
 60 *
 61 END

ZETA, from line 29 on, is essentially your code. GAMMA uses a 10th degree polynomial approximation for the interval [1..2] and simple multiplications for x > 2, but a higher order polynomial might be necessary for 10-digit accuracy. Anyway, it can be replaced with better GAMMA implementations. Still, the ideal 30-second limit is surpassed only for large negative arguments, close to the end of the valid range:

  3 XEQ ZETA  -->   1.202056903           (15.6 s)
  2.001 R/S   -->   1.643997513       (2) (17.0 s)
  2     R/S   -->   1.644934067           ( 4.5 s)
  1.5   R/S   -->   2.612375349           ( 4.5 s)
  0.5   R/S   -->  -1.460354509           ( 5.1 s)
  0     R/S   -->  -0.500000000           ( 4.6 s)
 -0.5   R/S   -->  -0.2078862450    (250) (12.8 s)
 -1     R/S   -->  -0.08333333384    (33) (11.6 s)
 -1.001 R/S   -->  -0.08316803696   (723) (24.3 s)
 -1.5   R/S   -->  -0.02548520436   (190) (24.0 s)
 -2     R/S   -->   0.00000000000         (23.6 s)
 -3     R/S   -->   0.008333333384   (33) (20.7 s)
 -5     R/S   -->  -0.003968253990   (68) (19.3 s)
 -7     R/S   -->   0.004166666686   (67) (18.4 s)
-15.16  R/S   -->   0.4964873534     (85) (18.5 s)
-33.34  R/S   -->  -1.924684098E10  (152) (21.9 s)
-41.42  R/S   -->  -3.506595602E16  (584) (24.1 s)
-48.49  R/S   -->  -3.653091058E22   (22) (26.2 s)
-58.59  R/S   -->   1.136304829E32  (792) (29.0 s)
-67.97  R/S   -->   1.832460467E40 (1182) (31.4 s)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Riemann's Zeta Function - another approach (RPL) - Gerson W. Barbosa - 08-04-2017 03:37 PM



User(s) browsing this thread: 2 Guest(s)