Average Error: 0.6 → 0.5
Time: 6.8s
Precision: binary64
Cost: 25920
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[e^{a - \log \left(e^{a} + e^{b}\right)} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (exp (- a (log (+ (exp a) (exp b))))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	return exp((a - log((exp(a) + exp(b)))));
}
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
    code = exp((a - log((exp(a) + exp(b)))))
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) {
	return Math.exp((a - Math.log((Math.exp(a) + Math.exp(b)))));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b):
	return math.exp((a - math.log((math.exp(a) + math.exp(b)))))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function code(a, b)
	return exp(Float64(a - log(Float64(exp(a) + exp(b)))))
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
function tmp = code(a, b)
	tmp = exp((a - log((exp(a) + exp(b)))));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_] := N[Exp[N[(a - N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\frac{e^{a}}{e^{a} + e^{b}}
e^{a - \log \left(e^{a} + e^{b}\right)}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 0.6

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

    \[\leadsto \color{blue}{e^{a - \log \left(e^{a} + e^{b}\right)}} \]
  3. Final simplification0.5

    \[\leadsto e^{a - \log \left(e^{a} + e^{b}\right)} \]

Alternatives

Alternative 1
Error11.5
Cost26312
\[\begin{array}{l} t_0 := e^{b} \leq 1\\ \mathbf{if}\;t_0:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{elif}\;t_0:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{1 + \left(a + e^{b}\right)}\\ \end{array} \]
Alternative 2
Error11.9
Cost26312
\[\begin{array}{l} t_0 := e^{b} \leq 1\\ \mathbf{if}\;t_0:\\ \;\;\;\;{\left({\left(e^{b} + 1\right)}^{-0.5}\right)}^{2}\\ \mathbf{elif}\;t_0:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{1 + \left(a + e^{b}\right)}\\ \end{array} \]
Alternative 3
Error11.7
Cost26184
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 5 \cdot 10^{+14}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.9
Cost20296
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 0.96:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 2:\\ \;\;\;\;\left(1 - \frac{b}{a + 2}\right) \cdot \frac{e^{a}}{a + 2}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.6
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 6
Error10.8
Cost7184
\[\begin{array}{l} t_0 := 0.0020833333333333333 \cdot {a}^{5}\\ t_1 := \frac{e^{a}}{2}\\ \mathbf{if}\;b \leq -1781171675.4519224:\\ \;\;\;\;1\\ \mathbf{elif}\;b \leq 2.2314268464299986 \cdot 10^{+53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 7.394218179557499 \cdot 10^{+119}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 5.0837819356448383 \cdot 10^{+179}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error1.3
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -34500000000000:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 8
Error13.0
Cost6724
\[\begin{array}{l} \mathbf{if}\;b \leq -1781171675.4519224:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{2}\\ \end{array} \]
Alternative 9
Error22.6
Cost6596
\[\begin{array}{l} \mathbf{if}\;a \leq -3.361888512428888 \cdot 10^{-21}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \end{array} \]
Alternative 10
Error28.9
Cost964
\[\begin{array}{l} \mathbf{if}\;b \leq -1781171675.4519224:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \frac{b}{a + 2}\right) \cdot \left(0.5 + a \cdot 0.25\right)\\ \end{array} \]
Alternative 11
Error29.1
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq -1781171675.4519224:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \end{array} \]
Alternative 12
Error29.3
Cost196
\[\begin{array}{l} \mathbf{if}\;b \leq -1781171675.4519224:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 13
Error46.6
Cost64
\[1 \]

Error

Reproduce

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