Average Error: 6.2 → 4.5
Time: 9.3s
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 r536682 = x;
        double r536683 = 0.5;
        double r536684 = r536682 - r536683;
        double r536685 = log(r536682);
        double r536686 = r536684 * r536685;
        double r536687 = r536686 - r536682;
        double r536688 = 0.91893853320467;
        double r536689 = r536687 + r536688;
        double r536690 = y;
        double r536691 = 0.0007936500793651;
        double r536692 = r536690 + r536691;
        double r536693 = z;
        double r536694 = r536692 * r536693;
        double r536695 = 0.0027777777777778;
        double r536696 = r536694 - r536695;
        double r536697 = r536696 * r536693;
        double r536698 = 0.083333333333333;
        double r536699 = r536697 + r536698;
        double r536700 = r536699 / r536682;
        double r536701 = r536689 + r536700;
        return r536701;
}

double f(double x, double y, double z) {
        double r536702 = x;
        double r536703 = 1.9602415927594686e+85;
        bool r536704 = r536702 <= r536703;
        double r536705 = log(r536702);
        double r536706 = 0.5;
        double r536707 = r536702 - r536706;
        double r536708 = r536705 * r536707;
        double r536709 = y;
        double r536710 = 0.0007936500793651;
        double r536711 = r536709 + r536710;
        double r536712 = z;
        double r536713 = r536711 * r536712;
        double r536714 = 0.0027777777777778;
        double r536715 = r536713 - r536714;
        double r536716 = r536715 * r536712;
        double r536717 = 0.083333333333333;
        double r536718 = r536716 + r536717;
        double r536719 = r536718 / r536702;
        double r536720 = 0.91893853320467;
        double r536721 = r536702 - r536720;
        double r536722 = r536719 - r536721;
        double r536723 = r536708 + r536722;
        double r536724 = 2.0;
        double r536725 = pow(r536712, r536724);
        double r536726 = r536725 / r536702;
        double r536727 = r536710 * r536726;
        double r536728 = 1.0;
        double r536729 = r536728 / r536702;
        double r536730 = log(r536729);
        double r536731 = fma(r536730, r536702, r536702);
        double r536732 = r536727 - r536731;
        double r536733 = fma(r536726, r536709, r536732);
        double r536734 = r536704 ? r536723 : r536733;
        return r536734;
}

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