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 »

 Messages In This Thread Faster inverse gamma and factorial for the WP 34S - Bit - 12-04-2014, 06:14 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-03-2015, 05:05 PM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-06-2015, 01:39 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-06-2015, 03:33 AM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-06-2015, 03:57 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-06-2015, 04:16 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-06-2015, 04:38 AM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-06-2015, 05:28 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-06-2015, 06:09 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-06-2015, 07:39 AM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-06-2015, 07:58 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-06-2015, 08:09 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-06-2015, 02:45 PM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-07-2015, 04:57 PM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-07-2015, 07:34 PM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-08-2015, 01:51 AM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-08-2015, 02:07 AM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-08-2015 03:34 PM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-08-2015, 05:04 PM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-08-2015, 05:27 PM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-08-2015, 05:39 PM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-08-2015, 07:10 PM RE: Faster inverse gamma and factorial for the WP 34S - rprosperi - 02-08-2015, 08:56 PM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-08-2015, 09:22 PM RE: Faster inverse gamma and factorial for the WP 34S - rprosperi - 02-08-2015, 09:44 PM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-08-2015, 10:13 PM RE: Faster inverse gamma and factorial for the WP 34S - rprosperi - 02-08-2015, 10:54 PM RE: Faster inverse gamma and factorial for the WP 34S - BarryMead - 02-08-2015, 11:06 PM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-09-2015, 06:50 AM RE: Faster inverse gamma and factorial for the WP 34S - Paul Dale - 02-08-2015, 07:02 AM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-16-2015, 07:07 AM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-16-2015, 05:46 PM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-16-2015, 07:09 PM RE: Faster inverse gamma and factorial for the WP 34S - Bit - 02-16-2015, 07:30 PM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-16-2015, 09:00 PM RE: Faster inverse gamma and factorial for the WP 34S - Paul Dale - 02-16-2015, 08:46 PM RE: Faster inverse gamma and factorial for the WP 34S - Dieter - 02-16-2015, 09:09 PM RE: Faster inverse gamma and factorial for the WP 34S - Paul Dale - 02-16-2015, 09:43 PM

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