Expand description
The gamma family’s backend for Compensated, one rung below
SpecializedSpecialMath.
See the parent module for why this rung exists. In short: the gamma family
is the part of thermite-special that is driven by fitted coefficients, and the
width of a Compensated decides which coefficients are correct - so it needs a
dispatch axis that Compensated’s single blanket backend impl does not have.
§Implementing
Every method has a default, so the minimal impl is empty:
impl<V: FloatVector<Element = f64>> SpecializedCompensatedSpecialMath<Compensated<f64>>
for Compensated<V> {}Override a method when this width can do better than the generic series - typically by carrying a table tuned to it.
§The generic algorithm
The defaults are Stirling and its derivatives, which is one expansion in one set of
constants for the whole family. Shift the argument up by the recurrences until it is
large ($x \gtrsim 30$ for double-double), then:
\ln\Gamma(x) \sim (x - \tfrac{1}{2})\ln x - x + \tfrac{1}{2}\ln 2\pi
+ \sum_{n \ge 1} \frac{B_{2n}}{2n(2n-1)x^{2n-1}}\psi(x) \sim \ln x - \frac{1}{2x} - \sum_{n \ge 1} \frac{B_{2n}}{2n\,x^{2n}}
\qquad
\psi_1(x) \sim \frac{1}{x} + \frac{1}{2x^2} + \sum_{n \ge 1} \frac{B_{2n}}{x^{2n+1}}The Bernoulli numbers are exact rationals, so unlike the minimax rationals the real
f32/f64 paths use, they extend to any precision without refitting - there is no
oracle to chase and no table to source. Roughly 13 terms clear $2^{-106}$ at
$x > 30$, about half that for double-single, so the term count is a const off the
mantissa width rather than a fixed loop.
This is why Compensated may never want Lanczos. The real paths use it because it
skips the shift loop; here every operation is already an order of magnitude more
expensive, so the loop costs relatively less and a 24-coefficient table at 32 digits
costs a lot to source and validate.
Traits§
- Compensated
Gamma Ops - What a default body needs of
Compensated<V>in order to do compensated arithmetic. - Specialized
Compensated Special Math - Backend for the coefficient-bearing part of
Compensated’s special math.