0

I have to calculate factorials of an arbitrarily large integers mod another arbitrarily large integer. i have considered Stirling's Approximation and Ramanujan’s factorial approximation. is it possible to get better estimates?

2 Answers2

1

Writing $$n!\approx\sqrt{\pi}\left(\frac{n}{e}\right)^n\root\LARGE{6}\of{8n^3+4n^2+n+\frac 1 {30}\color{red}{-}x(n)}$$ with $$x(n)=\frac{a_0+a_1n+a_2n^2}{b_0+b_1n+b_2n^2+b_3n^3}$$ the coefficients are $$\left( \begin{array}{cc} a_0 & 12521740840824081\\ a_1 & 132077016740516320 \\ a_2 & 261892615461486240 \\ b_0 &3339455095907419720 \\ b_1 & 7902477164268212400 \\ b_2 & 5812898776788230400 \end{array} \right)$$ A few values $$\left( \begin{array}{ccc} n & \text{approximation} & \text{exact} \\ 10 & 3628800 & 3628800 \\ 15 & 1307674368000 & 1307674368000 \\ 20 & 2432902008176639896 & 2432902008176640000 \\ 25 & 15511210043330985910414618 & 15511210043330985984000000 \\ 30 & 265252859812191058429178640362769 & 265252859812191058636308480000000 \end{array} \right)$$

Edit

Using ratios of polyomials (as done in this answer and the previous one) leads to incredibly huge coefficients. Thinking more about it, I thought that is would be better to just write $$x(n)=\sum_{k=1}^m \frac{a_k}{n^k}$$ and, when required, transform this expansion to the desired $[p,p+1]$ Padé approximant. The coefficients so obtained are listed below $$\left( \begin{array}{cc} k & a_k \\ 1 & \frac{11}{240} \\ 2 & -\frac{79}{3360} \\ 3 & -\frac{3539}{201600} \\ 4 & \frac{9511}{403200} \\ 5 & \frac{10051}{716800} \\ 6 & -\frac{233934691}{6386688000} \\ 7 & -\frac{3595113569}{178827264000} \\ 8 & \frac{403527851669}{4649508864000} \\ 9 & \frac{25622861661869}{557941063680000} \\ 10 & -\frac{30016604936501}{101443829760000} \\ 11 & -\frac{685661227463561}{4463528509440000} \\ 12 & \frac{109896661164737049961}{79673983893504000000} \end{array} \right)$$ For $n=25$, this would lead to $\color{blue}{1551121004333098598400000}5$.

For $n=30$ , this would lead to $\color{blue}{26525285981219105863630848}5359781$.

This seems to be significantly better.

0

Stirlings approximation is good ... especially if in the expression for $\ln(n!)$ you include the series in odd powers of 1/n. Are you aware of that series - Stirlings aporoximation is all-too-often given without it. The coefficients of it are not too compliated - Bernoulli numbers multiplied by simple factors. Ah yes! maybe it is troublesome for very large n then because of that - the way the Bernoulli numbers 'turn round'.

This might answer your question though.

AmbretteOrrisey
  • 1,001
  • 6
  • 12