Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The algorithm for logFactorial bears re-evaluation #17

Closed
treeowl opened this issue Oct 18, 2012 · 1 comment
Closed

The algorithm for logFactorial bears re-evaluation #17

treeowl opened this issue Oct 18, 2012 · 1 comment

Comments

@treeowl
Copy link

treeowl commented Oct 18, 2012

John D. Cook claims at http://www.johndcook.com/blog/2010/08/16/how-to-compute-log-factorial/ that for values of n over approximately 256, it should be sufficient to use the approximation

log(x!) ~= (x – 1/2) log(x) – x + (1/2) log(2 π) + 1/(12 x).

If this is true, it should substantially improve the efficiency of logFactorial. Even if it is not quite true for n=256, it should become true for larger values of n. Cook also recommends using a table for values of n under around 256. His sample code uses a very slightly smaller table for unstated reasons. If a 256-entry table is judged too large for some reason, it would still pay to use a small table for the values currently calculated by sum of logs, cut over to the current approximation, and then finally cut over to Cook's suggestion (or similar).

@Shimuuar
Copy link
Collaborator

Shimuuar commented Nov 4, 2012

Probably that's correct. What's really needed for switch is

  1. Evaluation of approximation's precision. Is it good enough. When we cold switch.
  2. Benchmarks which show that implementation is indeed faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants