You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 58a75c7
Browse filesBrowse the repository at this point in the historyBrowse files
The factorial, gamma and the totient compile under Compile<TIn, TOut> (#1620)
Compile<TIn, TOut> had no form for x!, gamma or phi, and Compile's own had defects. Both compilers
now call one routine in SpecialFunctions.
The factorial is exact at a whole number up to 170, rounded once to a double, and infinite past it;
NaN at a negative whole number, one of the gamma function's poles, as in the interpreter; and
elsewhere the Lanczos approximation Compile always used (g = 7, nine terms), taken in logarithms,
the reflection formula included. Compile's overflowed its own power before the value did, so from
just past 141!, about 2e243, it compiled to NaN, up to 170!. At a whole number it was a rounding
off the integer, 23.999999999999996 at 4, which a compilation over integers truncates to 23. Off
the real line the reflection's sin(pi z) overflowed where the value is tiny; past
|Im(pi z)| = 20 it is a logarithm written out now. gamma(x) is (x - 1)!.
The totient is the totient at a whole number, 0 at one that is not positive, and NaN at any other
number, as the interpreter's is. Compile truncated a fraction to the whole number below it, so
phi(2.5) was phi(2). Under Compile<TIn, TOut>, long, int and BigInteger take it exactly.
Against mpmath the compiled factorial is within 1.1e-13 of the value on a grid of [-14, 14]^2,
2.4e-13 up the imaginary axis to 10^4.5 and 3.2e-13 on circles out to radius 300. It is further
out only where the conditioning forces it: next to a pole, and in the subnormal range past -177.
SpecialFunctionCompilationTest gains the factorial and gamma against the interpreter, through both
compilers and over doubles; whole numbers exact, including under Compile<long, long>; 171 infinite
and the poles NaN; and the totient at whole numbers over every integer type, NaN elsewhere.
UserInvalidExceptions keeps binomial, gcd, lcm and prime as the nodes with no compiled form.
Closes#1607.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0 commit comments