Average Error: 5.8 → 3.3
Time: 10.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, -x\right) + 0.91893853320467\\ t_1 := z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right)\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_0 + \frac{0.083333333333333}{x}\\ \mathbf{elif}\;t_1 \leq 1.594554769117199 \cdot 10^{+280}:\\ \;\;\;\;t_0 + {\left(\frac{x}{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.083333333333333}{x} + \left(0.91893853320467 + \left(\left(x - 0.5\right) \cdot \log x - 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 (+ (fma (- x 0.5) (log x) (- x)) 0.91893853320467))
        (t_1 (* z (- (* (+ y 0.0007936500793651) z) 0.0027777777777778))))
   (if (<= t_1 (- INFINITY))
     (+ t_0 (/ 0.083333333333333 x))
     (if (<= t_1 1.594554769117199e+280)
       (+
        t_0
        (pow
         (/
          x
          (fma
           z
           (fma (+ y 0.0007936500793651) z -0.0027777777777778)
           0.083333333333333))
         -1.0))
       (+
        (/ 0.083333333333333 x)
        (+ 0.91893853320467 (- (* (- x 0.5) (log x)) 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), -x) + 0.91893853320467;
	double t_1 = z * (((y + 0.0007936500793651) * z) - 0.0027777777777778);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_0 + (0.083333333333333 / x);
	} else if (t_1 <= 1.594554769117199e+280) {
		tmp = t_0 + pow((x / fma(z, fma((y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333)), -1.0);
	} else {
		tmp = (0.083333333333333 / x) + (0.91893853320467 + (((x - 0.5) * log(x)) - 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 = Float64(fma(Float64(x - 0.5), log(x), Float64(-x)) + 0.91893853320467)
	t_1 = Float64(z * Float64(Float64(Float64(y + 0.0007936500793651) * z) - 0.0027777777777778))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(t_0 + Float64(0.083333333333333 / x));
	elseif (t_1 <= 1.594554769117199e+280)
		tmp = Float64(t_0 + (Float64(x / fma(z, fma(Float64(y + 0.0007936500793651), z, -0.0027777777777778), 0.083333333333333)) ^ -1.0));
	else
		tmp = Float64(Float64(0.083333333333333 / x) + Float64(0.91893853320467 + Float64(Float64(Float64(x - 0.5) * log(x)) - 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[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision] + (-x)), $MachinePrecision] + 0.91893853320467), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(N[(N[(y + 0.0007936500793651), $MachinePrecision] * z), $MachinePrecision] - 0.0027777777777778), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(t$95$0 + N[(0.083333333333333 / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1.594554769117199e+280], N[(t$95$0 + N[Power[N[(x / N[(z * N[(N[(y + 0.0007936500793651), $MachinePrecision] * z + -0.0027777777777778), $MachinePrecision] + 0.083333333333333), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], N[(N[(0.083333333333333 / x), $MachinePrecision] + N[(0.91893853320467 + N[(N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $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(x - 0.5, \log x, -x\right) + 0.91893853320467\\
t_1 := z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right)\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_0 + \frac{0.083333333333333}{x}\\

\mathbf{elif}\;t_1 \leq 1.594554769117199 \cdot 10^{+280}:\\
\;\;\;\;t_0 + {\left(\frac{x}{\mathsf{fma}\left(z, \mathsf{fma}\left(y + 0.0007936500793651, z, -0.0027777777777778\right), 0.083333333333333\right)}\right)}^{-1}\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original5.8
Target1.4
Herbie3.3
\[\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) < -inf.0

    1. Initial program 64.0

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

      \[\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. Taylor expanded in z around 0 37.0

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

    if -inf.0 < (*.f64 (-.f64 (*.f64 (+.f64 y 7936500793651/10000000000000000) z) 13888888888889/5000000000000000) z) < 1.59455476911719891e280

    1. Initial program 0.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. 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}} \]

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

    1. Initial program 54.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. Taylor expanded in z around 0 28.7

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

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

Reproduce

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