Average Error: 6.0 → 0.3
Time: 1.1m
Precision: 64
\[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le 20160595213046037610496:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, z \cdot \left(7.936500793651000149400709382518925849581 \cdot 10^{-4} + y\right) - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x} - \frac{x \cdot x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right) \cdot \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)}{\mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right) + x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z}{\frac{x}{z}}, \frac{z \cdot 7.936500793651000149400709382518925849581 \cdot 10^{-4}}{\frac{x}{z}} - \frac{0.002777777777777800001512975569539776188321 \cdot z}{x}\right) - \left(x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)\right)\\ \end{array}\]
\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}
\begin{array}{l}
\mathbf{if}\;x \le 20160595213046037610496:\\
\;\;\;\;\frac{\mathsf{fma}\left(z, z \cdot \left(7.936500793651000149400709382518925849581 \cdot 10^{-4} + y\right) - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x} - \frac{x \cdot x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right) \cdot \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)}{\mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right) + x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{\frac{x}{z}}, \frac{z \cdot 7.936500793651000149400709382518925849581 \cdot 10^{-4}}{\frac{x}{z}} - \frac{0.002777777777777800001512975569539776188321 \cdot z}{x}\right) - \left(x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)\right)\\

\end{array}
double f(double x, double y, double z) {
        double r19660369 = x;
        double r19660370 = 0.5;
        double r19660371 = r19660369 - r19660370;
        double r19660372 = log(r19660369);
        double r19660373 = r19660371 * r19660372;
        double r19660374 = r19660373 - r19660369;
        double r19660375 = 0.91893853320467;
        double r19660376 = r19660374 + r19660375;
        double r19660377 = y;
        double r19660378 = 0.0007936500793651;
        double r19660379 = r19660377 + r19660378;
        double r19660380 = z;
        double r19660381 = r19660379 * r19660380;
        double r19660382 = 0.0027777777777778;
        double r19660383 = r19660381 - r19660382;
        double r19660384 = r19660383 * r19660380;
        double r19660385 = 0.083333333333333;
        double r19660386 = r19660384 + r19660385;
        double r19660387 = r19660386 / r19660369;
        double r19660388 = r19660376 + r19660387;
        return r19660388;
}

double f(double x, double y, double z) {
        double r19660389 = x;
        double r19660390 = 2.0160595213046038e+22;
        bool r19660391 = r19660389 <= r19660390;
        double r19660392 = z;
        double r19660393 = 0.0007936500793651;
        double r19660394 = y;
        double r19660395 = r19660393 + r19660394;
        double r19660396 = r19660392 * r19660395;
        double r19660397 = 0.0027777777777778;
        double r19660398 = r19660396 - r19660397;
        double r19660399 = 0.083333333333333;
        double r19660400 = fma(r19660392, r19660398, r19660399);
        double r19660401 = r19660400 / r19660389;
        double r19660402 = r19660389 * r19660389;
        double r19660403 = log(r19660389);
        double r19660404 = 0.5;
        double r19660405 = r19660389 - r19660404;
        double r19660406 = 0.91893853320467;
        double r19660407 = fma(r19660403, r19660405, r19660406);
        double r19660408 = r19660407 * r19660407;
        double r19660409 = r19660402 - r19660408;
        double r19660410 = r19660407 + r19660389;
        double r19660411 = r19660409 / r19660410;
        double r19660412 = r19660401 - r19660411;
        double r19660413 = r19660389 / r19660392;
        double r19660414 = r19660392 / r19660413;
        double r19660415 = r19660392 * r19660393;
        double r19660416 = r19660415 / r19660413;
        double r19660417 = r19660397 * r19660392;
        double r19660418 = r19660417 / r19660389;
        double r19660419 = r19660416 - r19660418;
        double r19660420 = fma(r19660394, r19660414, r19660419);
        double r19660421 = r19660389 - r19660407;
        double r19660422 = r19660420 - r19660421;
        double r19660423 = r19660391 ? r19660412 : r19660422;
        return r19660423;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.0
Target1.2
Herbie0.3
\[\left(\left(\left(x - 0.5\right) \cdot \log x + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \frac{0.08333333333333299564049667651488562114537}{x}\right) + \frac{z}{x} \cdot \left(z \cdot \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) - 0.002777777777777800001512975569539776188321\right)\]

Derivation

  1. Split input into 2 regimes
  2. if x < 2.0160595213046038e+22

    1. Initial program 0.2

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}\]
    2. Simplified0.2

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x} - \left(x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)\right)}\]
    3. Using strategy rm
    4. Applied flip--0.2

      \[\leadsto \frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x} - \color{blue}{\frac{x \cdot x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right) \cdot \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)}{x + \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)}}\]

    if 2.0160595213046038e+22 < x

    1. Initial program 10.8

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}\]
    2. Simplified10.8

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x} - \left(x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)\right)}\]
    3. Using strategy rm
    4. Applied div-inv10.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right) \cdot \frac{1}{x}} - \left(x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)\right)\]
    5. Taylor expanded around inf 10.9

      \[\leadsto \color{blue}{\left(\left(7.936500793651000149400709382518925849581 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} + \frac{{z}^{2} \cdot y}{x}\right) - 0.002777777777777800001512975569539776188321 \cdot \frac{z}{x}\right)} - \left(x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)\right)\]
    6. Simplified0.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z}{\frac{x}{z}}, \frac{z \cdot 7.936500793651000149400709382518925849581 \cdot 10^{-4}}{\frac{x}{z}} - \frac{0.002777777777777800001512975569539776188321 \cdot z}{x}\right)} - \left(x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 20160595213046037610496:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, z \cdot \left(7.936500793651000149400709382518925849581 \cdot 10^{-4} + y\right) - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x} - \frac{x \cdot x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right) \cdot \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)}{\mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right) + x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z}{\frac{x}{z}}, \frac{z \cdot 7.936500793651000149400709382518925849581 \cdot 10^{-4}}{\frac{x}{z}} - \frac{0.002777777777777800001512975569539776188321 \cdot z}{x}\right) - \left(x - \mathsf{fma}\left(\log x, x - 0.5, 0.9189385332046700050057097541866824030876\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (x y z)
  :name "Numeric.SpecFunctions:$slogFactorial from math-functions-0.1.5.2, B"

  :herbie-target
  (+ (+ (+ (* (- x 0.5) (log x)) (- 0.91893853320467 x)) (/ 0.083333333333333 x)) (* (/ z x) (- (* z (+ y 0.0007936500793651)) 0.0027777777777778)))

  (+ (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467) (/ (+ (* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z) 0.083333333333333) x)))