﻿ Vector, the Journal of the British APL Association

## Volumes

British APL Association

Archive articles posted online on request: ask the archivist.

Volume 10, No.2

# An Improvement to LOGGAMMA

(Step by Step Analysis of Variance, Education Vector, July 1993)

In the first place the name of the function is misleading since what LOGGAMMA delivers is log of gamma of half the argument. An excellent approximation for true log gamma can be obtained from Feller’s extension to Stirling’s formula for log factorial, namely

```                                        1     1
ln n! = .5(ln 2n) + (n+.5)(ln n) - n + --- - ---n-3
12n   360
```

(see An Introduction to Probability, William Feller). Here it is in APL:

```  Z←LOGFACT N
  →0 IF 0=Z←N
  Z←((0.5+0,N),÷¯1,12,¯360)+.×(⍟(○2),N),N,÷¨N,N*3
```

A final trivial adjustment must be made to allow for the fact that ⌈(n)=(n-1)!

For the purposes of FTAIL the above routine is an unnecessary refinement. However there are circumstances where it is invaluable, for example in calculating binomial probabilities with large parameter values, or in applying the Fisher Exact Test.

(webpage generated: 8 December 2005, 05:10)

```script began 20:40:19
caching off
debug mode off
cache time 3600 sec
cached index is fresh
recompiling index.xml
index compiled in 0.2979 secs