| Alternative 1 | |
|---|---|
| Error | 1.7 |
| Cost | 13120 |
\[\frac{e^{a}}{1 + e^{b}}
\]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (if (<= a -650000.0) 0.0 (/ 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 <= -650000.0) {
tmp = 0.0;
} 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 <= (-650000.0d0)) then
tmp = 0.0d0
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 <= -650000.0) {
tmp = 0.0;
} 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 <= -650000.0: tmp = 0.0 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 <= -650000.0) tmp = 0.0; 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 <= -650000.0) tmp = 0.0; 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, -650000.0], 0.0, 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 -650000:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
Results
| Original | 0.9 |
|---|---|
| Target | 0.0 |
| Herbie | 1.2 |
if a < -6.5e5Initial program 0.9
Taylor expanded in a around 0 41.0
Taylor expanded in b around 0 61.5
Simplified61.5
[Start]61.5 | \[ \frac{1}{2 + b}
\] |
|---|---|
+-commutative [=>]61.5 | \[ \frac{1}{\color{blue}{b + 2}}
\] |
Applied egg-rr42.3
Taylor expanded in b around inf 0.2
if -6.5e5 < a Initial program 0.9
Taylor expanded in a around 0 1.5
Final simplification1.2
| Alternative 1 | |
|---|---|
| Error | 1.7 |
| Cost | 13120 |
| Alternative 2 | |
|---|---|
| Error | 11.2 |
| Cost | 6724 |
| Alternative 3 | |
|---|---|
| Error | 23.3 |
| Cost | 980 |
| Alternative 4 | |
|---|---|
| Error | 23.4 |
| Cost | 724 |
| Alternative 5 | |
|---|---|
| Error | 13.7 |
| Cost | 708 |
| Alternative 6 | |
|---|---|
| Error | 37.9 |
| Cost | 64 |
herbie shell --seed 2023056
(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))))