Average Error: 6.3 → 4.5
Time: 9.5s
Precision: binary64
\[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 7.87607369627486 \cdot 10^{-23}:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\left(0.0007936500793651 \cdot \frac{{z}^{2}}{x} + \left(\frac{{z}^{2} \cdot y}{x} + 0.083333333333333 \cdot \frac{1}{x}\right)\right) - 0.0027777777777778 \cdot \frac{z}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, 0.91893853320467 - x\right) + \mathsf{fma}\left(\frac{z}{x}, -0.0027777777777778, \mathsf{fma}\left(0.0007936500793651, \frac{z \cdot z}{x}, \mathsf{fma}\left(\frac{y}{x}, z \cdot z, \frac{0.083333333333333}{x}\right)\right)\right)\\ \end{array} \]
\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}
\begin{array}{l}
\mathbf{if}\;x \leq 7.87607369627486 \cdot 10^{-23}:\\
\;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\left(0.0007936500793651 \cdot \frac{{z}^{2}}{x} + \left(\frac{{z}^{2} \cdot y}{x} + 0.083333333333333 \cdot \frac{1}{x}\right)\right) - 0.0027777777777778 \cdot \frac{z}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, 0.91893853320467 - x\right) + \mathsf{fma}\left(\frac{z}{x}, -0.0027777777777778, \mathsf{fma}\left(0.0007936500793651, \frac{z \cdot z}{x}, \mathsf{fma}\left(\frac{y}{x}, z \cdot z, \frac{0.083333333333333}{x}\right)\right)\right)\\


\end{array}
(FPCore (x y z)
 :precision binary64
 (+
  (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467)
  (/
   (+
    (* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z)
    0.083333333333333)
   x)))
(FPCore (x y z)
 :precision binary64
 (if (<= x 7.87607369627486e-23)
   (+
    (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467)
    (-
     (+
      (* 0.0007936500793651 (/ (pow z 2.0) x))
      (+ (/ (* (pow z 2.0) y) x) (* 0.083333333333333 (/ 1.0 x))))
     (* 0.0027777777777778 (/ z x))))
   (+
    (fma (log x) (- x 0.5) (- 0.91893853320467 x))
    (fma
     (/ z x)
     -0.0027777777777778
     (fma
      0.0007936500793651
      (/ (* z z) x)
      (fma (/ y x) (* z z) (/ 0.083333333333333 x)))))))
double code(double x, double y, double z) {
	return ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + ((((((y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x);
}
double code(double x, double y, double z) {
	double tmp;
	if (x <= 7.87607369627486e-23) {
		tmp = ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + (((0.0007936500793651 * (pow(z, 2.0) / x)) + (((pow(z, 2.0) * y) / x) + (0.083333333333333 * (1.0 / x)))) - (0.0027777777777778 * (z / x)));
	} else {
		tmp = fma(log(x), (x - 0.5), (0.91893853320467 - x)) + fma((z / x), -0.0027777777777778, fma(0.0007936500793651, ((z * z) / x), fma((y / x), (z * z), (0.083333333333333 / x))));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.3
Target1.3
Herbie4.5
\[\left(\left(\left(x - 0.5\right) \cdot \log x + \left(0.91893853320467 - x\right)\right) + \frac{0.083333333333333}{x}\right) + \frac{z}{x} \cdot \left(z \cdot \left(y + 0.0007936500793651\right) - 0.0027777777777778\right) \]

Derivation

  1. Split input into 2 regimes
  2. if x < 7.87607369627486013e-23

    1. Initial program 0.4

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    2. Taylor expanded in y around 0 0.5

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\left(\left(0.0007936500793651 \cdot \frac{{z}^{2}}{x} + \left(\frac{y \cdot {z}^{2}}{x} + 0.083333333333333 \cdot \frac{1}{x}\right)\right) - 0.0027777777777778 \cdot \frac{z}{x}\right)} \]

    if 7.87607369627486013e-23 < x

    1. Initial program 10.0

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    2. Taylor expanded in x around 0 10.0

      \[\leadsto \color{blue}{\left(\left(0.91893853320467 + \log x \cdot x\right) - \left(0.5 \cdot \log x + x\right)\right)} + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    3. Simplified10.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log x, x + -0.5, 0.91893853320467 - x\right)} + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    4. Applied add-cube-cbrt_binary6410.0

      \[\leadsto \mathsf{fma}\left(\log x, x + -0.5, 0.91893853320467 - x\right) + \frac{\left(\color{blue}{\left(\left(\sqrt[3]{y + 0.0007936500793651} \cdot \sqrt[3]{y + 0.0007936500793651}\right) \cdot \sqrt[3]{y + 0.0007936500793651}\right)} \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    5. Applied associate-*l*_binary6410.0

      \[\leadsto \mathsf{fma}\left(\log x, x + -0.5, 0.91893853320467 - x\right) + \frac{\left(\color{blue}{\left(\sqrt[3]{y + 0.0007936500793651} \cdot \sqrt[3]{y + 0.0007936500793651}\right) \cdot \left(\sqrt[3]{y + 0.0007936500793651} \cdot z\right)} - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    6. Taylor expanded in y around 0 10.1

      \[\leadsto \mathsf{fma}\left(\log x, x + -0.5, 0.91893853320467 - x\right) + \color{blue}{\left(\left(0.0007936500793651 \cdot \frac{{z}^{2}}{x} + \left(\frac{y \cdot {z}^{2}}{x} + 0.083333333333333 \cdot \frac{1}{x}\right)\right) - 0.0027777777777778 \cdot \frac{z}{x}\right)} \]
    7. Simplified7.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7.87607369627486 \cdot 10^{-23}:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\left(0.0007936500793651 \cdot \frac{{z}^{2}}{x} + \left(\frac{{z}^{2} \cdot y}{x} + 0.083333333333333 \cdot \frac{1}{x}\right)\right) - 0.0027777777777778 \cdot \frac{z}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, 0.91893853320467 - x\right) + \mathsf{fma}\left(\frac{z}{x}, -0.0027777777777778, \mathsf{fma}\left(0.0007936500793651, \frac{z \cdot z}{x}, \mathsf{fma}\left(\frac{y}{x}, z \cdot z, \frac{0.083333333333333}{x}\right)\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022063 
(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)))