break_eternity.js
break_eternity.js copied to clipboard
Wrong factorial approximation
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
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).
Your fix has been added to my pull request. Hopefully that means it'll get fixed soon.
Fixed.