Average Error: 6.1 → 2.7
Time: 14.3s
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 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ t_1 := t_0 + \frac{0.083333333333333 - z \cdot 0.0027777777777778}{x}\\ t_2 := \frac{z \cdot z}{x}\\ \mathbf{if}\;z \leq -1.3543156149683942 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -0.00019444066752115447:\\ \;\;\;\;\left(0.91893853320467 + \mathsf{fma}\left(x - 0.5, \log x, -x\right)\right) + \mathsf{fma}\left(0.0007936500793651, t_2, \mathsf{fma}\left(\frac{y}{x}, z \cdot z, \frac{z}{x} \cdot -0.0027777777777778\right)\right)\\ \mathbf{elif}\;z \leq 48939846456029.02:\\ \;\;\;\;\left(0.91893853320467 + \mathsf{fma}\left(\log x, x - 0.5, -x\right)\right) + \frac{\frac{1}{x}}{\frac{1}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right), 0.083333333333333\right)}}\\ \mathbf{elif}\;z \leq 2.1822361911060752 \cdot 10^{+120}:\\ \;\;\;\;t_0 + t_2 \cdot \left(0.0007936500793651 + y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\
t_1 := t_0 + \frac{0.083333333333333 - z \cdot 0.0027777777777778}{x}\\
t_2 := \frac{z \cdot z}{x}\\
\mathbf{if}\;z \leq -1.3543156149683942 \cdot 10^{+154}:\\
\;\;\;\;t_1\\

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

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

\mathbf{elif}\;z \leq 2.1822361911060752 \cdot 10^{+120}:\\
\;\;\;\;t_0 + t_2 \cdot \left(0.0007936500793651 + y\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\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 (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467))
        (t_1 (+ t_0 (/ (- 0.083333333333333 (* z 0.0027777777777778)) x)))
        (t_2 (/ (* z z) x)))
   (if (<= z -1.3543156149683942e+154)
     t_1
     (if (<= z -0.00019444066752115447)
       (+
        (+ 0.91893853320467 (fma (- x 0.5) (log x) (- x)))
        (fma
         0.0007936500793651
         t_2
         (fma (/ y x) (* z z) (* (/ z x) -0.0027777777777778))))
       (if (<= z 48939846456029.02)
         (+
          (+ 0.91893853320467 (fma (log x) (- x 0.5) (- x)))
          (/
           (/ 1.0 x)
           (/
            1.0
            (fma
             z
             (fma z (+ 0.0007936500793651 y) -0.0027777777777778)
             0.083333333333333))))
         (if (<= z 2.1822361911060752e+120)
           (+ t_0 (* t_2 (+ 0.0007936500793651 y)))
           t_1))))))
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 = (((x - 0.5) * log(x)) - x) + 0.91893853320467;
	double t_1 = t_0 + ((0.083333333333333 - (z * 0.0027777777777778)) / x);
	double t_2 = (z * z) / x;
	double tmp;
	if (z <= -1.3543156149683942e+154) {
		tmp = t_1;
	} else if (z <= -0.00019444066752115447) {
		tmp = (0.91893853320467 + fma((x - 0.5), log(x), -x)) + fma(0.0007936500793651, t_2, fma((y / x), (z * z), ((z / x) * -0.0027777777777778)));
	} else if (z <= 48939846456029.02) {
		tmp = (0.91893853320467 + fma(log(x), (x - 0.5), -x)) + ((1.0 / x) / (1.0 / fma(z, fma(z, (0.0007936500793651 + y), -0.0027777777777778), 0.083333333333333)));
	} else if (z <= 2.1822361911060752e+120) {
		tmp = t_0 + (t_2 * (0.0007936500793651 + y));
	} else {
		tmp = t_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.1
Target1.1
Herbie2.7
\[\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 4 regimes
  2. if z < -1.3543156149683942e154 or 2.18223619110607522e120 < z

    1. Initial program 54.3

      \[\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 28.0

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

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

    if -1.3543156149683942e154 < z < -1.94440667521154469e-4

    1. Initial program 8.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. Applied egg-rr8.5

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

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

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

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

    if -1.94440667521154469e-4 < z < 48939846456029.0234

    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. Applied egg-rr0.3

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

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

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

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

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

    if 48939846456029.0234 < z < 2.18223619110607522e120

    1. Initial program 6.2

      \[\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 inf 6.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.3543156149683942 \cdot 10^{+154}:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{0.083333333333333 - z \cdot 0.0027777777777778}{x}\\ \mathbf{elif}\;z \leq -0.00019444066752115447:\\ \;\;\;\;\left(0.91893853320467 + \mathsf{fma}\left(x - 0.5, \log x, -x\right)\right) + \mathsf{fma}\left(0.0007936500793651, \frac{z \cdot z}{x}, \mathsf{fma}\left(\frac{y}{x}, z \cdot z, \frac{z}{x} \cdot -0.0027777777777778\right)\right)\\ \mathbf{elif}\;z \leq 48939846456029.02:\\ \;\;\;\;\left(0.91893853320467 + \mathsf{fma}\left(\log x, x - 0.5, -x\right)\right) + \frac{\frac{1}{x}}{\frac{1}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right), 0.083333333333333\right)}}\\ \mathbf{elif}\;z \leq 2.1822361911060752 \cdot 10^{+120}:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{z \cdot z}{x} \cdot \left(0.0007936500793651 + y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{0.083333333333333 - z \cdot 0.0027777777777778}{x}\\ \end{array} \]

Reproduce

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