?

Average Error: 0.6 → 0.5
Time: 7.9s
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
Error12.1
Cost32457
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 1 \lor \neg \left(e^{b} \leq 2\right):\\ \;\;\;\;e^{-\mathsf{log1p}\left(e^{b}\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{a - \mathsf{log1p}\left(e^{a}\right)}\\ \end{array} \]
Alternative 2
Error12.1
Cost32393
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 1 \lor \neg \left(e^{b} \leq 2\right):\\ \;\;\;\;e^{-\mathsf{log1p}\left(e^{b}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \end{array} \]
Alternative 3
Error12.1
Cost26185
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 1 \lor \neg \left(e^{b} \leq 2\right):\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \end{array} \]
Alternative 4
Error0.6
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 5
Error1.0
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 6
Error14.5
Cost6860
\[\begin{array}{l} \mathbf{if}\;b \leq -0.08:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq -4.3 \cdot 10^{-44}:\\ \;\;\;\;0.5 + b \cdot \left(0.020833333333333332 \cdot \left(b \cdot b\right) + -0.25\right)\\ \mathbf{elif}\;b \leq -8.5 \cdot 10^{-134}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 7
Error14.2
Cost6860
\[\begin{array}{l} \mathbf{if}\;b \leq -2.5:\\ \;\;\;\;e^{b} + 1\\ \mathbf{elif}\;b \leq -1.55 \cdot 10^{-43}:\\ \;\;\;\;0.5 + b \cdot \left(0.020833333333333332 \cdot \left(b \cdot b\right) + -0.25\right)\\ \mathbf{elif}\;b \leq -2.45 \cdot 10^{-131}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 8
Error22.7
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 4.4 \cdot 10^{-18}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 9
Error22.9
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 4.1 \cdot 10^{-5}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b}\right) + -1\\ \end{array} \]
Alternative 10
Error30.3
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 4.1 \cdot 10^{-5}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]
Alternative 11
Error38.7
Cost320
\[0.5 + a \cdot 0.25 \]
Alternative 12
Error38.9
Cost64
\[0.5 \]

Error

Reproduce?

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