| Alternative 1 | |
|---|---|
| Accuracy | 81.6% |
| Cost | 6852 |
\[\begin{array}{l}
\mathbf{if}\;a \leq -1.85 \cdot 10^{+59}:\\
\;\;\;\;\frac{e^{a}}{a}\\
\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 (<= a -1.85e+59) (/ (exp a) 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 (a <= -1.85e+59) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
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
real(8) :: tmp
if (a <= (-1.85d+59)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
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) {
double tmp;
if (a <= -1.85e+59) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b): tmp = 0 if a <= -1.85e+59: tmp = math.exp(a) / a else: tmp = 1.0 / (1.0 + math.exp(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 (a <= -1.85e+59) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.85e+59) tmp = exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = 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[a, -1.85e+59], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;a \leq -1.85 \cdot 10^{+59}:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 70.0% |
|---|---|
| Target | 100.0% |
| Herbie | 81.6% |
if a < -1.84999999999999999e59Initial program 86.4%
Taylor expanded in b around 0 96.7%
Taylor expanded in a around 0 96.7%
Simplified96.7%
[Start]96.7% | \[ \frac{e^{a}}{2 + a}
\] |
|---|---|
+-commutative [=>]96.7% | \[ \frac{e^{a}}{\color{blue}{a + 2}}
\] |
Taylor expanded in a around inf 96.7%
if -1.84999999999999999e59 < a Initial program 67.5%
Taylor expanded in a around 0 83.5%
Final simplification86.6%
| Alternative 1 | |
|---|---|
| Accuracy | 81.6% |
| Cost | 6852 |
| Alternative 2 | |
|---|---|
| Accuracy | 59.2% |
| Cost | 6724 |
| Alternative 3 | |
|---|---|
| Accuracy | 43.8% |
| Cost | 452 |
| Alternative 4 | |
|---|---|
| Accuracy | 32.1% |
| Cost | 64 |
herbie shell --seed 2023271
(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))))