Average Error: 6.1 → 0.5
Time: 19.7s
Precision: binary64
Cost: 15432
\[\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 := z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right)\\ t_1 := z \cdot \left(z \cdot \frac{y + 0.0007936500793651}{x}\right) + \left(x \cdot \log x - x\right)\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+148}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 3.2 \cdot 10^{+99}:\\ \;\;\;\;\mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \frac{t_0 + 0.083333333333333}{x}\\ \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 (* z (+ (* (+ y 0.0007936500793651) z) -0.0027777777777778)))
        (t_1
         (+ (* z (* z (/ (+ y 0.0007936500793651) x))) (- (* x (log x)) x))))
   (if (<= t_0 -1e+148)
     t_1
     (if (<= t_0 3.2e+99)
       (+
        (fma (+ x -0.5) (log x) (- 0.91893853320467 x))
        (/ (+ t_0 0.083333333333333) x))
       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 = z * (((y + 0.0007936500793651) * z) + -0.0027777777777778);
	double t_1 = (z * (z * ((y + 0.0007936500793651) / x))) + ((x * log(x)) - x);
	double tmp;
	if (t_0 <= -1e+148) {
		tmp = t_1;
	} else if (t_0 <= 3.2e+99) {
		tmp = fma((x + -0.5), log(x), (0.91893853320467 - x)) + ((t_0 + 0.083333333333333) / x);
	} else {
		tmp = t_1;
	}
	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(z * Float64(Float64(Float64(y + 0.0007936500793651) * z) + -0.0027777777777778))
	t_1 = Float64(Float64(z * Float64(z * Float64(Float64(y + 0.0007936500793651) / x))) + Float64(Float64(x * log(x)) - x))
	tmp = 0.0
	if (t_0 <= -1e+148)
		tmp = t_1;
	elseif (t_0 <= 3.2e+99)
		tmp = Float64(fma(Float64(x + -0.5), log(x), Float64(0.91893853320467 - x)) + Float64(Float64(t_0 + 0.083333333333333) / x));
	else
		tmp = t_1;
	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[(z * N[(N[(N[(y + 0.0007936500793651), $MachinePrecision] * z), $MachinePrecision] + -0.0027777777777778), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(z * N[(z * N[(N[(y + 0.0007936500793651), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(x * N[Log[x], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+148], t$95$1, If[LessEqual[t$95$0, 3.2e+99], N[(N[(N[(x + -0.5), $MachinePrecision] * N[Log[x], $MachinePrecision] + N[(0.91893853320467 - x), $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$0 + 0.083333333333333), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], t$95$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}
\begin{array}{l}
t_0 := z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right)\\
t_1 := z \cdot \left(z \cdot \frac{y + 0.0007936500793651}{x}\right) + \left(x \cdot \log x - x\right)\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+148}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 3.2 \cdot 10^{+99}:\\
\;\;\;\;\mathsf{fma}\left(x + -0.5, \log x, 0.91893853320467 - x\right) + \frac{t_0 + 0.083333333333333}{x}\\

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


\end{array}

Error

Target

Original6.1
Target1.2
Herbie0.5
\[\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 (*.f64 (-.f64 (*.f64 (+.f64 y 7936500793651/10000000000000000) z) 13888888888889/5000000000000000) z) < -1e148 or 3.19999999999999999e99 < (*.f64 (-.f64 (*.f64 (+.f64 y 7936500793651/10000000000000000) z) 13888888888889/5000000000000000) z)

    1. Initial program 23.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. Taylor expanded in z around inf 23.7

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

      \[\leadsto \left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.91893853320467\right) + \color{blue}{z \cdot \left(z \cdot \frac{0.0007936500793651 + y}{x}\right)} \]
      Proof
      (*.f64 z (*.f64 z (/.f64 (+.f64 7936500793651/10000000000000000 y) x))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (*.f64 (Rewrite<= /-rgt-identity_binary64 (/.f64 z 1)) (/.f64 (+.f64 7936500793651/10000000000000000 y) x))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (Rewrite<= times-frac_binary64 (/.f64 (*.f64 z (+.f64 7936500793651/10000000000000000 y)) (*.f64 1 x)))): 31 points increase in error, 34 points decrease in error
      (*.f64 z (/.f64 (*.f64 z (+.f64 7936500793651/10000000000000000 y)) (Rewrite=> *-lft-identity_binary64 x))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 z (*.f64 z (+.f64 7936500793651/10000000000000000 y))) x)): 58 points increase in error, 29 points decrease in error
      (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (+.f64 7936500793651/10000000000000000 y))) x): 22 points increase in error, 33 points decrease in error
      (/.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) (+.f64 7936500793651/10000000000000000 y)) x): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in x around inf 1.1

      \[\leadsto \color{blue}{\left(-1 \cdot \log \left(\frac{1}{x}\right) - 1\right) \cdot x} + z \cdot \left(z \cdot \frac{0.0007936500793651 + y}{x}\right) \]
    5. Simplified1.2

      \[\leadsto \color{blue}{\left(x \cdot \log x - x\right)} + z \cdot \left(z \cdot \frac{0.0007936500793651 + y}{x}\right) \]
      Proof
      (-.f64 (*.f64 x (log.f64 x)) x): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 x (log.f64 x)) (Rewrite<= *-rgt-identity_binary64 (*.f64 x 1))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> distribute-lft-out--_binary64 (*.f64 x (-.f64 (log.f64 x) 1))): 29 points increase in error, 36 points decrease in error
      (*.f64 x (-.f64 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (log.f64 x)))) 1)): 0 points increase in error, 0 points decrease in error
      (*.f64 x (-.f64 (neg.f64 (Rewrite<= log-rec_binary64 (log.f64 (/.f64 1 x)))) 1)): 0 points increase in error, 1 points decrease in error
      (*.f64 x (-.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (log.f64 (/.f64 1 x)))) 1)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 (*.f64 -1 (log.f64 (/.f64 1 x))) 1) x)): 0 points increase in error, 0 points decrease in error

    if -1e148 < (*.f64 (-.f64 (*.f64 (+.f64 y 7936500793651/10000000000000000) z) 13888888888889/5000000000000000) z) < 3.19999999999999999e99

    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.8

      \[\leadsto \left(\color{blue}{{\left(\sqrt[3]{\left(x + -0.5\right) \cdot \log x - x}\right)}^{3}} + 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 \color{blue}{\mathsf{fma}\left(x + -0.5, \log x, -\left(x - 0.91893853320467\right)\right)} + \frac{\left(\left(y + 0.0007936500793651\right) \cdot z - 0.0027777777777778\right) \cdot z + 0.083333333333333}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error0.6
Cost9160
\[\begin{array}{l} t_0 := z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right)\\ t_1 := z \cdot \left(z \cdot \frac{y + 0.0007936500793651}{x}\right) + \left(x \cdot \log x - x\right)\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+148}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+93}:\\ \;\;\;\;\frac{t_0 + 0.083333333333333}{x} + \left(0.91893853320467 - \left(x + \log x \cdot \left(0.5 - x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.8
Cost7876
\[\begin{array}{l} \mathbf{if}\;x \leq 0.01:\\ \;\;\;\;\frac{0.083333333333333}{x} + \left(\left(0.91893853320467 + \frac{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right)}{x}\right) + \log x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{y + 0.0007936500793651}{x}\right) + \left(0.91893853320467 - \left(x + \log x \cdot \left(0.5 - x\right)\right)\right)\\ \end{array} \]
Alternative 3
Error1.1
Cost7748
\[\begin{array}{l} \mathbf{if}\;x \leq 0.01:\\ \;\;\;\;\frac{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right) + 0.083333333333333}{x} + \left(0.91893853320467 + \log x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{y + 0.0007936500793651}{x}\right) + \left(x \cdot \log x - x\right)\\ \end{array} \]
Alternative 4
Error0.8
Cost7748
\[\begin{array}{l} \mathbf{if}\;x \leq 0.01:\\ \;\;\;\;\frac{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right) + 0.083333333333333}{x} + \left(0.91893853320467 + \log x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{y + 0.0007936500793651}{x}\right) + \left(0.91893853320467 - \left(x + \log x \cdot \left(0.5 - x\right)\right)\right)\\ \end{array} \]
Alternative 5
Error1.3
Cost7492
\[\begin{array}{l} \mathbf{if}\;x \leq 0.01:\\ \;\;\;\;0.91893853320467 + \frac{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right) + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \frac{y + 0.0007936500793651}{x}\right) + \left(x \cdot \log x - x\right)\\ \end{array} \]
Alternative 6
Error6.8
Cost7364
\[\begin{array}{l} \mathbf{if}\;x \leq 4.8 \cdot 10^{-15}:\\ \;\;\;\;0.91893853320467 + \frac{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right) + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(0.91893853320467 - \left(x + \log x \cdot \left(0.5 - x\right)\right)\right) + \frac{0.083333333333333}{x}\\ \end{array} \]
Alternative 7
Error7.1
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 3200000000000:\\ \;\;\;\;0.91893853320467 + \frac{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right) + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \log x - x\\ \end{array} \]
Alternative 8
Error7.1
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 3200000000000:\\ \;\;\;\;0.91893853320467 + \frac{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right) + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\log x + -1\right)\\ \end{array} \]
Alternative 9
Error31.5
Cost1224
\[\begin{array}{l} t_0 := \frac{0.083333333333333}{x} + z \cdot \left(\left(y + 0.0007936500793651\right) \cdot \frac{z}{x}\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10^{+110}:\\ \;\;\;\;0.91893853320467 + \frac{z \cdot \left(\left(y + 0.0007936500793651\right) \cdot z + -0.0027777777777778\right) + 0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error32.6
Cost1092
\[\begin{array}{l} \mathbf{if}\;x \leq 10^{-168}:\\ \;\;\;\;\frac{0.083333333333333}{x} + \frac{y}{\frac{x}{z \cdot z}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y + 0.0007936500793651\right) \cdot \frac{z}{x}\right) + \frac{\frac{1}{x}}{12.000000000000048}\\ \end{array} \]
Alternative 11
Error39.1
Cost968
\[\begin{array}{l} t_0 := \frac{0.083333333333333}{x} + \frac{z \cdot z}{\frac{x}{y}}\\ \mathbf{if}\;z \leq -1.7426544281853126 \cdot 10^{-82}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.0937595132892643 \cdot 10^{-125}:\\ \;\;\;\;\frac{0.083333333333333}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error32.7
Cost964
\[\begin{array}{l} \mathbf{if}\;x \leq 10^{-168}:\\ \;\;\;\;\frac{0.083333333333333}{x} + \frac{y}{\frac{x}{z \cdot z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.083333333333333}{x} + z \cdot \left(\left(y + 0.0007936500793651\right) \cdot \frac{z}{x}\right)\\ \end{array} \]
Alternative 13
Error37.9
Cost704
\[\frac{0.083333333333333}{x} + \frac{y}{\frac{x}{z \cdot z}} \]
Alternative 14
Error43.1
Cost192
\[\frac{0.083333333333333}{x} \]

Error

Reproduce

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