Average Error: 0.8 → 0.4
Time: 10.6s
Precision: binary64
Cost: 20040
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} t_0 := \frac{1}{1 + e^{b}}\\ \mathbf{if}\;e^{b} \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 2:\\ \;\;\;\;\frac{1}{1 + \frac{b + 1}{e^{a}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (/ 1.0 (+ 1.0 (exp b)))))
   (if (<= (exp b) 0.0)
     t_0
     (if (<= (exp b) 2.0) (/ 1.0 (+ 1.0 (/ (+ b 1.0) (exp a)))) t_0))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double t_0 = 1.0 / (1.0 + exp(b));
	double tmp;
	if (exp(b) <= 0.0) {
		tmp = t_0;
	} else if (exp(b) <= 2.0) {
		tmp = 1.0 / (1.0 + ((b + 1.0) / exp(a)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp(a) / (exp(a) + exp(b))
end function
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 1.0d0 / (1.0d0 + exp(b))
    if (exp(b) <= 0.0d0) then
        tmp = t_0
    else if (exp(b) <= 2.0d0) then
        tmp = 1.0d0 / (1.0d0 + ((b + 1.0d0) / exp(a)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b) {
	return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
public static double code(double a, double b) {
	double t_0 = 1.0 / (1.0 + Math.exp(b));
	double tmp;
	if (Math.exp(b) <= 0.0) {
		tmp = t_0;
	} else if (Math.exp(b) <= 2.0) {
		tmp = 1.0 / (1.0 + ((b + 1.0) / Math.exp(a)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b):
	t_0 = 1.0 / (1.0 + math.exp(b))
	tmp = 0
	if math.exp(b) <= 0.0:
		tmp = t_0
	elif math.exp(b) <= 2.0:
		tmp = 1.0 / (1.0 + ((b + 1.0) / math.exp(a)))
	else:
		tmp = t_0
	return tmp
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function code(a, b)
	t_0 = Float64(1.0 / Float64(1.0 + exp(b)))
	tmp = 0.0
	if (exp(b) <= 0.0)
		tmp = t_0;
	elseif (exp(b) <= 2.0)
		tmp = Float64(1.0 / Float64(1.0 + Float64(Float64(b + 1.0) / exp(a))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
function tmp_2 = code(a, b)
	t_0 = 1.0 / (1.0 + exp(b));
	tmp = 0.0;
	if (exp(b) <= 0.0)
		tmp = t_0;
	elseif (exp(b) <= 2.0)
		tmp = 1.0 / (1.0 + ((b + 1.0) / exp(a)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Exp[b], $MachinePrecision], 0.0], t$95$0, If[LessEqual[N[Exp[b], $MachinePrecision], 2.0], N[(1.0 / N[(1.0 + N[(N[(b + 1.0), $MachinePrecision] / N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
t_0 := \frac{1}{1 + e^{b}}\\
\mathbf{if}\;e^{b} \leq 0:\\
\;\;\;\;t_0\\

\mathbf{elif}\;e^{b} \leq 2:\\
\;\;\;\;\frac{1}{1 + \frac{b + 1}{e^{a}}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.8
Target0.0
Herbie0.4
\[\frac{1}{1 + e^{b - a}} \]

Derivation

  1. Split input into 2 regimes
  2. if (exp.f64 b) < 0.0 or 2 < (exp.f64 b)

    1. Initial program 1.2

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Taylor expanded in a around 0 0.3

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]

    if 0.0 < (exp.f64 b) < 2

    1. Initial program 0.5

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Applied egg-rr0.5

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{a} + e^{b}}{e^{a}}}} \]
    3. Taylor expanded in b around 0 10.5

      \[\leadsto \frac{1}{\color{blue}{1 + \left(\frac{b}{e^{a}} + \frac{1}{e^{a}}\right)}} \]
    4. Simplified0.5

      \[\leadsto \frac{1}{\color{blue}{1 + \frac{b + 1}{e^{a}}}} \]
      Proof
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error0.8
Cost19648
\[\frac{1}{e^{a} + e^{b}} \cdot e^{a} \]
Alternative 2
Error0.8
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 3
Error0.7
Cost7048
\[\begin{array}{l} t_0 := \frac{1}{1 + e^{b}}\\ \mathbf{if}\;b \leq -460000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 0.085:\\ \;\;\;\;\frac{1}{1 + e^{-a}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.1
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -780000:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
Alternative 5
Error22.3
Cost6592
\[\frac{e^{a}}{2} \]
Alternative 6
Error27.7
Cost1860
\[\begin{array}{l} \mathbf{if}\;b \leq -7500:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \left(1 + \left(\left(-a \cdot \left(1 + b\right)\right) + \left(b + \left(-\left(1 + b\right) \cdot \left(-1 + 0.5\right)\right) \cdot \left(a \cdot a\right)\right)\right)\right)}\\ \end{array} \]
Alternative 7
Error34.6
Cost900
\[\begin{array}{l} \mathbf{if}\;b \leq -10.5:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(\left(-a \cdot \left(1 + b\right)\right) + b\right) + 2}\\ \end{array} \]
Alternative 8
Error38.4
Cost320
\[0.5 + 0.25 \cdot a \]
Alternative 9
Error38.5
Cost64
\[0.5 \]

Error

Reproduce

herbie shell --seed 2023010 
(FPCore (a b)
  :name "Quotient of sum of exps"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ 1.0 (exp (- b a))))

  (/ (exp a) (+ (exp a) (exp b))))