?

Average Error: 0.7 → 1.0
Time: 6.1s
Precision: binary64
Cost: 13252

?

\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 + \mathsf{expm1}\left(b\right)}\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (<= (exp a) 0.0) (/ (exp a) 2.0) (/ 1.0 (+ 2.0 (expm1 b)))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double tmp;
	if (exp(a) <= 0.0) {
		tmp = exp(a) / 2.0;
	} else {
		tmp = 1.0 / (2.0 + expm1(b));
	}
	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 tmp;
	if (Math.exp(a) <= 0.0) {
		tmp = Math.exp(a) / 2.0;
	} else {
		tmp = 1.0 / (2.0 + Math.expm1(b));
	}
	return tmp;
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b):
	tmp = 0
	if math.exp(a) <= 0.0:
		tmp = math.exp(a) / 2.0
	else:
		tmp = 1.0 / (2.0 + math.expm1(b))
	return tmp
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function code(a, b)
	tmp = 0.0
	if (exp(a) <= 0.0)
		tmp = Float64(exp(a) / 2.0);
	else
		tmp = Float64(1.0 / Float64(2.0 + expm1(b)));
	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_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(1.0 / N[(2.0 + N[(Exp[b] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{e^{a}}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \mathsf{expm1}\left(b\right)}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

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

    1. Initial program 0.7

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

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

      \[\leadsto \frac{e^{a}}{\color{blue}{2}} \]

    if 0.0 < (exp.f64 a)

    1. Initial program 0.7

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

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
    3. Applied egg-rr1.2

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

      \[\leadsto \frac{1}{\color{blue}{2 + \mathsf{expm1}\left(b\right)}} \]
      Proof

      [Start]1.2

      \[ \frac{1}{\left(1 + \left(1 + e^{b}\right)\right) - 1} \]

      associate-+r+ [=>]1.2

      \[ \frac{1}{\color{blue}{\left(\left(1 + 1\right) + e^{b}\right)} - 1} \]

      metadata-eval [=>]1.2

      \[ \frac{1}{\left(\color{blue}{2} + e^{b}\right) - 1} \]

      associate--l+ [=>]1.2

      \[ \frac{1}{\color{blue}{2 + \left(e^{b} - 1\right)}} \]

      expm1-def [=>]1.2

      \[ \frac{1}{2 + \color{blue}{\mathsf{expm1}\left(b\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 + \mathsf{expm1}\left(b\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error12.2
Cost26184
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 1:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{elif}\;e^{b} \leq 1.2:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 + \mathsf{expm1}\left(b\right)}\\ \end{array} \]
Alternative 2
Error0.7
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 3
Error1.0
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 4
Error11.2
Cost6724
\[\begin{array}{l} \mathbf{if}\;b \leq 280:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{2}{b \cdot b}\right) + -1\\ \end{array} \]
Alternative 5
Error22.7
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 1.25 \cdot 10^{-264}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 6
Error22.3
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 1.7:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{2}{b \cdot b}\right) + -1\\ \end{array} \]
Alternative 7
Error22.7
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 1.5:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b}\right) + -1\\ \end{array} \]
Alternative 8
Error29.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.55:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]
Alternative 9
Error38.7
Cost320
\[0.5 + a \cdot 0.25 \]
Alternative 10
Error38.8
Cost64
\[0.5 \]

Error

Reproduce?

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