Average Error: 5.8 → 4.0
Time: 18.9s
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 3.17800226500740349 \cdot 10^{58}:\\ \;\;\;\;\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)\\ \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 3.17800226500740349 \cdot 10^{58}:\\
\;\;\;\;\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)\\

\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 r553787 = x;
        double r553788 = 0.5;
        double r553789 = r553787 - r553788;
        double r553790 = log(r553787);
        double r553791 = r553789 * r553790;
        double r553792 = r553791 - r553787;
        double r553793 = 0.91893853320467;
        double r553794 = r553792 + r553793;
        double r553795 = y;
        double r553796 = 0.0007936500793651;
        double r553797 = r553795 + r553796;
        double r553798 = z;
        double r553799 = r553797 * r553798;
        double r553800 = 0.0027777777777778;
        double r553801 = r553799 - r553800;
        double r553802 = r553801 * r553798;
        double r553803 = 0.083333333333333;
        double r553804 = r553802 + r553803;
        double r553805 = r553804 / r553787;
        double r553806 = r553794 + r553805;
        return r553806;
}

double f(double x, double y, double z) {
        double r553807 = x;
        double r553808 = 3.1780022650074035e+58;
        bool r553809 = r553807 <= r553808;
        double r553810 = log(r553807);
        double r553811 = 0.5;
        double r553812 = r553807 - r553811;
        double r553813 = y;
        double r553814 = 0.0007936500793651;
        double r553815 = r553813 + r553814;
        double r553816 = z;
        double r553817 = r553815 * r553816;
        double r553818 = 0.0027777777777778;
        double r553819 = r553817 - r553818;
        double r553820 = 0.083333333333333;
        double r553821 = fma(r553819, r553816, r553820);
        double r553822 = r553821 / r553807;
        double r553823 = 0.91893853320467;
        double r553824 = r553823 - r553807;
        double r553825 = r553822 + r553824;
        double r553826 = fma(r553810, r553812, r553825);
        double r553827 = -r553818;
        double r553828 = r553816 / r553807;
        double r553829 = 2.0;
        double r553830 = pow(r553816, r553829);
        double r553831 = r553830 / r553807;
        double r553832 = r553831 * r553815;
        double r553833 = fma(r553827, r553828, r553832);
        double r553834 = r553833 + r553824;
        double r553835 = fma(r553810, r553812, r553834);
        double r553836 = r553809 ? r553826 : r553835;
        return r553836;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original5.8
Target1.2
Herbie4.0
\[\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 < 3.1780022650074035e+58

    1. Initial program 0.7

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

      \[\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 div-inv0.8

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

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \color{blue}{\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 3.1780022650074035e+58 < x

    1. Initial program 11.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. Simplified11.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 3.17800226500740349 \cdot 10^{58}:\\ \;\;\;\;\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)\\ \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 2020042 +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)))