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

Wrong factorial approximation #162

Closed
hypcos opened this issue Mar 23, 2024 · 3 comments
Closed

Wrong factorial approximation #162

hypcos opened this issue Mar 23, 2024 · 3 comments

Comments

@hypcos
Copy link

hypcos commented Mar 23, 2024

  var f_gamma = function f_gamma(n) {
    //unrelated things
    var l = 0.9189385332046727; //0.5*Math.log(2*Math.PI)
    l = l + (n + 0.5) * Math.log(n);
    l = l - n;
    var n2 = n * n;
    var np = n;
    l = l + 1 / (12 * np);
    np = np * n2;
    l = l + 1 / (360 * np);
    np = np * n2;
    l = l + 1 / (1260 * np);
    np = np * n2;
    l = l + 1 / (1680 * np);
    np = np * n2;
    l = l + 1 / (1188 * np);
    np = np * n2;
    l = l + 691 / (360360 * np);
    np = np * n2;
    l = l + 7 / (1092 * np);
    np = np * n2;
    l = l + 3617 / (122400 * np);
    return Math.exp(l) / scal1;
  };

This looks like the series expansion of ln(n!), but some coefficients are wrong:
The l = l + 1 / (360 * np); should be l = l - 1 / (360 * np);
The l = l + 1 / (1680 * np); should be l = l - 1 / (1680 * np);
The l = l + 691 / (360360 * np); should be l = l - 691 / (360360 * np);
The l = l + 3617 / (122400 * np); should be l = l - 3617 / (122400 * np);
I guess the mistake also exists in other files than break_eternity.js

@James103
Copy link

I tested these changes and the corrected f_gamma function appears to be much more accurate (with a relative error around 10-14 instead of 10-6).

@MathCookie17
Copy link
Collaborator

Your fix has been added to my pull request. Hopefully that means it'll get fixed soon.

@MathCookie17
Copy link
Collaborator

Fixed.

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

No branches or pull requests

3 participants