Faster inverse gamma and factorial for the WP 34S
02-08-2015, 03:34 PM (This post was last modified: 02-08-2015 05:26 PM by Dieter.)
Post: #19
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Faster inverse gamma and factorial for the WP 34S
(02-08-2015 02:07 AM)BarryMead Wrote:  If you combine the source code for the Digamma function with Dieter's Inverse Gamma function, the combined program is longer than Bit's original Inverse Gamma function (in RAM memory steps).

Yes, that's true of course. But you can also include the relevant parts of the current digamma function into the inverse gamma routine. As far as I can tell, only positive arguments occur, and also some overhead in digamma can be removed. The final result may look like this:

Code:
LBL"IGM" STO 00 #pi #086 STO 04 / + CNST 87   // that's sqrt(2*pi) / LN RSD 05    // make sure x>=-1 RCL X #eE / RSD 15    // and x > -1/e Wp / #1/2 + LBL 00 STO 01 Clx STO 02 #008 RCL 01 1/x STO+02 x<> L INC X x<?Y BACK 005 1/x STO 03 x² FILL #020 / #021 1/x - * #001 SDR 001 + * DEC X * #012 / RCL 03 LN - #1/2 RCL*03 - RCL-02 RCL 00 RCL 01 Γ - RCL/L RCL/Y RCL 01 ENTER RCL+Z CNVG? 03 RTN DSZ 04 GTO 00 ERR 20

This version has 69 lines and it runs even faster. Γ-1(0,89) now is returned in 1,6 (SP) resp. 2,3 (DP) seconds.

The code also addresses a problem for arguments that are too close to the Gamma minimum at 0,88560 31944 10888 70027 88159 00582 58873 32... Here the current inverse Gamma implementation throws an error (Lambert's W is undefined for x<–1/e). This is handled by the two RSDs.

Arguments very close to the mentioned Gamma minimum still take longer, but they return a result instead of an error message. That is: they do, except in some extremely close cases. Γ-1(0,88560 31944 10888 70027 88159 1) still works, but accuracy may be limited. Arguments even closer will not converge within reasonable time, so the code is limited to 86 iterations. Otherwise a "No root found" error is generated. In this case X and Y hold the two last approximations and the last adjustment is in Z, so that the user at least gets a result along with a rough impression of its accuracy.

Dieter
 « Next Oldest | Next Newest »