Average Error: 4.0 → 0.4
Time: 6.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} t_0 := \mathsf{fma}\left(x - 0.5, \log x, 0.91893853320467\right) - x\\ \mathbf{if}\;x \leq 4.0281667929952995 \cdot 10^{+67}:\\ \;\;\;\;t_0 + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0 + z \cdot \left(\left(y + 0.0007936500793651\right) \cdot \frac{z}{x}\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 := \mathsf{fma}\left(x - 0.5, \log x, 0.91893853320467\right) - x\\
\mathbf{if}\;x \leq 4.0281667929952995 \cdot 10^{+67}:\\
\;\;\;\;t_0 + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;t_0 + z \cdot \left(\left(y + 0.0007936500793651\right) \cdot \frac{z}{x}\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 (- (fma (- x 0.5) (log x) 0.91893853320467) x)))
   (if (<= x 4.0281667929952995e+67)
     (+
      t_0
      (/
       (fma
        z
        (fma (+ y 0.0007936500793651) z -0.0027777777777778)
        0.083333333333333)
       x))
     (+ t_0 (* z (* (+ y 0.0007936500793651) (/ z 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 = fma((x - 0.5), log(x), 0.91893853320467) - x;
	double tmp;
	if (x <= 4.0281667929952995e+67) {
		tmp = t_0 + (fma(z, fma((y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333) / x);
	} else {
		tmp = t_0 + (z * ((y + 0.0007936500793651) * (z / x)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original4.0
Target0.9
Herbie0.4
\[\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 < 4.0281667929952995e67

    1. Initial program 0.5

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

      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(x - 0.5, \log x, 0.91893853320467\right) - x\right) + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x}} \]
    3. Applied *-un-lft-identity_binary640.5

      \[\leadsto \left(\mathsf{fma}\left(x - 0.5, \log x, 0.91893853320467\right) - \color{blue}{1 \cdot x}\right) + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x} \]
    4. Applied cancel-sign-sub-inv_binary640.5

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

    if 4.0281667929952995e67 < x

    1. Initial program 9.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. Simplified9.8

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

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

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

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

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

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

Reproduce

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