```Date: Oct 25, 2001 1:30 AM
Author: David W. Cantrell
Subject: Inverse gamma function

An approximation of the inverse of the gamma function is presented.The approximation is sufficiently accurate that it allows the inverseof the (discrete) factorial function to be expressed precisely.This article is in response to my own previous inquiry (copied at the end),to which there were no responses, regarding the inverse of the gammafunction.Let k denote the positive zero of the digamma function, approximately1.461632 . For x >= k, Gamma(x) is strictly increasing. Thus, restrictingits domain accordingly, the inverse is a function. Perhaps this should becalled the principal branch of the inverse of gamma. It is certainly themost interesting, and obtaining a good asymptotic approximation for itwill be our main concern. We will eventually comment on the otherbranches; until then, it should be assumed that we are dealing withGamma(x) for x >= k and its inverse.Near the end of my recent sci.math article "23 kt. asymptotic expansionfor gamma function", I presented a nice approximation for the gammafunction:  Sqrt(2*pi)*((x-1/2)/e)^(x-1/2) - cwhere c = Sqrt(2*pi)/e - Gamma(k), approximately 0.036534 .This approximation of gamma is precisely invertible in terms of a wellstudied function; presumably, such cannot be said for the well knowapproximation Sqrt(2*pi/x)*(x/e)^x. The principal branch of the LambertW function will be used. [Those unfamiliar with this function may consultfor details if necessary. Briefly, it is the inverse of the functionx*e^x.] Letting L(x) = ln((x+c)/Sqrt(2*pi)), the inverse of my gammaapproximation is  ApproxInvGamma or AIG(x) = L(x) / W(L(x) / e) + 1/2.For large x, this gives a good approximation of the inverse of the gammafunction. In the table below, I have chosen x = Gamma(N) = (N-1)! forvarious integer N purely for convenience, so that precise inverses areimmediately obvious.N       AIG((N-1)!)    Rel. error2         2.02           0.015         4.995         -0.00110        9.998         -0.000220       19.9993        -0.00004At the endpoint of the domain, we have AIG(Gamma(k)) = 1.50063,giving the approximation's worst |relative error| = 0.02668 . It shouldalso be noted that the approximation's error itself, not just relativeerror, approaches 0 as x increases without bound. [Needless to say, sucha strong statement cannot be made about the error in the approximationused here for the gamma function itself!]A precise inverse for the factorial function N! for positive integer N cannow be given by simply rounding to the nearest integer (since errors aresufficiently small -- less than 1/2 being all that was required):  InvFact(x) = Round(AIG(x)) - 1   for x = N!As an example,  InvFact(24) = Round(AIG(24)) - 1 = Round(4.995) - 1 = 5 - 1 = 4.Asymptotic approximations for branches of the inverse of gamma otherthan the principal branch will now be considered briefly. For nonpositiveintegers n, let k_n denote the smallest zero of the digamma functiongreater than n. Then, for negative n, considering that Gamma(x) restrictedto [ k_n, k_(n+1) ] is one-to-one, it has an inverse function, which wewill call the n branch of the inverse of gamma; also, noting that k_0 = k,we separately define the 0 branch to be the previously discussed principalbranch. (Apologies if my numbering of branches contravenes some wellestablished system of which I am unaware!)Nice _algebraic_ asymptotic approximations can be obtained fairlyeasily for all nonprincipal branches. (For all nonpositive n, the gammafunction has a simple pole at n.) For example, for the -1 branch, thefunction 1/(g+x), where g is the Euler gamma constant (approximately0.577216), works well when |x| is large. x    InvGamma_(-1)(x)  1/(g+x)     error   |relative error|-100     -0.010059     -0.010058   0.000001     0.0001-10      -0.1075       -0.1061     0.0014       0.013 1        1             0.634     -0.366        0.366 10       0.0953        0.0945    -0.0008       0.008 100      0.009944      0.009943  -0.000001     0.0001The middle entry was included to show that such a simple approximation,not surprisingly, performs poorly near an endpoint of the domain.Algebraic approximations, involving square or cube roots, which performfar better near endpoints of the domain, as well as asymptotically, canalso be derived fairly easily.For all other branches, the simplest nice asymptotic approximations arerational functions having both numerator and denominator of degree 1. Asexamples: For the -2 branch, we have the approximation (2-g+x)/(g-1-x),and for the -3 branch, 4(g-2+2x)/(3-2g-4x).Finally, as almost just a curiosity:Previously, for the Lambert W function, we used only its principal branch.However, if its other real branch is also used when obtaining the inverseof my gamma approximation, then AIG(x) = L(x) / W(L(x) / e) + 1/2 becomesbivalued close to the endpoint of its domain, now approximating part of the-1 branch of the inverse of gamma, as well as all of its principal branch.Although the approximation of that part of the -1 branch is poor, it issufficiently accurate so that InvFact(x) = Round(AIG(x)) - 1 now gives theprecise inverse relation of N! for integer N >= 0, with bivalued InvFact(1)being 0 or 1.Comments are welcome.    David W. CantrellDavid W. Cantrell <DWCantrell@sigmaxi.org> wrote:> Anonymous <anonymous@anonymous.anonymous> wrote:> > "Jeremy Price" <drjeremyphd@spam.home.com> wrote in message> > news://Az6x7.103487\$QK.59321764@news1.sttln1.wa.home.com...> > > Yes, that was suppose to be the gamma function.> > > How do you find the inverse of it?> >> > Try a sketch of the gamma function, especially also on the -ve axis.> > Should give you some indication on part of the problem.  However, even> > after restricting the domain, I don't think you can find a nice> > expression for the inverse, if that is what you are looking for.>> Related questions seem to occur fairly often in math newsgroups.> In my article at> ,> I give, without proof, a possible inverse for the (discrete) factorial> function N! (for N >=1).>> I would be interested in knowing of results, including approximations,> concerning the inverse of gamma (with its domain restricted so that the> inverse is a function). Surely such an inverse has already been> investigated substantially.>> Regards,>   David Cantrell-- -------------------- http://NewsReader.Com/ --------------------                    Usenet Newsgroup Service
```