Average Error: 6.2 → 3.2
Time: 9.7s
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} t_0 := z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right)\\ t_1 := \log \left(\sqrt{x}\right)\\ \mathbf{if}\;t_0 \leq -1.371162106624129 \cdot 10^{+301}:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\frac{0.083333333333333}{x} - 0.0027777777777778 \cdot \frac{z}{x}\right)\\ \mathbf{elif}\;t_0 \leq 2.1114119818840957 \cdot 10^{+307}:\\ \;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, 0.91893853320467 - x\right) + \frac{\frac{1}{x}}{\frac{1}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, y + 0.0007936500793651, -0.0027777777777778\right), 0.083333333333333\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.083333333333333}{x} + \left(\left(x - 0.5\right) \cdot t_1 + \mathsf{fma}\left(x - 0.5, t_1, 0.91893853320467 - x\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}
t_0 := z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right)\\
t_1 := \log \left(\sqrt{x}\right)\\
\mathbf{if}\;t_0 \leq -1.371162106624129 \cdot 10^{+301}:\\
\;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\frac{0.083333333333333}{x} - 0.0027777777777778 \cdot \frac{z}{x}\right)\\

\mathbf{elif}\;t_0 \leq 2.1114119818840957 \cdot 10^{+307}:\\
\;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, 0.91893853320467 - x\right) + \frac{\frac{1}{x}}{\frac{1}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, y + 0.0007936500793651, -0.0027777777777778\right), 0.083333333333333\right)}}\\

\mathbf{else}:\\
\;\;\;\;\frac{0.083333333333333}{x} + \left(\left(x - 0.5\right) \cdot t_1 + \mathsf{fma}\left(x - 0.5, t_1, 0.91893853320467 - x\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
 (let* ((t_0 (* z (- (* (+ y 0.0007936500793651) z) 0.0027777777777778)))
        (t_1 (log (sqrt x))))
   (if (<= t_0 -1.371162106624129e+301)
     (+
      (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467)
      (- (/ 0.083333333333333 x) (* 0.0027777777777778 (/ z x))))
     (if (<= t_0 2.1114119818840957e+307)
       (+
        (fma (log x) (- x 0.5) (- 0.91893853320467 x))
        (/
         (/ 1.0 x)
         (/
          1.0
          (fma
           z
           (fma z (+ y 0.0007936500793651) -0.0027777777777778)
           0.083333333333333))))
       (+
        (/ 0.083333333333333 x)
        (+ (* (- x 0.5) t_1) (fma (- x 0.5) t_1 (- 0.91893853320467 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 t_0 = z * (((y + 0.0007936500793651) * z) - 0.0027777777777778);
	double t_1 = log(sqrt(x));
	double tmp;
	if (t_0 <= -1.371162106624129e+301) {
		tmp = ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + ((0.083333333333333 / x) - (0.0027777777777778 * (z / x)));
	} else if (t_0 <= 2.1114119818840957e+307) {
		tmp = fma(log(x), (x - 0.5), (0.91893853320467 - x)) + ((1.0 / x) / (1.0 / fma(z, fma(z, (y + 0.0007936500793651), -0.0027777777777778), 0.083333333333333)));
	} else {
		tmp = (0.083333333333333 / x) + (((x - 0.5) * t_1) + fma((x - 0.5), t_1, (0.91893853320467 - x)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.2
Target1.3
Herbie3.2
\[\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 3 regimes
  2. if (*.f64 (-.f64 (*.f64 (+.f64 y 7936500793651/10000000000000000) z) 13888888888889/5000000000000000) z) < -1.37116210662412908e301

    1. Initial program 60.8

      \[\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 z around 0 31.6

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{\left(0.083333333333333 \cdot \frac{1}{x} - 0.0027777777777778 \cdot \frac{z}{x}\right)} \]
    3. Simplified31.6

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

    if -1.37116210662412908e301 < (*.f64 (-.f64 (*.f64 (+.f64 y 7936500793651/10000000000000000) z) 13888888888889/5000000000000000) z) < 2.1114119818840957e307

    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 x around 0 0.4

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

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

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

      \[\leadsto \mathsf{fma}\left(\log x, x + -0.5, 0.91893853320467 - x\right) + \frac{1}{\color{blue}{\frac{x}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right), 0.083333333333333\right)}}} \]
    6. Applied div-inv_binary640.3

      \[\leadsto \mathsf{fma}\left(\log x, x + -0.5, 0.91893853320467 - x\right) + \frac{1}{\color{blue}{x \cdot \frac{1}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right), 0.083333333333333\right)}}} \]
    7. Applied associate-/r*_binary640.3

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

    if 2.1114119818840957e307 < (*.f64 (-.f64 (*.f64 (+.f64 y 7936500793651/10000000000000000) z) 13888888888889/5000000000000000) z)

    1. Initial program 63.7

      \[\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. Applied add-sqr-sqrt_binary6463.7

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

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \color{blue}{\left(\log \left(\sqrt{x}\right) + \log \left(\sqrt{x}\right)\right)} - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    4. Applied distribute-rgt-in_binary6463.7

      \[\leadsto \left(\left(\color{blue}{\left(\log \left(\sqrt{x}\right) \cdot \left(x - 0.5\right) + \log \left(\sqrt{x}\right) \cdot \left(x - 0.5\right)\right)} - x\right) + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    5. Applied associate--l+_binary6463.7

      \[\leadsto \left(\color{blue}{\left(\log \left(\sqrt{x}\right) \cdot \left(x - 0.5\right) + \left(\log \left(\sqrt{x}\right) \cdot \left(x - 0.5\right) - x\right)\right)} + 0.91893853320467\right) + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
    6. Applied associate-+l+_binary6463.7

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

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

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

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

Reproduce

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