Average Error: 6.2 → 0.8
Time: 7.0s
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(\log x, 0.5 - x, x\right)\\ \mathbf{if}\;x \leq 1.2 \cdot 10^{+84}:\\ \;\;\;\;\left(0.8444480278083504 - {t_0}^{2}\right) \cdot \frac{1}{t_0 + 0.91893853320467} + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(0.91893853320467 - t_0\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
 (let* ((t_0 (fma (log x) (- 0.5 x) x)))
   (if (<= x 1.2e+84)
     (+
      (* (- 0.8444480278083504 (pow t_0 2.0)) (/ 1.0 (+ t_0 0.91893853320467)))
      (/
       (fma
        z
        (fma (+ y 0.0007936500793651) z -0.0027777777777778)
        0.083333333333333)
       x))
     (+ (- 0.91893853320467 t_0) (* 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 t_0 = fma(log(x), (0.5 - x), x);
	double tmp;
	if (x <= 1.2e+84) {
		tmp = ((0.8444480278083504 - pow(t_0, 2.0)) * (1.0 / (t_0 + 0.91893853320467))) + (fma(z, fma((y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333) / x);
	} else {
		tmp = (0.91893853320467 - t_0) + (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)
	t_0 = fma(log(x), Float64(0.5 - x), x)
	tmp = 0.0
	if (x <= 1.2e+84)
		tmp = Float64(Float64(Float64(0.8444480278083504 - (t_0 ^ 2.0)) * Float64(1.0 / Float64(t_0 + 0.91893853320467))) + Float64(fma(z, fma(Float64(y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333) / x));
	else
		tmp = Float64(Float64(0.91893853320467 - t_0) + 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_] := Block[{t$95$0 = N[(N[Log[x], $MachinePrecision] * N[(0.5 - x), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[x, 1.2e+84], N[(N[(N[(0.8444480278083504 - N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(t$95$0 + 0.91893853320467), $MachinePrecision]), $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 - t$95$0), $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}
t_0 := \mathsf{fma}\left(\log x, 0.5 - x, x\right)\\
\mathbf{if}\;x \leq 1.2 \cdot 10^{+84}:\\
\;\;\;\;\left(0.8444480278083504 - {t_0}^{2}\right) \cdot \frac{1}{t_0 + 0.91893853320467} + \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;\left(0.91893853320467 - t_0\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

Original6.2
Target1.4
Herbie0.8
\[\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 < 1.2e84

    1. Initial program 1.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. Simplified1.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 1.2

      \[\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. Simplified1.2

      \[\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-rr1.2

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

    if 1.2e84 < x

    1. Initial program 12.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. Simplified12.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 z around inf 12.7

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

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

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

Reproduce

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