Average Error: 6.2 → 1.3
Time: 32.0s
Precision: binary64
Cost: 14404
\[\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(z, 0.0007936500793651 + y, -0.0027777777777778\right)\\ \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\frac{0.083333333333333}{x} + \begin{array}{l} \mathbf{if}\;z \ne 0:\\ \;\;\;\;\frac{t_0}{\frac{x}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \frac{z}{x}\\ \end{array}\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 z (+ 0.0007936500793651 y) -0.0027777777777778)))
   (+
    (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467)
    (+
     (/ 0.083333333333333 x)
     (if (!= z 0.0) (/ t_0 (/ x z)) (* t_0 (/ 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(z, (0.0007936500793651 + y), -0.0027777777777778);
	double tmp;
	if (z != 0.0) {
		tmp = t_0 / (x / z);
	} else {
		tmp = t_0 * (z / x);
	}
	return ((((x - 0.5) * log(x)) - x) + 0.91893853320467) + ((0.083333333333333 / x) + 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(z, Float64(0.0007936500793651 + y), -0.0027777777777778)
	tmp = 0.0
	if (z != 0.0)
		tmp = Float64(t_0 / Float64(x / z));
	else
		tmp = Float64(t_0 * Float64(z / x));
	end
	return Float64(Float64(Float64(Float64(Float64(x - 0.5) * log(x)) - x) + 0.91893853320467) + Float64(Float64(0.083333333333333 / x) + 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[(z * N[(0.0007936500793651 + y), $MachinePrecision] + -0.0027777777777778), $MachinePrecision]}, N[(N[(N[(N[(N[(x - 0.5), $MachinePrecision] * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] + 0.91893853320467), $MachinePrecision] + N[(N[(0.083333333333333 / x), $MachinePrecision] + If[Unequal[z, 0.0], N[(t$95$0 / N[(x / z), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(z / 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(z, 0.0007936500793651 + y, -0.0027777777777778\right)\\
\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\frac{0.083333333333333}{x} + \begin{array}{l}
\mathbf{if}\;z \ne 0:\\
\;\;\;\;\frac{t_0}{\frac{x}{z}}\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{z}{x}\\


\end{array}\right)
\end{array}

Error

Target

Original6.2
Target1.3
Herbie1.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. 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 0 6.2

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

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

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

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

    \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\frac{0.083333333333333}{x} + \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;z \ne 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right)}{\frac{x}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{x} \cdot \mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right)\\ } \end{array}}\right) \]
  7. Simplified1.3

    \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\frac{0.083333333333333}{x} + \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;z \ne 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right)}{\frac{x}{z}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right) \cdot \frac{z}{x}\\ } \end{array}}\right) \]
    Proof

Alternatives

Alternative 1
Error1.3
Cost14272
\[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \left(\frac{0.083333333333333}{x} + \frac{z}{x} \cdot \mathsf{fma}\left(z, 0.0007936500793651 + y, -0.0027777777777778\right)\right) \]
Alternative 2
Error3.4
Cost13636
\[\begin{array}{l} \mathbf{if}\;x \leq 2.16 \cdot 10^{+136}:\\ \;\;\;\;\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{\left(\left(\left(y + 0.0007936500793651\right) \cdot z\right) \cdot z + z \cdot -0.0027777777777778\right) + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \frac{0.083333333333333}{x}\\ \end{array} \]
Alternative 3
Error7.2
Cost8136
\[\begin{array}{l} t_0 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ t_1 := t_0 + \frac{y \cdot \left(z \cdot z\right) + 0.083333333333333}{x}\\ \mathbf{if}\;y \leq -1.3 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+69}:\\ \;\;\;\;t_0 + \frac{1}{x} \cdot \left(\left(0.0007936500793651 \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error3.5
Cost8132
\[\begin{array}{l} t_0 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ \mathbf{if}\;x \leq 2.1 \cdot 10^{+136}:\\ \;\;\;\;t_0 + \frac{\left(\left(\left(y + 0.0007936500793651\right) \cdot z\right) \cdot z + z \cdot -0.0027777777777778\right) + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{0.083333333333333}{x}\\ \end{array} \]
Alternative 5
Error7.6
Cost8008
\[\begin{array}{l} t_0 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ \mathbf{if}\;y \leq -2.5 \cdot 10^{+59}:\\ \;\;\;\;t_0 + \frac{y \cdot \left(z \cdot z\right) + 0.083333333333333}{x}\\ \mathbf{elif}\;y \leq 2.95 \cdot 10^{+161}:\\ \;\;\;\;t_0 + \frac{\left(0.0007936500793651 \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{1}{x} \cdot \left(z \cdot \left(z \cdot y\right) + 0.083333333333333\right)\\ \end{array} \]
Alternative 6
Error3.5
Cost8004
\[\begin{array}{l} t_0 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ \mathbf{if}\;x \leq 4 \cdot 10^{+134}:\\ \;\;\;\;t_0 + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{0.083333333333333}{x}\\ \end{array} \]
Alternative 7
Error7.8
Cost7876
\[\begin{array}{l} t_0 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ \mathbf{if}\;x \leq 10^{+134}:\\ \;\;\;\;t_0 + \frac{1}{x} \cdot \left(z \cdot \left(z \cdot y\right) + 0.083333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{0.083333333333333}{x}\\ \end{array} \]
Alternative 8
Error10.8
Cost7752
\[\begin{array}{l} t_0 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ \mathbf{if}\;x \leq 475:\\ \;\;\;\;\left(\left(0.91893853320467 - x\right) - \left(0.5 - x\right) \cdot \log x\right) + \frac{0.083333333333333}{x}\\ \mathbf{elif}\;x \leq 10^{+134}:\\ \;\;\;\;t_0 + \frac{y \cdot \left(z \cdot z\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{0.083333333333333}{x}\\ \end{array} \]
Alternative 9
Error10.7
Cost7752
\[\begin{array}{l} t_0 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ \mathbf{if}\;x \leq 840:\\ \;\;\;\;\left(\left(0.91893853320467 - x\right) - \left(0.5 - x\right) \cdot \log x\right) + \frac{0.083333333333333}{x}\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{+135}:\\ \;\;\;\;t_0 + \frac{z \cdot \left(z \cdot y\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{0.083333333333333}{x}\\ \end{array} \]
Alternative 10
Error7.8
Cost7748
\[\begin{array}{l} t_0 := \left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\\ \mathbf{if}\;x \leq 2.5 \cdot 10^{+134}:\\ \;\;\;\;t_0 + \frac{y \cdot \left(z \cdot z\right) + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{0.083333333333333}{x}\\ \end{array} \]
Alternative 11
Error12.3
Cost7232
\[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \frac{0.083333333333333}{x} \]
Alternative 12
Error12.3
Cost7232
\[\left(\left(0.91893853320467 - x\right) - \left(0.5 - x\right) \cdot \log x\right) + \frac{0.083333333333333}{x} \]
Alternative 13
Error43.4
Cost192
\[\frac{0.083333333333333}{x} \]

Error

Reproduce

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