| Alternative 1 | |
|---|---|
| Accuracy | 80.8% |
| Cost | 26185 |
\[\begin{array}{l}
\mathbf{if}\;e^{b} \leq 1 \lor \neg \left(e^{b} \leq 1.0000005\right):\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\end{array}
\]

(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (if (<= a -620000000000.0) 0.0 (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
double tmp;
if (a <= -620000000000.0) {
tmp = 0.0;
} else {
tmp = 1.0 / (exp(b) + 1.0);
}
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 <= (-620000000000.0d0)) then
tmp = 0.0d0
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
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 <= -620000000000.0) {
tmp = 0.0;
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b): tmp = 0 if a <= -620000000000.0: tmp = 0.0 else: tmp = 1.0 / (math.exp(b) + 1.0) 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 <= -620000000000.0) tmp = 0.0; else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); 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 <= -620000000000.0) tmp = 0.0; else tmp = 1.0 / (exp(b) + 1.0); 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, -620000000000.0], 0.0, N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;a \leq -620000000000:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
Results
| Original | 98.9% |
|---|---|
| Target | 100.0% |
| Herbie | 98.3% |
if a < -6.2e11Initial program 96.7%
Taylor expanded in a around 0 25.4%
Taylor expanded in b around 0 3.7%
Simplified3.7%
[Start]3.7 | \[ \frac{1}{2 + b}
\] |
|---|---|
+-commutative [=>]3.7 | \[ \frac{1}{\color{blue}{b + 2}}
\] |
Applied egg-rr23.8%
[Start]3.7 | \[ \frac{1}{b + 2}
\] |
|---|---|
expm1-log1p-u [=>]3.7 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{b + 2}\right)\right)}
\] |
expm1-udef [=>]23.8 | \[ \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{b + 2}\right)} - 1}
\] |
log1p-udef [=>]23.8 | \[ e^{\color{blue}{\log \left(1 + \frac{1}{b + 2}\right)}} - 1
\] |
add-exp-log [<=]23.8 | \[ \color{blue}{\left(1 + \frac{1}{b + 2}\right)} - 1
\] |
Simplified23.8%
[Start]23.8 | \[ \left(1 + \frac{1}{b + 2}\right) - 1
\] |
|---|---|
associate--l+ [=>]23.8 | \[ \color{blue}{1 + \left(\frac{1}{b + 2} - 1\right)}
\] |
Taylor expanded in b around inf 100.0%
if -6.2e11 < a Initial program 97.9%
Taylor expanded in a around 0 97.0%
Final simplification97.7%
| Alternative 1 | |
|---|---|
| Accuracy | 80.8% |
| Cost | 26185 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 25920 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 19520 |
| Alternative 4 | |
|---|---|
| Accuracy | 76.1% |
| Cost | 7124 |
| Alternative 5 | |
|---|---|
| Accuracy | 79.6% |
| Cost | 708 |
| Alternative 6 | |
|---|---|
| Accuracy | 63.8% |
| Cost | 584 |
| Alternative 7 | |
|---|---|
| Accuracy | 63.5% |
| Cost | 460 |
| Alternative 8 | |
|---|---|
| Accuracy | 39.2% |
| Cost | 64 |
herbie shell --seed 2023159
(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))))