Average Error: 6.0 → 4.1
Time: 14.5s
Precision: 64
\[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le 15119356296086663000:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + 1 \cdot \frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{{z}^{2}}{x}, y, 7.93650079365100015 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} - \mathsf{fma}\left(\log \left(\frac{1}{x}\right), x, x\right)\right)\\ \end{array}\]
\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x}
\begin{array}{l}
\mathbf{if}\;x \le 15119356296086663000:\\
\;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + 1 \cdot \frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{{z}^{2}}{x}, y, 7.93650079365100015 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} - \mathsf{fma}\left(\log \left(\frac{1}{x}\right), x, x\right)\right)\\

\end{array}
double f(double x, double y, double z) {
        double r2376 = x;
        double r2377 = 0.5;
        double r2378 = r2376 - r2377;
        double r2379 = log(r2376);
        double r2380 = r2378 * r2379;
        double r2381 = r2380 - r2376;
        double r2382 = 0.91893853320467;
        double r2383 = r2381 + r2382;
        double r2384 = y;
        double r2385 = 0.0007936500793651;
        double r2386 = r2384 + r2385;
        double r2387 = z;
        double r2388 = r2386 * r2387;
        double r2389 = 0.0027777777777778;
        double r2390 = r2388 - r2389;
        double r2391 = r2390 * r2387;
        double r2392 = 0.083333333333333;
        double r2393 = r2391 + r2392;
        double r2394 = r2393 / r2376;
        double r2395 = r2383 + r2394;
        return r2395;
}

double f(double x, double y, double z) {
        double r2396 = x;
        double r2397 = 1.5119356296086663e+19;
        bool r2398 = r2396 <= r2397;
        double r2399 = 0.5;
        double r2400 = r2396 - r2399;
        double r2401 = log(r2396);
        double r2402 = r2400 * r2401;
        double r2403 = r2402 - r2396;
        double r2404 = 0.91893853320467;
        double r2405 = r2403 + r2404;
        double r2406 = 1.0;
        double r2407 = y;
        double r2408 = 0.0007936500793651;
        double r2409 = r2407 + r2408;
        double r2410 = z;
        double r2411 = r2409 * r2410;
        double r2412 = 0.0027777777777778;
        double r2413 = r2411 - r2412;
        double r2414 = 0.083333333333333;
        double r2415 = fma(r2413, r2410, r2414);
        double r2416 = r2415 / r2396;
        double r2417 = r2406 * r2416;
        double r2418 = r2405 + r2417;
        double r2419 = 2.0;
        double r2420 = pow(r2410, r2419);
        double r2421 = r2420 / r2396;
        double r2422 = r2408 * r2421;
        double r2423 = r2406 / r2396;
        double r2424 = log(r2423);
        double r2425 = fma(r2424, r2396, r2396);
        double r2426 = r2422 - r2425;
        double r2427 = fma(r2421, r2407, r2426);
        double r2428 = r2398 ? r2418 : r2427;
        return r2428;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.0
Target1.3
Herbie4.1
\[\left(\left(\left(x - 0.5\right) \cdot \log x + \left(0.91893853320467001 - x\right)\right) + \frac{0.0833333333333329956}{x}\right) + \frac{z}{x} \cdot \left(z \cdot \left(y + 7.93650079365100015 \cdot 10^{-4}\right) - 0.0027777777777778\right)\]

Derivation

  1. Split input into 2 regimes
  2. if x < 1.5119356296086663e+19

    1. Initial program 0.2

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.2

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{\color{blue}{1 \cdot x}}\]
    4. Applied *-un-lft-identity0.2

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + \frac{\color{blue}{1 \cdot \left(\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956\right)}}{1 \cdot x}\]
    5. Applied times-frac0.2

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + \color{blue}{\frac{1}{1} \cdot \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x}}\]
    6. Simplified0.2

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + \color{blue}{1} \cdot \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x}\]
    7. Simplified0.2

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + 1 \cdot \color{blue}{\frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x}}\]

    if 1.5119356296086663e+19 < x

    1. Initial program 10.6

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x}\]
    2. Simplified10.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log x, x - 0.5, \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x} - \left(x - 0.91893853320467001\right)\right)}\]
    3. Taylor expanded around inf 10.6

      \[\leadsto \color{blue}{\left(7.93650079365100015 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} + \frac{{z}^{2} \cdot y}{x}\right) - \left(x + x \cdot \log \left(\frac{1}{x}\right)\right)}\]
    4. Simplified7.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 15119356296086663000:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467001\right) + 1 \cdot \frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{{z}^{2}}{x}, y, 7.93650079365100015 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} - \mathsf{fma}\left(\log \left(\frac{1}{x}\right), x, x\right)\right)\\ \end{array}\]

Reproduce

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

  :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)))