Average Error: 11.0 → 1.2
Time: 37.8s
Precision: binary64
Cost: 19844
\[\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x} \]
\[\begin{array}{l} \mathbf{if}\;y \leq 5.8 \cdot 10^{-6}:\\ \;\;\;\;\frac{{\left(e^{x}\right)}^{\log \left(\frac{x}{x + y}\right)}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(e^{x}\right)}^{\left(\frac{-1}{x}\right)}}{x}\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (exp (* x (log (/ x (+ x y))))) x))
(FPCore (x y)
 :precision binary64
 (if (<= y 5.8e-6)
   (/ (pow (exp x) (log (/ x (+ x y)))) x)
   (/ (pow (exp x) (/ -1.0 x)) x)))
double code(double x, double y) {
	return exp((x * log((x / (x + y))))) / x;
}
double code(double x, double y) {
	double tmp;
	if (y <= 5.8e-6) {
		tmp = pow(exp(x), log((x / (x + y)))) / x;
	} else {
		tmp = pow(exp(x), (-1.0 / x)) / x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = exp((x * log((x / (x + y))))) / x
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 5.8d-6) then
        tmp = (exp(x) ** log((x / (x + y)))) / x
    else
        tmp = (exp(x) ** ((-1.0d0) / x)) / x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	return Math.exp((x * Math.log((x / (x + y))))) / x;
}
public static double code(double x, double y) {
	double tmp;
	if (y <= 5.8e-6) {
		tmp = Math.pow(Math.exp(x), Math.log((x / (x + y)))) / x;
	} else {
		tmp = Math.pow(Math.exp(x), (-1.0 / x)) / x;
	}
	return tmp;
}
def code(x, y):
	return math.exp((x * math.log((x / (x + y))))) / x
def code(x, y):
	tmp = 0
	if y <= 5.8e-6:
		tmp = math.pow(math.exp(x), math.log((x / (x + y)))) / x
	else:
		tmp = math.pow(math.exp(x), (-1.0 / x)) / x
	return tmp
function code(x, y)
	return Float64(exp(Float64(x * log(Float64(x / Float64(x + y))))) / x)
end
function code(x, y)
	tmp = 0.0
	if (y <= 5.8e-6)
		tmp = Float64((exp(x) ^ log(Float64(x / Float64(x + y)))) / x);
	else
		tmp = Float64((exp(x) ^ Float64(-1.0 / x)) / x);
	end
	return tmp
end
function tmp = code(x, y)
	tmp = exp((x * log((x / (x + y))))) / x;
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 5.8e-6)
		tmp = (exp(x) ^ log((x / (x + y)))) / x;
	else
		tmp = (exp(x) ^ (-1.0 / x)) / x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := N[(N[Exp[N[(x * N[Log[N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]
code[x_, y_] := If[LessEqual[y, 5.8e-6], N[(N[Power[N[Exp[x], $MachinePrecision], N[Log[N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision], N[(N[Power[N[Exp[x], $MachinePrecision], N[(-1.0 / x), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]]
\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x}
\begin{array}{l}
\mathbf{if}\;y \leq 5.8 \cdot 10^{-6}:\\
\;\;\;\;\frac{{\left(e^{x}\right)}^{\log \left(\frac{x}{x + y}\right)}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{{\left(e^{x}\right)}^{\left(\frac{-1}{x}\right)}}{x}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.0
Target7.8
Herbie1.2
\[\begin{array}{l} \mathbf{if}\;y < -3.7311844206647956 \cdot 10^{+94}:\\ \;\;\;\;\frac{e^{\frac{-1}{y}}}{x}\\ \mathbf{elif}\;y < 2.817959242728288 \cdot 10^{+37}:\\ \;\;\;\;\frac{{\left(\frac{x}{y + x}\right)}^{x}}{x}\\ \mathbf{elif}\;y < 2.347387415166998 \cdot 10^{+178}:\\ \;\;\;\;\log \left(e^{\frac{{\left(\frac{x}{y + x}\right)}^{x}}{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{-1}{y}}}{x}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if y < 5.8000000000000004e-6

    1. Initial program 4.4

      \[\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x} \]
    2. Simplified0.8

      \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{\log \left(\frac{x}{x + y}\right)}}{x}} \]
      Proof

    if 5.8000000000000004e-6 < y

    1. Initial program 32.3

      \[\frac{e^{x \cdot \log \left(\frac{x}{x + y}\right)}}{x} \]
    2. Simplified22.2

      \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{\log \left(\frac{x}{x + y}\right)}}{x}} \]
      Proof
    3. Taylor expanded in x around -inf 2.5

      \[\leadsto \frac{{\left(e^{x}\right)}^{\color{blue}{\left(\frac{-1}{x}\right)}}}{x} \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error1.4
Cost13316
\[\begin{array}{l} \mathbf{if}\;y \leq 5.8 \cdot 10^{-6}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(e^{x}\right)}^{\left(\frac{-1}{x}\right)}}{x}\\ \end{array} \]
Alternative 2
Error6.5
Cost7176
\[\begin{array}{l} \mathbf{if}\;y \leq 195:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+190}:\\ \;\;\;\;3 - \left(3 + \left(-\frac{e^{-1}}{x}\right)\right)\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+234}:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;1 - \left(1 + \frac{1}{x \cdot x}\right)\\ \end{array} \]
Alternative 3
Error7.3
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq 345:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+190}:\\ \;\;\;\;1 - \left(1 + \frac{1}{x \cdot x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 4
Error9.8
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq 300:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{elif}\;y \leq 3.55 \cdot 10^{+36}:\\ \;\;\;\;\frac{-1}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x}\\ \end{array} \]
Alternative 5
Error9.7
Cost192
\[\frac{1}{x} \]
Alternative 6
Error61.8
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2023010 
(FPCore (x y)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, F"
  :precision binary64

  :herbie-target
  (if (< y -3.7311844206647956e+94) (/ (exp (/ -1.0 y)) x) (if (< y 2.817959242728288e+37) (/ (pow (/ x (+ y x)) x) x) (if (< y 2.347387415166998e+178) (log (exp (/ (pow (/ x (+ y x)) x) x))) (/ (exp (/ -1.0 y)) x))))

  (/ (exp (* x (log (/ x (+ x y))))) x))