Factorial and gamma -- 8 different HP's Message #15 Posted by Karl Schneider on 12 Sept 2002, 2:28 a.m., in response to message #14 by Werner Huysegoms
Thank you, Ellis, for the info and insightful links on this subject.
I believe that Werner is on the mark regarding the algorithms.
On the 34C, 15C, and 32Sii, "x!" is a dual-use key, calculating factorial(x) for non-negative integer-valued x and gamma(x+1) for real x < 69.96 other than negative integers. (The 15C will ignore the imaginary part of complex x). On the 34C and 15C, x! takes much longer to execute for non-integer values of x than for integer-valued x, indicating use of different algorithms -- presumably using looped-multiplication for integer x and some estimating method for non-integer x. I suspect that the same is true of the 32Sii.
On the 42S, the algorithms are separated into the functions "n!" for n < 254 and "gam" for x < 254.12, which allows gamma(x) to be directly executed according to its definition without adjusting the input argument. Surprisingly, "gam" is almost instantaneous -- much faster than "n!" for n and x that are large and roughly equal. However, "gam" will execute (x-1)! instead if x is an integer.
On the 28C and 48G, one can execute factorial(x) or gamma(x+1) by entering x, keying in "FACT", then hitting <EVAL>. x < 253.12 for a *correct* answer (within range of 1E500) and x must not be a negative integer (or else, "infinite result" is the answer).
On the 41C-, however, any value of x other than a non-negative integer will give a "DATA ERROR" message, and I know of no HP Pac ROM that provides the gamma function.
Finally, the 17Bii provides only the n! function.
There you have it -- implementation of factorial and gamma for eight different machines. Who can explain the fast performance of gamma for the 42S?
-- Karl
|