Average Error: 5.9 → 4.1
Time: 18.2s
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 5.22724690959896697 \cdot 10^{38}:\\ \;\;\;\;\sqrt{\log x \cdot \left(x - 0.5\right)} \cdot \sqrt{\mathsf{fma}\left(\sqrt[3]{x} \cdot \sqrt[3]{x}, \sqrt[3]{x}, -0.5\right) \cdot \log x + \left(0.5 - 0.5\right) \cdot \log x} + \left(\frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x} + \left(0.91893853320467001 - x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, \mathsf{fma}\left(-0.0027777777777778, \frac{z}{x}, \frac{{z}^{2}}{x} \cdot \left(y + 7.93650079365100015 \cdot 10^{-4}\right)\right) + \left(0.91893853320467001 - 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 5.22724690959896697 \cdot 10^{38}:\\
\;\;\;\;\sqrt{\log x \cdot \left(x - 0.5\right)} \cdot \sqrt{\mathsf{fma}\left(\sqrt[3]{x} \cdot \sqrt[3]{x}, \sqrt[3]{x}, -0.5\right) \cdot \log x + \left(0.5 - 0.5\right) \cdot \log x} + \left(\frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x} + \left(0.91893853320467001 - x\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r489540 = x;
        double r489541 = 0.5;
        double r489542 = r489540 - r489541;
        double r489543 = log(r489540);
        double r489544 = r489542 * r489543;
        double r489545 = r489544 - r489540;
        double r489546 = 0.91893853320467;
        double r489547 = r489545 + r489546;
        double r489548 = y;
        double r489549 = 0.0007936500793651;
        double r489550 = r489548 + r489549;
        double r489551 = z;
        double r489552 = r489550 * r489551;
        double r489553 = 0.0027777777777778;
        double r489554 = r489552 - r489553;
        double r489555 = r489554 * r489551;
        double r489556 = 0.083333333333333;
        double r489557 = r489555 + r489556;
        double r489558 = r489557 / r489540;
        double r489559 = r489547 + r489558;
        return r489559;
}

double f(double x, double y, double z) {
        double r489560 = x;
        double r489561 = 5.227246909598967e+38;
        bool r489562 = r489560 <= r489561;
        double r489563 = log(r489560);
        double r489564 = 0.5;
        double r489565 = r489560 - r489564;
        double r489566 = r489563 * r489565;
        double r489567 = sqrt(r489566);
        double r489568 = cbrt(r489560);
        double r489569 = r489568 * r489568;
        double r489570 = -r489564;
        double r489571 = fma(r489569, r489568, r489570);
        double r489572 = r489571 * r489563;
        double r489573 = r489564 - r489564;
        double r489574 = r489573 * r489563;
        double r489575 = r489572 + r489574;
        double r489576 = sqrt(r489575);
        double r489577 = r489567 * r489576;
        double r489578 = y;
        double r489579 = 0.0007936500793651;
        double r489580 = r489578 + r489579;
        double r489581 = z;
        double r489582 = r489580 * r489581;
        double r489583 = 0.0027777777777778;
        double r489584 = r489582 - r489583;
        double r489585 = 0.083333333333333;
        double r489586 = fma(r489584, r489581, r489585);
        double r489587 = r489586 / r489560;
        double r489588 = 0.91893853320467;
        double r489589 = r489588 - r489560;
        double r489590 = r489587 + r489589;
        double r489591 = r489577 + r489590;
        double r489592 = -r489583;
        double r489593 = r489581 / r489560;
        double r489594 = 2.0;
        double r489595 = pow(r489581, r489594);
        double r489596 = r489595 / r489560;
        double r489597 = r489596 * r489580;
        double r489598 = fma(r489592, r489593, r489597);
        double r489599 = r489598 + r489589;
        double r489600 = fma(r489563, r489565, r489599);
        double r489601 = r489562 ? r489591 : r489600;
        return r489601;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original5.9
Target1.2
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 < 5.227246909598967e+38

    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. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log x, x - 0.5, \frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x} + \left(0.91893853320467001 - x\right)\right)}\]
    3. Using strategy rm
    4. Applied fma-udef0.2

      \[\leadsto \color{blue}{\log x \cdot \left(x - 0.5\right) + \left(\frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x} + \left(0.91893853320467001 - x\right)\right)}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt0.3

      \[\leadsto \color{blue}{\sqrt{\log x \cdot \left(x - 0.5\right)} \cdot \sqrt{\log x \cdot \left(x - 0.5\right)}} + \left(\frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x} + \left(0.91893853320467001 - x\right)\right)\]
    7. Using strategy rm
    8. Applied add-cube-cbrt0.3

      \[\leadsto \sqrt{\log x \cdot \left(x - 0.5\right)} \cdot \sqrt{\log x \cdot \left(x - \color{blue}{\left(\sqrt[3]{0.5} \cdot \sqrt[3]{0.5}\right) \cdot \sqrt[3]{0.5}}\right)} + \left(\frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x} + \left(0.91893853320467001 - x\right)\right)\]
    9. Applied add-cube-cbrt0.4

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

      \[\leadsto \sqrt{\log x \cdot \left(x - 0.5\right)} \cdot \sqrt{\log x \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt[3]{x} \cdot \sqrt[3]{x}, \sqrt[3]{x}, -\sqrt[3]{0.5} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{0.5}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{0.5}, \sqrt[3]{0.5} \cdot \sqrt[3]{0.5}, \sqrt[3]{0.5} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{0.5}\right)\right)\right)}} + \left(\frac{\mathsf{fma}\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778, z, 0.0833333333333329956\right)}{x} + \left(0.91893853320467001 - x\right)\right)\]
    11. Applied distribute-lft-in0.4

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

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

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

    if 5.227246909598967e+38 < x

    1. Initial program 11.0

      \[\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.9

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

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

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

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

Reproduce

herbie shell --seed 2020043 +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)))