Average Error: 5.9 → 0.9
Time: 5.2s
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}\;z \leq -6 \cdot 10^{+15}:\\ \;\;\;\;\left(0.91893853320467 - \mathsf{fma}\left(\log x, 0.5 - x, x\right)\right) - \frac{z}{\frac{x}{0.0027777777777778 + z \cdot \left(-0.0007936500793651 - y\right)}}\\ \mathbf{elif}\;z \leq 3.05 \cdot 10^{+66}:\\ \;\;\;\;\left(0.91893853320467 - \mathsf{fma}\left(0.5 - x, \log x, x\right)\right) + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(0.91893853320467 - \left(x + \log x \cdot \left(0.5 - x\right)\right)\right) + z \cdot \left(z \cdot \frac{y + 0.0007936500793651}{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
 (if (<= z -6e+15)
   (-
    (- 0.91893853320467 (fma (log x) (- 0.5 x) x))
    (/ z (/ x (+ 0.0027777777777778 (* z (- -0.0007936500793651 y))))))
   (if (<= z 3.05e+66)
     (+
      (- 0.91893853320467 (fma (- 0.5 x) (log x) x))
      (/
       (fma
        z
        (fma (+ y 0.0007936500793651) z -0.0027777777777778)
        0.083333333333333)
       x))
     (+
      (- 0.91893853320467 (+ x (* (log x) (- 0.5 x))))
      (* z (* z (/ (+ y 0.0007936500793651) 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 (z <= -6e+15) {
		tmp = (0.91893853320467 - fma(log(x), (0.5 - x), x)) - (z / (x / (0.0027777777777778 + (z * (-0.0007936500793651 - y)))));
	} else if (z <= 3.05e+66) {
		tmp = (0.91893853320467 - fma((0.5 - x), log(x), x)) + (fma(z, fma((y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333) / x);
	} else {
		tmp = (0.91893853320467 - (x + (log(x) * (0.5 - x)))) + (z * (z * ((y + 0.0007936500793651) / x)));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(Float64(Float64(Float64(x - 0.5) * log(x)) - x) + 0.91893853320467) + Float64(Float64(Float64(Float64(Float64(Float64(y + 0.0007936500793651) * z) - 0.0027777777777778) * z) + 0.083333333333333) / x))
end
function code(x, y, z)
	tmp = 0.0
	if (z <= -6e+15)
		tmp = Float64(Float64(0.91893853320467 - fma(log(x), Float64(0.5 - x), x)) - Float64(z / Float64(x / Float64(0.0027777777777778 + Float64(z * Float64(-0.0007936500793651 - y))))));
	elseif (z <= 3.05e+66)
		tmp = Float64(Float64(0.91893853320467 - fma(Float64(0.5 - x), log(x), x)) + Float64(fma(z, fma(Float64(y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333) / x));
	else
		tmp = Float64(Float64(0.91893853320467 - Float64(x + Float64(log(x) * Float64(0.5 - x)))) + Float64(z * Float64(z * Float64(Float64(y + 0.0007936500793651) / x))));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] + 0.91893853320467), $MachinePrecision] + N[(N[(N[(N[(N[(N[(y + 0.0007936500793651), $MachinePrecision] * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision] * z), $MachinePrecision] + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[z, -6e+15], N[(N[(0.91893853320467 - N[(N[Log[x], $MachinePrecision] * N[(0.5 - x), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] - N[(z / N[(x / N[(0.0027777777777778 + N[(z * N[(-0.0007936500793651 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.05e+66], N[(N[(0.91893853320467 - N[(N[(0.5 - x), $MachinePrecision] * N[Log[x], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] + N[(N[(z * N[(N[(y + 0.0007936500793651), $MachinePrecision] * z + -0.0027777777777778), $MachinePrecision] + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(0.91893853320467 - N[(x + N[(N[Log[x], $MachinePrecision] * N[(0.5 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z * N[(z * N[(N[(y + 0.0007936500793651), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\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}\;z \leq -6 \cdot 10^{+15}:\\
\;\;\;\;\left(0.91893853320467 - \mathsf{fma}\left(\log x, 0.5 - x, x\right)\right) - \frac{z}{\frac{x}{0.0027777777777778 + z \cdot \left(-0.0007936500793651 - y\right)}}\\

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

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original5.9
Target1.2
Herbie0.9
\[\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 z < -6e15

    1. Initial program 21.9

      \[\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. Simplified21.9

      \[\leadsto \color{blue}{\left(0.91893853320467 - \mathsf{fma}\left(\log x, 0.5 - x, x\right)\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 inf 22.6

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

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

    if -6e15 < z < 3.0500000000000001e66

    1. Initial program 0.6

      \[\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.6

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

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

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

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

    if 3.0500000000000001e66 < z

    1. Initial program 31.1

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

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

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

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

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

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

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

Reproduce

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