Average Error: 0.7 → 0.9
Time: 7.1s
Precision: binary64
Cost: 32456
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 0.999999999999995:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 1.002:\\ \;\;\;\;e^{a - \mathsf{log1p}\left(e^{a}\right)}\\ \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 (+ (exp b) 1.0))))
   (if (<= (exp b) 0.999999999999995)
     t_0
     (if (<= (exp b) 1.002) (exp (- a (log1p (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 / (exp(b) + 1.0);
	double tmp;
	if (exp(b) <= 0.999999999999995) {
		tmp = t_0;
	} else if (exp(b) <= 1.002) {
		tmp = exp((a - log1p(exp(a))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
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 / (Math.exp(b) + 1.0);
	double tmp;
	if (Math.exp(b) <= 0.999999999999995) {
		tmp = t_0;
	} else if (Math.exp(b) <= 1.002) {
		tmp = Math.exp((a - Math.log1p(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 / (math.exp(b) + 1.0)
	tmp = 0
	if math.exp(b) <= 0.999999999999995:
		tmp = t_0
	elif math.exp(b) <= 1.002:
		tmp = math.exp((a - math.log1p(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(exp(b) + 1.0))
	tmp = 0.0
	if (exp(b) <= 0.999999999999995)
		tmp = t_0;
	elseif (exp(b) <= 1.002)
		tmp = exp(Float64(a - log1p(exp(a))));
	else
		tmp = t_0;
	end
	return 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[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Exp[b], $MachinePrecision], 0.999999999999995], t$95$0, If[LessEqual[N[Exp[b], $MachinePrecision], 1.002], N[Exp[N[(a - N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
t_0 := \frac{1}{e^{b} + 1}\\
\mathbf{if}\;e^{b} \leq 0.999999999999995:\\
\;\;\;\;t_0\\

\mathbf{elif}\;e^{b} \leq 1.002:\\
\;\;\;\;e^{a - \mathsf{log1p}\left(e^{a}\right)}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.7

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

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

    if 0.999999999999995004 < (exp.f64 b) < 1.002

    1. Initial program 0.6

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

      \[\leadsto \color{blue}{\frac{e^{a}}{1 + e^{a}}} \]
    3. Applied egg-rr0.8

      \[\leadsto \color{blue}{e^{a - \mathsf{log1p}\left(e^{a}\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{b} \leq 0.999999999999995:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{elif}\;e^{b} \leq 1.002:\\ \;\;\;\;e^{a - \mathsf{log1p}\left(e^{a}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]

Alternatives

Alternative 1
Error0.9
Cost26184
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 0.999999999999995:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 1.002:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.7
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 3
Error1.1
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0.99:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 4
Error2.0
Cost6856
\[\begin{array}{l} \mathbf{if}\;b \leq -65.03457022728482:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 19.98336883665251:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Error14.0
Cost6596
\[\begin{array}{l} \mathbf{if}\;b \leq -1.1225341323172226 \cdot 10^{-45}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 6
Error13.5
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -84081.80901330551:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 7
Error22.0
Cost452
\[\begin{array}{l} \mathbf{if}\;a \leq -84081.80901330551:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \end{array} \]
Alternative 8
Error22.1
Cost196
\[\begin{array}{l} \mathbf{if}\;a \leq -8.740771633340857 \cdot 10^{-7}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 9
Error39.0
Cost64
\[0.5 \]

Error

Reproduce

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