Average Error: 6.2 → 4.5
Time: 8.8s
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 1.96024159275946858 \cdot 10^{85}:\\ \;\;\;\;\log x \cdot \left(x - 0.5\right) + \left(\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)\\ \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 1.96024159275946858 \cdot 10^{85}:\\
\;\;\;\;\log x \cdot \left(x - 0.5\right) + \left(\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)\\

\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 r597577 = x;
        double r597578 = 0.5;
        double r597579 = r597577 - r597578;
        double r597580 = log(r597577);
        double r597581 = r597579 * r597580;
        double r597582 = r597581 - r597577;
        double r597583 = 0.91893853320467;
        double r597584 = r597582 + r597583;
        double r597585 = y;
        double r597586 = 0.0007936500793651;
        double r597587 = r597585 + r597586;
        double r597588 = z;
        double r597589 = r597587 * r597588;
        double r597590 = 0.0027777777777778;
        double r597591 = r597589 - r597590;
        double r597592 = r597591 * r597588;
        double r597593 = 0.083333333333333;
        double r597594 = r597592 + r597593;
        double r597595 = r597594 / r597577;
        double r597596 = r597584 + r597595;
        return r597596;
}

double f(double x, double y, double z) {
        double r597597 = x;
        double r597598 = 1.9602415927594686e+85;
        bool r597599 = r597597 <= r597598;
        double r597600 = log(r597597);
        double r597601 = 0.5;
        double r597602 = r597597 - r597601;
        double r597603 = r597600 * r597602;
        double r597604 = y;
        double r597605 = 0.0007936500793651;
        double r597606 = r597604 + r597605;
        double r597607 = z;
        double r597608 = r597606 * r597607;
        double r597609 = 0.0027777777777778;
        double r597610 = r597608 - r597609;
        double r597611 = r597610 * r597607;
        double r597612 = 0.083333333333333;
        double r597613 = r597611 + r597612;
        double r597614 = r597613 / r597597;
        double r597615 = 0.91893853320467;
        double r597616 = r597597 - r597615;
        double r597617 = r597614 - r597616;
        double r597618 = r597603 + r597617;
        double r597619 = 2.0;
        double r597620 = pow(r597607, r597619);
        double r597621 = r597620 / r597597;
        double r597622 = r597605 * r597621;
        double r597623 = 1.0;
        double r597624 = r597623 / r597597;
        double r597625 = log(r597624);
        double r597626 = fma(r597625, r597597, r597597);
        double r597627 = r597622 - r597626;
        double r597628 = fma(r597621, r597604, r597627);
        double r597629 = r597599 ? r597618 : r597628;
        return r597629;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.2
Target1.3
Herbie4.5
\[\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.9602415927594686e+85

    1. Initial program 1.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. Simplified1.2

      \[\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. Using strategy rm
    4. Applied fma-udef1.2

      \[\leadsto \color{blue}{\log x \cdot \left(x - 0.5\right) + \left(\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)}\]

    if 1.9602415927594686e+85 < x

    1. Initial program 12.3

      \[\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. Simplified12.3

      \[\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 12.4

      \[\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. Simplified8.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 1.96024159275946858 \cdot 10^{85}:\\ \;\;\;\;\log x \cdot \left(x - 0.5\right) + \left(\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)\\ \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 2020060 +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)))