MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

NFactorial[n_], fast for large (n).




If (num) is a large integer   N[ num! ]   computes the exact value of 
(num!),
and then converts it to a less precise value.  This can take a
relatively  long time (see below).

In[1]:=
N[12000!];//Timing

Out[1]=
{10.16 Second,Null}

But  (n!) == Gamma[n+1]
So I define a function  NFactorial[n_Integer]

In[2]:=
NFactorial[n_Integer]:=Gamma[n+1.0]

NFactorial[12000]  is computed in an instant!

In[3]:=
NFactorial[12000];//Timing

Out[3]=
{0. Second,Null}

I wanted to assign the rule to  N[Factorial[n_Integer]] but I understand
I would have to give N a Hold attribute to do that. I worry there will
be a down side to making N hold it's argument.

You can also make fast machine precision implementations of other
functions  such as:
Binomial, Fibonacci, BernoulliB, EulerE, StirlingS1, ....

The Handbook of Mathematica Functions, by  Abramowitz M., Stegun I. A.
is a good source for the needed identities.  However, Abramowitz,
Stegun  neglect to discuss Fibonacci numbers!

For Fibonacci numbers use the following elegant expression:
Fibonacci[n_]:=(GoldenRatio^n - (-GoldenRatio)^(-n))/Sqrt[5]


Ted Ersek




  • Prev by Date: Re: graphics question
  • Next by Date: red-green stereograms
  • Prev by thread: Re: A Bug / Feature
  • Next by thread: Re: NFactorial[n_], fast for large (n).