| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 25920 |
\[e^{a - \log \left(e^{a} + e^{b}\right)}
\]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (if (<= (exp b) 0.999998) (/ 1.0 (+ (exp b) 1.0)) (if (<= (exp b) 1.0002) (/ (exp a) (+ (exp a) 1.0)) 0.0)))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
double tmp;
if (exp(b) <= 0.999998) {
tmp = 1.0 / (exp(b) + 1.0);
} else if (exp(b) <= 1.0002) {
tmp = exp(a) / (exp(a) + 1.0);
} else {
tmp = 0.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 (exp(b) <= 0.999998d0) then
tmp = 1.0d0 / (exp(b) + 1.0d0)
else if (exp(b) <= 1.0002d0) then
tmp = exp(a) / (exp(a) + 1.0d0)
else
tmp = 0.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 (Math.exp(b) <= 0.999998) {
tmp = 1.0 / (Math.exp(b) + 1.0);
} else if (Math.exp(b) <= 1.0002) {
tmp = Math.exp(a) / (Math.exp(a) + 1.0);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b): tmp = 0 if math.exp(b) <= 0.999998: tmp = 1.0 / (math.exp(b) + 1.0) elif math.exp(b) <= 1.0002: tmp = math.exp(a) / (math.exp(a) + 1.0) else: tmp = 0.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 (exp(b) <= 0.999998) tmp = Float64(1.0 / Float64(exp(b) + 1.0)); elseif (exp(b) <= 1.0002) tmp = Float64(exp(a) / Float64(exp(a) + 1.0)); else tmp = 0.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 (exp(b) <= 0.999998) tmp = 1.0 / (exp(b) + 1.0); elseif (exp(b) <= 1.0002) tmp = exp(a) / (exp(a) + 1.0); else tmp = 0.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[N[Exp[b], $MachinePrecision], 0.999998], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Exp[b], $MachinePrecision], 1.0002], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], 0.0]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 0.999998:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\mathbf{elif}\;e^{b} \leq 1.0002:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
Results
| Original | 99.0% |
|---|---|
| Target | 100.0% |
| Herbie | 98.6% |
if (exp.f64 b) < 0.999998000000000054Initial program 98.1%
Taylor expanded in a around 0 100.0%
if 0.999998000000000054 < (exp.f64 b) < 1.0002Initial program 100.0%
Taylor expanded in b around 0 99.3%
if 1.0002 < (exp.f64 b) Initial program 98.7%
Taylor expanded in a around 0 97.5%
Taylor expanded in b around 0 5.3%
Simplified5.3%
[Start]5.3 | \[ \frac{1}{2 + b}
\] |
|---|---|
+-commutative [=>]5.3 | \[ \frac{1}{\color{blue}{b + 2}}
\] |
Applied egg-rr91.3%
[Start]5.3 | \[ \frac{1}{b + 2}
\] |
|---|---|
expm1-log1p-u [=>]5.3 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{b + 2}\right)\right)}
\] |
expm1-udef [=>]91.3 | \[ \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{b + 2}\right)} - 1}
\] |
log1p-udef [=>]91.3 | \[ e^{\color{blue}{\log \left(1 + \frac{1}{b + 2}\right)}} - 1
\] |
add-exp-log [<=]91.3 | \[ \color{blue}{\left(1 + \frac{1}{b + 2}\right)} - 1
\] |
Taylor expanded in b around inf 100.0%
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 25920 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 19520 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 13252 |
| Alternative 4 | |
|---|---|
| Accuracy | 79.5% |
| Cost | 6596 |
| Alternative 5 | |
|---|---|
| Accuracy | 79.3% |
| Cost | 708 |
| Alternative 6 | |
|---|---|
| Accuracy | 65.1% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 64.8% |
| Cost | 196 |
| Alternative 8 | |
|---|---|
| Accuracy | 39.0% |
| Cost | 64 |
herbie shell --seed 2023160
(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))))