| Alternative 1 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 19652 |
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.98:\\
\;\;\;\;\frac{e^{a}}{1 + e^{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 (<= b -380000000.0) (/ 1.0 (+ 1.0 (exp b))) (if (<= b -9.0) (/ (exp a) 2.0) (/ (exp a) (+ (exp b) (exp a))))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
double tmp;
if (b <= -380000000.0) {
tmp = 1.0 / (1.0 + exp(b));
} else if (b <= -9.0) {
tmp = exp(a) / 2.0;
} else {
tmp = exp(a) / (exp(b) + exp(a));
}
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 (b <= (-380000000.0d0)) then
tmp = 1.0d0 / (1.0d0 + exp(b))
else if (b <= (-9.0d0)) then
tmp = exp(a) / 2.0d0
else
tmp = exp(a) / (exp(b) + exp(a))
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 (b <= -380000000.0) {
tmp = 1.0 / (1.0 + Math.exp(b));
} else if (b <= -9.0) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = Math.exp(a) / (Math.exp(b) + Math.exp(a));
}
return tmp;
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b): tmp = 0 if b <= -380000000.0: tmp = 1.0 / (1.0 + math.exp(b)) elif b <= -9.0: tmp = math.exp(a) / 2.0 else: tmp = math.exp(a) / (math.exp(b) + math.exp(a)) return tmp
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function code(a, b) tmp = 0.0 if (b <= -380000000.0) tmp = Float64(1.0 / Float64(1.0 + exp(b))); elseif (b <= -9.0) tmp = Float64(exp(a) / 2.0); else tmp = Float64(exp(a) / Float64(exp(b) + exp(a))); 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 (b <= -380000000.0) tmp = 1.0 / (1.0 + exp(b)); elseif (b <= -9.0) tmp = exp(a) / 2.0; else tmp = exp(a) / (exp(b) + exp(a)); 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[b, -380000000.0], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -9.0], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[b], $MachinePrecision] + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;b \leq -380000000:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\mathbf{elif}\;b \leq -9:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{a}}{e^{b} + e^{a}}\\
\end{array}
Results
| Original | 99.0% |
|---|---|
| Target | 100.0% |
| Herbie | 99.0% |
if b < -3.8e8Initial program 98.4%
Taylor expanded in a around 0 100.0%
if -3.8e8 < b < -9Initial program 80.0%
Taylor expanded in b around 0 38.8%
Taylor expanded in a around 0 38.8%
if -9 < b Initial program 99.4%
Final simplification99.0%
| Alternative 1 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 19652 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 13252 |
| Alternative 3 | |
|---|---|
| Accuracy | 81.6% |
| Cost | 6724 |
| Alternative 4 | |
|---|---|
| Accuracy | 64.5% |
| Cost | 708 |
| Alternative 5 | |
|---|---|
| Accuracy | 52.4% |
| Cost | 452 |
| Alternative 6 | |
|---|---|
| Accuracy | 39.1% |
| Cost | 64 |
herbie shell --seed 2023131
(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))))