Repository navigation
Commit 0a56a2a
Make Spouge's constants from exact ratios and powers of e (#2090)
The factorial of a non-integer is Spouge's approximation, with a = 1.3 P constants at P digits,
cached per precision. Each constant c_k = (-1)^(k - 1) (a - k)^(k - 1/2) e^(a - k)/(k - 1)! was made
with a power to a non-integer exponent and an exponential, a logarithm and two exponentials at
1.95 P digits for each of the 1.3 P terms. The first factorial at a precision
took 0.9 s at 100 digits, 20.5 s at 300 and 218 s at 600.
(a - k)^(k - 1)/(k - 1)! is a ratio of exact integers, sqrt(a - k) one square root, and e^(a - k)
the running product of e, carried with ten more digits for the a multiplications and rounded
back to the constants' precision. The first factorial now takes 0.12 s at 100 digits, 0.57 s at
300, 1.5 s at 600, 5.5 s at 1000 and 30 s at 2000.
The values are unchanged. Against mpmath, Gamma(1/3), Gamma(1/3 + i), Gamma(2/7), Gamma(-7/3),
Gamma(101/2) and Gamma(-5/2 + 3i) have the same error on both builds at 100 and 300 digits,
within 1.3 units of the last digit, and stay within that at 600 and 1000. Once compiled, an
evaluation at 100 digits costs the same, 7 to 10 ms, on both. A test of (1/3)! and (1/3 + i)! at
300 digits is added.
Part of #2075.
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>1 parent 2be40ba commit 0a56a2a
2 files changed
Lines changed: 35 additions & 10 deletions
File tree
- Sources
- AngouriMath/Functions
- Tests/UnitTests/Core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1245 | 1245 | | |
1246 | 1246 | | |
1247 | 1247 | | |
1248 | | - | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
1249 | 1258 | | |
1250 | 1259 | | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
1257 | | - | |
1258 | | - | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
1259 | 1266 | | |
1260 | 1267 | | |
1261 | 1268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
81 | 99 | | |
82 | 100 | | |
83 | 101 | | |
| |||
0 commit comments