Post Reply 
Zeta Function
01-19-2016, 09:57 PM (This post was last modified: 01-19-2016 09:58 PM by Namir.)
Post: #1
Zeta Function
Here is a program that calculates the Zeta function. The program prompts you for s, the argument for the function, and for the tolerance value (recommend 1e-8). The function places the function's value in the X stack register,

Code:
1    LBL "ZETA"        
2    LBL A        
3    S?        
4    PROMPT        
5    STO 0        
6    TOLER?        
7    PROMPT        
8    STO 07        # store tolerance
9    1        
10    STO 04        # n=1
11    STO 08        # n! = 1
12    2        
13    /        
14    STO 01        # OutSum = 1/2
15    LBL 00        #--------------------------- start of outer loop 
16    RCL 04        # View n
17    PSE        
18    STO 11        # I = n
19    STO* 08        # update n!
20    RCL 08        
21    STO 10        # init (n-k)!
22    1        
23    STO 03        # k = 1
24    STO 09        # k! =1
25    STO 02        # InSum = 1
26    STO 06        # CHS=1
27    LBL 01        # --------------------------- start of inner loop
28    -1        
29    STO* 06        # CHS=-CHS
30    RCL 03        
31    STO* 09        # update k!
32    RCL 11        
33    X=0?        
34    GTO 02        
35    STO/ 10        # update (n-k)!
36    1        
37    RCL 10        
38    X=0?        
39    +        
40    STO 10        
41    1        
42    STO- 11        # I = I - 1
43    LBL 02        
44    RCL 08        
45    RCL 09        
46    /        
47    RCL 10        
48    /        
49    RCL 06        
50    *        
51    RCL 03        
52    1        
53    +        
54    STO 03        # k = k + 1
55    RCL 00        
56    Y^X        
57    /        
58    STO+ 02        # InSum = InSum + ...
59    RCL 04        
60    RCL 03        
61    X<=Y?        # k<=n?
62    GTO 01        # --------------------------- End of Inner loop
63    RCL 02        
64    2        
65    RCL 04        
66    1        
67    +        
68    STO 04        # n = n + 1
69    +        
70    Y^X        
71    /        
72    STO+ 01        # OutSum = OutSum + Term
73    ABS        
74    RCL 07        
75    X<=Y?        # Tolerance <= Term?
76    GTO 00        # --------------------------- End of Outer loop
77    2        
78    1        
79    RCL 00        
80    -        
81    Y^X        
82    CHS        
83    1        
84    +        # calculate 1 - 2^(1-s)
85    1/X        
86    RCL 01        
87    *        
88    RTN

The memory map for the program is:

Code:
R00 = s
R01 = Outer Sun, Outer Sum
R02 = Inner Sum, Inner Sum
R03 = k
R04 = n
R05 = Term
R06 = CHS
R07 = Toler
R08 = n!
R09 = k!
R10 = (n-k)!
R11 = I

The function uses a fast converging series (see Wikipedia) and can give results for small arguments of s such as Zeta(1.1).

Namir

PS: I am aware that Jean-Marie Baillard has a Zeta function implemented in the HP-41C Software Library. His program is shorter than mine and uses just two registers. However, I tried to calculate Zeta(1.1) using his version and I had to stop after the HP-41CX emulator went on and on and on!
Find all posts by this user
Quote this message in a reply
01-24-2016, 09:25 AM (This post was last modified: 01-24-2016 09:26 AM by Ángel Martin.)
Post: #2
RE: Zeta Function
(01-19-2016 09:57 PM)Namir Wrote:  PS: I am aware that Jean-Marie Baillard has a Zeta function implemented in the HP-41C Software Library. His program is shorter than mine and uses just two registers. However, I tried to calculate Zeta(1.1) using his version and I had to stop after the HP-41CX emulator went on and on and on!

Hi Namir, I guess you must have something wrong in your V41 setup - or a bad transcription of the program code. I just ran the case x=1.1 using ZETAX in the SandMath (which implements Jean-Marc's Borwein algorithm) and it took 13.48 seconds to return the result 10.58444847. I also ran it for x=1.001, which returned 1,000.577289 in approximately the same time. Both examples done at the default speed, i.e. NOT in TURBO mode.

Cheers,
'AM

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
Post Reply 




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