Post Reply 
Calculate large factorials on a HP48 (SysRPL)
02-23-2014, 04:33 PM (This post was last modified: 02-23-2014 05:11 PM by Dieter.)
Post: #7
RE: Calculate large factorials on a HP48 (SysRPL)
(02-18-2014 10:32 PM)Christoph Giesselink Wrote:  A solution for this is using the internal data type "long real". This SysRPL program using the same algorithm like before. Because the logarithm to the base 10 don't exist for long real I use the natural logarithm function %%LN.

So essentially you're calculating ln n! first and then n! is obtained from this.

There is an easier and much faster method for this: simply use a Stirling approximation. With only two terms, the largest error in log10 n! is less than 1 unit in the 12th significant digit if n ≥ 70. Since n! can be calculated directly for n ≤ 253, we only have to consider n ≥ 254. If evaluated exactly (!), the absolute error of log10 n! is less than 3,3 E-16, i.e. better than the available working precicion. So two terms are all we need:

\(ln n!  =  n · ln n + \frac{1}{2}ln(2 n \pi) - n + \frac{1}{12 n} - \frac{1}{360 n^3} + ...\)

The resulting accuracy is essentially limited by that of the internal 15-digit functions and the order of addition: add the smallest terms first.

Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Calculate large factorials on a HP48 (SysRPL) - Dieter - 02-23-2014 04:33 PM

User(s) browsing this thread: 1 Guest(s)