\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.9997404070023854:\\
\;\;\;\;\frac{e^{a}}{1 + \left(b + \mathsf{fma}\left(0.5, b \cdot b, \mathsf{fma}\left(0.16666666666666666, {b}^{3}, e^{a}\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
:precision binary64
(if (<= (exp a) 0.9997404070023854)
(/
(exp a)
(+
1.0
(+ b (fma 0.5 (* b b) (fma 0.16666666666666666 (pow b 3.0) (exp a))))))
(/ 1.0 (+ 1.0 (exp 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.9997404070023854) {
tmp = exp(a) / (1.0 + (b + fma(0.5, (b * b), fma(0.16666666666666666, pow(b, 3.0), exp(a)))));
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}




Bits error versus a




Bits error versus b
| Original | 0.6 |
|---|---|
| Target | 0.0 |
| Herbie | 0.9 |
if (exp.f64 a) < 0.99974040700238542Initial program 0.9
Taylor expanded around 0 0.9
Simplified0.9
if 0.99974040700238542 < (exp.f64 a) Initial program 0.6
Taylor expanded around 0 0.4
Simplified0.4
Taylor expanded around 0 0.9
Final simplification0.9
herbie shell --seed 2021211
(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))))