Average Error: 5.7 → 3.8
Time: 12.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 12423664.860470358:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(x - 0.5, \log x, -x\right) + 0.91893853320467001} \cdot \sqrt{\mathsf{fma}\left(x - 0.5, \log x, -x\right) + 0.91893853320467001} + \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(x - 0.5, \log x, -x\right) + 0.91893853320467001\right) + \left(\frac{{z}^{2}}{x} \cdot \left(y + 7.93650079365100015 \cdot 10^{-4}\right) - 0.0027777777777778 \cdot \frac{z}{x}\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 12423664.860470358:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(x - 0.5, \log x, -x\right) + 0.91893853320467001} \cdot \sqrt{\mathsf{fma}\left(x - 0.5, \log x, -x\right) + 0.91893853320467001} + \frac{\left(\left(y + 7.93650079365100015 \cdot 10^{-4}\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.0833333333333329956}{x}\\

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

\end{array}
double f(double x, double y, double z) {
        double r412016 = x;
        double r412017 = 0.5;
        double r412018 = r412016 - r412017;
        double r412019 = log(r412016);
        double r412020 = r412018 * r412019;
        double r412021 = r412020 - r412016;
        double r412022 = 0.91893853320467;
        double r412023 = r412021 + r412022;
        double r412024 = y;
        double r412025 = 0.0007936500793651;
        double r412026 = r412024 + r412025;
        double r412027 = z;
        double r412028 = r412026 * r412027;
        double r412029 = 0.0027777777777778;
        double r412030 = r412028 - r412029;
        double r412031 = r412030 * r412027;
        double r412032 = 0.083333333333333;
        double r412033 = r412031 + r412032;
        double r412034 = r412033 / r412016;
        double r412035 = r412023 + r412034;
        return r412035;
}

double f(double x, double y, double z) {
        double r412036 = x;
        double r412037 = 12423664.860470358;
        bool r412038 = r412036 <= r412037;
        double r412039 = 0.5;
        double r412040 = r412036 - r412039;
        double r412041 = log(r412036);
        double r412042 = -r412036;
        double r412043 = fma(r412040, r412041, r412042);
        double r412044 = 0.91893853320467;
        double r412045 = r412043 + r412044;
        double r412046 = sqrt(r412045);
        double r412047 = r412046 * r412046;
        double r412048 = y;
        double r412049 = 0.0007936500793651;
        double r412050 = r412048 + r412049;
        double r412051 = z;
        double r412052 = r412050 * r412051;
        double r412053 = 0.0027777777777778;
        double r412054 = r412052 - r412053;
        double r412055 = r412054 * r412051;
        double r412056 = 0.083333333333333;
        double r412057 = r412055 + r412056;
        double r412058 = r412057 / r412036;
        double r412059 = r412047 + r412058;
        double r412060 = 2.0;
        double r412061 = pow(r412051, r412060);
        double r412062 = r412061 / r412036;
        double r412063 = r412062 * r412050;
        double r412064 = r412051 / r412036;
        double r412065 = r412053 * r412064;
        double r412066 = r412063 - r412065;
        double r412067 = r412045 + r412066;
        double r412068 = r412038 ? r412059 : r412067;
        return r412068;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original5.7
Target1.2
Herbie3.8
\[\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 < 12423664.860470358

    1. Initial program 0.1

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

      \[\leadsto \left(\color{blue}{\mathsf{fma}\left(x - 0.5, \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}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt0.2

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

    if 12423664.860470358 < x

    1. Initial program 9.9

      \[\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 fma-neg9.8

      \[\leadsto \left(\color{blue}{\mathsf{fma}\left(x - 0.5, \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}\]
    4. Taylor expanded around inf 9.9

      \[\leadsto \left(\mathsf{fma}\left(x - 0.5, \log x, -x\right) + 0.91893853320467001\right) + \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)}\]
    5. Simplified6.4

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

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

Reproduce

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