Average Error: 0.6 → 0.9
Time: 4.7s
Precision: binary64
Cost: 32520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} t_0 := e^{b} + 1\\ \mathbf{if}\;e^{b} \leq 0.2:\\ \;\;\;\;\frac{1}{t_0}\\ \mathbf{elif}\;e^{b} \leq 2:\\ \;\;\;\;e^{a - \mathsf{log1p}\left(e^{a}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{t_0}^{-3}}\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (+ (exp b) 1.0)))
   (if (<= (exp b) 0.2)
     (/ 1.0 t_0)
     (if (<= (exp b) 2.0) (exp (- a (log1p (exp a)))) (cbrt (pow t_0 -3.0))))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double t_0 = exp(b) + 1.0;
	double tmp;
	if (exp(b) <= 0.2) {
		tmp = 1.0 / t_0;
	} else if (exp(b) <= 2.0) {
		tmp = exp((a - log1p(exp(a))));
	} else {
		tmp = cbrt(pow(t_0, -3.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 = Math.exp(b) + 1.0;
	double tmp;
	if (Math.exp(b) <= 0.2) {
		tmp = 1.0 / t_0;
	} else if (Math.exp(b) <= 2.0) {
		tmp = Math.exp((a - Math.log1p(Math.exp(a))));
	} else {
		tmp = Math.cbrt(Math.pow(t_0, -3.0));
	}
	return tmp;
}
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function code(a, b)
	t_0 = Float64(exp(b) + 1.0)
	tmp = 0.0
	if (exp(b) <= 0.2)
		tmp = Float64(1.0 / t_0);
	elseif (exp(b) <= 2.0)
		tmp = exp(Float64(a - log1p(exp(a))));
	else
		tmp = cbrt((t_0 ^ -3.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[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[N[Exp[b], $MachinePrecision], 0.2], N[(1.0 / t$95$0), $MachinePrecision], If[LessEqual[N[Exp[b], $MachinePrecision], 2.0], N[Exp[N[(a - N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Power[N[Power[t$95$0, -3.0], $MachinePrecision], 1/3], $MachinePrecision]]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
t_0 := e^{b} + 1\\
\mathbf{if}\;e^{b} \leq 0.2:\\
\;\;\;\;\frac{1}{t_0}\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{t_0}^{-3}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (exp.f64 b) < 0.20000000000000001

    1. Initial program 1.8

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

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

    if 0.20000000000000001 < (exp.f64 b) < 2

    1. Initial program 0.4

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

      \[\leadsto \color{blue}{e^{a - \log \left(e^{a} + e^{b}\right)}} \]
    3. Taylor expanded in b around 0 1.1

      \[\leadsto e^{\color{blue}{a - \log \left(1 + e^{a}\right)}} \]
    4. Simplified1.1

      \[\leadsto e^{\color{blue}{a - \mathsf{log1p}\left(e^{a}\right)}} \]

    if 2 < (exp.f64 b)

    1. Initial program 0.4

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

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\frac{e^{a}}{e^{a} + e^{b}}\right)}^{3}}} \]
    3. Taylor expanded in a around 0 0.2

      \[\leadsto \sqrt[3]{\color{blue}{\frac{1}{{\left(1 + e^{b}\right)}^{3}}}} \]
    4. Applied egg-rr0.3

      \[\leadsto \sqrt[3]{\color{blue}{{\left(1 + e^{b}\right)}^{-3}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.9

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

Alternatives

Alternative 1
Error0.9
Cost32456
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 0.2:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 2:\\ \;\;\;\;e^{a - \mathsf{log1p}\left(e^{a}\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.9
Cost26312
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 0.2:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 2:\\ \;\;\;\;\frac{1}{\frac{e^{a} + 1}{e^{a}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.9
Cost26184
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 0.2:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 2:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.5
Cost25920
\[e^{a - \log \left(e^{a} + e^{b}\right)} \]
Alternative 5
Error0.6
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 6
Error1.0
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 2 \cdot 10^{-215}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 7
Error16.5
Cost6860
\[\begin{array}{l} \mathbf{if}\;b \leq -1.2804148640715022 \cdot 10^{-38}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 1.1907074296206517 \cdot 10^{-271}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;b \leq 15368402910379.81:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 8
Error22.5
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq -3.556673513553628 \cdot 10^{-259}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 9
Error37.9
Cost64
\[0.5 \]

Error

Reproduce

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