(DM42) Gamma function for complex values
04-10-2023, 03:52 PM
Post: #3
 Gjermund Skailand Member Posts: 78 Joined: Dec 2013
RE: (DM42) Gamma function for complex values
Minor update, correct files attachef

Gamma function for complex values s = x +iy for DM42, Free42
Motivation: The GAMMA function only accept real values.
Uses Bernoulli coefficients, requires the program B2n, see earlier post for details.
and reflection formula for x< 0.5
Accurate to 30 digits, (32 for "small" imaginary values).

Requires the function B2n, included below.

Alternatively , for speed increase, temporarily insert a STOP at line 52,
run with e.g (1 i1) then do a manual STO "B34",
remove the STOP and change line 52 XEQ "B2N" to 52 RCL "B34"
If somewhat reduced accuracy , say 16 digis, change line 41 from 34 to 18
raw file included

With USB power calculation time is approx 0.16s (0.08s with precomputed table)

Compare accuracy with e.g. gamma function at http://www.wolframalpha.com
DM42: 0.5 i0.5 gamma -->
0.8181639995417473940777488735553224 - 0.7633138287139826166702967877608994 i

WolframAlpha: gamma(0.5 + i*0.5)
0.8181639995417473940777488735553249 - 0.7633138287139826166702967877609006 i

2023-04-10 skai
Code:
 00 { 197-Byte Prgm } 01▸LBL "Gamma" 02 FUNC 11 03 L4STK 04 REAL? 05 0 06 CPX? 07 COMPLEX 08 X≠0? 09 GTO 00 10 R↓ 11 GAMMA 12 RTN 13▸LBL 00 14 RAD 15 X<>Y 16 LASTX 17 4 18 1 19 NEWMAT 20 ENTER 21 RCOMPLX 22 LSTO "REGS" 23 R↓ 24 STO 00 25 X<>Y 26 0.5 27 X≤Y? 28 GTO 01     29 CLX 30 PI 31 1 32 R↑ 33 - 34 STO 00 35 PI 36 × 37 SIN 38 ÷ 39▸LBL 01        40 LSTO "r" 41 34          @ must be integer 4n+2, 34 seems to be optimum 42 LSTO "N" 43 ENTER 44 RCL+ 00 45 STO 01 46 STO 03 47 X↑2 48 STO 02 49 X<>Y 50 2 51 ÷ 52 XEQ "B2n"   @ alternatively RCL "B34"  53 EDIT 54 CLST 55▸LBL 02      56 ISG ST Y 57 NOP 58 RCLEL 59 RCL ST Z 60 STO+ ST X 61 DSE ST X 62 RCL× ST T 63 STO+ ST X 64 RCL× 03 65 ÷ 66 + 67 RCL 02 68 STO× 03 69 R↓ 70 J+ 71 FC? 77 72 GTO 02     73 RCLEL 74 EXITALL 75 R↓ 76 E↑X 77 RCL× 03 78 RCL÷ 01 79 RCL 00 80 RCL "N" 81 DSE ST X 82 RCL ST Z 83▸LBL 03        84 RCL ST Y 85 RCL+ ST T 86 ÷ 87 DSE ST Y 88 GTO 03       89 RCL÷ ST Z 90 RCL 01 91 +/- 92 E↑X 93 × 94 RCL 01 95 RCL 00 96 0.5 97 - 98 Y↑X 99 × 100 PI 101 STO+ ST X 102 SQRT 103 × 104 RCL "r" 105 STO ST Z 106 CPX? 107 CLX 108 R↓ 109 0=? ST T 110 ÷ 111 END 00 { 121-Byte Prgm } 01▸LBL "Tn"  @  optimalizations by Werner H included   02▸LBL 10 03 1 04 NEWMAT 05 EDIT 06 LASTX 07▸LBL 02 08 STOEL 09 ISG ST Y 10 X<>Y 11 RCL× ST Y 12 I+ 13 FC? 76 14 GTO 02 15 2 16▸LBL 03 17 0 18 RCLEL 19 I+ 20 FS? 76 21 GTO 00 22▸LBL 04 23 X<>Y 24 STO× ST Y 25 2 26 + 27 X<>Y 28 RCLEL 29 RCL× ST Z 30 + 31 STOEL 32 DSE ST Y 33 I+ 34 FC? 76 35 GTO 04 36 R↑ 37 1 38 STOIJ 39 + 40 GTO 03 41▸LBL "B2n" 42 XEQ 10 43 EDIT 44 CLX 45▸LBL 05 46 +/- 47 ENTER 48 SIGN 49 STO+ ST X 50 + 51 RCLEL 52 2 53 RCL ST Z 54 ABS 55 Y↑X 56 X↑2 57 LASTX 58 - 59 ÷ 60 × 61 STOEL 62 R↓ 63 I+ 64 FC? 76 65 GTO 05 66▸LBL 00 67 RCLEL 68 EXITALL 69 END
.raw file included
brgds
Gjermund

Attached File(s)