Average Error: 0.1 → 0.8
Time: 6.8s
Precision: binary64
Cost: 7108
\[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
\[\begin{array}{l} \mathbf{if}\;y \leq 9.989230204048188 \cdot 10^{-18}:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(y + \left(x - y \cdot \log y\right)\right) - z\\ \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
(FPCore (x y z)
 :precision binary64
 (if (<= y 9.989230204048188e-18)
   (- (+ x (* (log y) -0.5)) z)
   (- (+ y (- x (* y (log y)))) z)))
double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * log(y))) + y) - z;
}
double code(double x, double y, double z) {
	double tmp;
	if (y <= 9.989230204048188e-18) {
		tmp = (x + (log(y) * -0.5)) - z;
	} else {
		tmp = (y + (x - (y * log(y)))) - z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= 9.989230204048188d-18) then
        tmp = (x + (log(y) * (-0.5d0))) - z
    else
        tmp = (y + (x - (y * log(y)))) - z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 9.989230204048188e-18) {
		tmp = (x + (Math.log(y) * -0.5)) - z;
	} else {
		tmp = (y + (x - (y * Math.log(y)))) - z;
	}
	return tmp;
}
def code(x, y, z):
	return ((x - ((y + 0.5) * math.log(y))) + y) - z
def code(x, y, z):
	tmp = 0
	if y <= 9.989230204048188e-18:
		tmp = (x + (math.log(y) * -0.5)) - z
	else:
		tmp = (y + (x - (y * math.log(y)))) - z
	return tmp
function code(x, y, z)
	return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z)
end
function code(x, y, z)
	tmp = 0.0
	if (y <= 9.989230204048188e-18)
		tmp = Float64(Float64(x + Float64(log(y) * -0.5)) - z);
	else
		tmp = Float64(Float64(y + Float64(x - Float64(y * log(y)))) - z);
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = ((x - ((y + 0.5) * log(y))) + y) - z;
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 9.989230204048188e-18)
		tmp = (x + (log(y) * -0.5)) - z;
	else
		tmp = (y + (x - (y * log(y)))) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[y, 9.989230204048188e-18], N[(N[(x + N[(N[Log[y], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(y + N[(x - N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\begin{array}{l}
\mathbf{if}\;y \leq 9.989230204048188 \cdot 10^{-18}:\\
\;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.1
Target0.1
Herbie0.8
\[\left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y \]

Derivation

  1. Split input into 2 regimes
  2. if y < 9.9892302040481884e-18

    1. Initial program 0.0

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Taylor expanded in y around 0 0.0

      \[\leadsto \color{blue}{\left(x - 0.5 \cdot \log y\right)} - z \]

    if 9.9892302040481884e-18 < y

    1. Initial program 0.2

      \[\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z \]
    2. Taylor expanded in y around inf 1.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9.989230204048188 \cdot 10^{-18}:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{else}:\\ \;\;\;\;\left(y + \left(x - y \cdot \log y\right)\right) - z\\ \end{array} \]

Alternatives

Alternative 1
Error10.4
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq 1.837728219707568 \cdot 10^{+127}:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 2
Error6.9
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq 4.857437768494244 \cdot 10^{+49}:\\ \;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right) - z\\ \end{array} \]
Alternative 3
Error18.9
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq 1.837728219707568 \cdot 10^{+127}:\\ \;\;\;\;x - z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \log y\right)\\ \end{array} \]
Alternative 4
Error32.3
Cost392
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6044267187032467 \cdot 10^{+101}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.2096011050043892 \cdot 10^{+38}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error25.7
Cost192
\[x - z \]
Alternative 6
Error44.4
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022228 
(FPCore (x y z)
  :name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (- (- (+ y x) z) (* (+ y 0.5) (log y)))

  (- (+ (- x (* (+ y 0.5) (log y))) y) z))