Dilogarithm & Polylogarithm Functions for the HP-41
Overview
1°) Real Arguments,
| x | < 1
2°) Complex Arguments, | z |
< 1
3°) Complex Arguments, | z |
= 1
1°) Real Arguments, | x | < 1
-This routine computes Li2(x) = - §0x
[ Ln(1-t) ]/t dt = SUMk=1,2,... xk/k2
Data Registers: R00 = k ,
R01 = x
Flags: /
Subroutines: /
01 LBL "LI2"
02 STO 01 03 CLX 04 STO 00 05 SIGN 06 LASTX 07 ENTER^ 08 LBL 01 09 X<> Z 10 RCL 01 11 * 12 STO Z 13 ISG 00 14 CLX 15 RCL 00 16 X^2 17 / 18 X<>Y 19 ST+ Y 20 X#Y? 21 GTO 01 22 END |
( 35 bytes / SIZE 002 )
STACK | INPUT | OUTPUT |
X | x | Li2(x) |
with | x | < 1
Example:
0.7 XEQ "LI2" >>>> Li2(0.7) = 0.889377624 ( in 19 seconds )
Notes:
-Execution time is very long if x is near 1
-In fact, Li2(1) = (PI)2/6 = 1.644934067...
-To compute the polylogarithm Lin(x) =
SUMk=1,2,... xk/kn only
minor modifications are needed:
01 LBL "LIN"
02 STO 01 03 X<>Y 04 STO 02 05 1 06 STO 03 07 CLX 08 STO 00 09 LBL 01 10 RCL 01 11 RCL 03 12 * 13 STO 03 14 ISG 00 15 CLX 16 RCL 00 17 RCL 02 18 Y^X 19 / 20 + 21 X#Y? 22 GTO 01 23 END |
( 33 bytes / SIZE 004 )
STACK | INPUTS | OUTPUTS |
Y | n | Lin(x) |
X | x | Lin(x) |
with | x | < 1
Example:
3 ENTER^
0.7 XEQ "LIN" >>>> Li3(0.7)
= 0.780063934 ( in 30 seconds )
2°) Complex Arguments, | z | < 1
Data Registers: R00 thru R06: temp
Flags: /
Subroutines: /
01 LBL "LI2Z"
02 R-P 03 STO 03 04 RDN 05 STO 04 06 CLX 07 STO 00 08 STO 01 09 STO 02 10 STO 06 |
11 SIGN
12 STO 05 13 LBL 01 14 RCL 04 15 RCL 06 16 + 17 STO 06 18 RCL 03 19 RCL 05 20 * |
21 STO 05
22 ISG 00 23 CLX 24 RCL 00 25 X^2 26 / 27 P-R 28 RCL 01 29 + 30 STO 01 |
31 LASTX
32 - 33 ABS 34 X<>Y 35 RCL 02 36 + 37 STO 02 38 LASTX 39 - 40 ABS |
41 +
42 X#0? 43 GTO 01 44 RCL 02 45 RCL 01 46 END |
( 57 bytes / SIZE 007 )
STACK | INPUTS | OUTPUTS |
Y | y | y' |
X | x | x' |
With Li2(x+i.y) = x' + i.y' ( | x+i.y | < 1 )
Example:
0.3 ENTER^
0.4 XEQ "LI2Z" >>>> 0.407770499
--- Execution time = 36s ---
X<>Y 0.374503158
-So, Li2( 0.4 + 0.3 i ) = 0.407770499 + 0.374503158 i
Notes:
-If you want to compute the polylogarithm Lin(z) = SUMk=1,2,... zk/kn
Replace line 25 by RCL 07 Y^X
add X<>Y STO 07 after line 05
replace line 01 by LBL "LINZ" and place n in Z-register
before executing "LINZ"
-For example,
3 ENTER^
0.3 ENTER^
0.4 XEQ "LINZ" >>>> 0.405995304
--- Execution time = 38s ---
X<>Y 0.334761838
-Thus, Li3( 0.4 + 0.3 i ) = 0.405995304
+ 0.334761838 i
3°) Complex Arguments, | z | = 1
-Due to the execution time, "LI2Z" is not very useful when | z | = 1
-Fortunately, alternative formulas are available for | µ
| < PI where µ = arg(z)
SUMk=1,2,..... cos(k.µ) / k2 = PI2/6 - PI x ABS(µ)/2 + µ2/4
SUMk=1,2,..... sin(k.µ) / k2
= -µ ln | µ | + µ + SUMk=1,2,..... (-1)k-1/(2k+1)!
[B2k/(2k)] µ2k+1 where B2k
are the Bernoulli numbers
01 LBL "DILM1"
02 STO 00 03 X^2 04 ENTER^ 05 STO Z 06 92 E18 07 / 08 1931 E15 09 1/X 10 + 11 * 12 3983 E13 13 1/X 14 + 15 * 16 12462 E-19 17 + |
18 *
19 15 20 FACT 21 12 22 * 23 1/X 24 + 25 * 26 29522 E7 27 1/X 28 + 29 * 30 11 31 FACT 32 132 33 * 34 1/X |
35 +
36 * 37 9 38 FACT 39 240 40 * 41 1/X 42 + 43 * 44 7 45 FACT 46 252 47 * 48 1/X 49 + 50 * 51 5 |
52 FACT
53 X^2 54 1/X 55 + 56 * 57 72 58 1/X 59 + 60 * 61 1 62 + 63 RCL 00 64 ABS 65 X#0? 66 LN 67 - 68 RCL 00 |
69 ST* Y
70 ABS 71 2 72 / 73 X^2 74 LASTX 75 PI 76 * 77 - 78 PI 79 X^2 80 6 81 / 82 + 83 END |
( 135 bytes / SIZE 001 )
STACK | INPUTS | OUTPUTS |
Y | / | y |
X | µ | x |
with Li2(eiµ) = x + i.y | µ | <= PI
Example:
2.41 XEQ "DILM1" gives Li2( e 2.41 i ) = -0.688660081 + 0.490561965 i --- Execution time = 5.7 seconds ---
Notes:
- Li2(1) = (PI)2/6 = 1.644934067...
( for µ = 0 ) & Li2(-1) =
-(PI)2/12 = -0.822467034... ( for µ = PI
)
-The series is truncated to produce a 9 digit accuracy for µ
~ 3.14...
-This routine does not check that | µ | <= 1
-Add for instance PI ST+ X MOD PI
X>Y? CLX ST+ X - after line 01