| Alternative 1 | |
|---|---|
| Accuracy | 83.8% |
| Cost | 39108 |
\[\begin{array}{l}
t_0 := \frac{e^{a}}{e^{a} + e^{b}}\\
\mathbf{if}\;t_0 \leq 0.6:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;e^{-\mathsf{log1p}\left(e^{b}\right)}\\
\end{array}
\]

(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (let* ((t_0 (/ (exp a) (+ (exp a) (exp b))))) (if (<= t_0 0.6) t_0 (exp (- (log1p (exp b)))))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
double t_0 = exp(a) / (exp(a) + exp(b));
double tmp;
if (t_0 <= 0.6) {
tmp = t_0;
} else {
tmp = exp(-log1p(exp(b)));
}
return tmp;
}
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 t_0 = Math.exp(a) / (Math.exp(a) + Math.exp(b));
double tmp;
if (t_0 <= 0.6) {
tmp = t_0;
} else {
tmp = Math.exp(-Math.log1p(Math.exp(b)));
}
return tmp;
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b): t_0 = math.exp(a) / (math.exp(a) + math.exp(b)) tmp = 0 if t_0 <= 0.6: tmp = t_0 else: tmp = math.exp(-math.log1p(math.exp(b))) return tmp
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function code(a, b) t_0 = Float64(exp(a) / Float64(exp(a) + exp(b))) tmp = 0.0 if (t_0 <= 0.6) tmp = t_0; else tmp = exp(Float64(-log1p(exp(b)))); end return tmp end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_] := Block[{t$95$0 = N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.6], t$95$0, N[Exp[(-N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
t_0 := \frac{e^{a}}{e^{a} + e^{b}}\\
\mathbf{if}\;t_0 \leq 0.6:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;e^{-\mathsf{log1p}\left(e^{b}\right)}\\
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 68.9% |
|---|---|
| Target | 100.0% |
| Herbie | 83.8% |
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.599999999999999978Initial program 100.0%
if 0.599999999999999978 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 30.9%
Taylor expanded in a around 0 35.9%
Taylor expanded in a around 0 69.9%
Simplified69.9%
[Start]69.9% | \[ \frac{1}{1 + e^{b}}
\] |
|---|---|
rem-exp-log [<=]69.9% | \[ \frac{1}{\color{blue}{e^{\log \left(1 + e^{b}\right)}}}
\] |
log1p-def [=>]69.9% | \[ \frac{1}{e^{\color{blue}{\mathsf{log1p}\left(e^{b}\right)}}}
\] |
exp-neg [<=]69.9% | \[ \color{blue}{e^{-\mathsf{log1p}\left(e^{b}\right)}}
\] |
Final simplification85.5%
| Alternative 1 | |
|---|---|
| Accuracy | 83.8% |
| Cost | 39108 |
| Alternative 2 | |
|---|---|
| Accuracy | 59.2% |
| Cost | 7124 |
| Alternative 3 | |
|---|---|
| Accuracy | 65.8% |
| Cost | 7124 |
| Alternative 4 | |
|---|---|
| Accuracy | 80.1% |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Accuracy | 48.6% |
| Cost | 1480 |
| Alternative 6 | |
|---|---|
| Accuracy | 43.6% |
| Cost | 836 |
| Alternative 7 | |
|---|---|
| Accuracy | 43.4% |
| Cost | 708 |
| Alternative 8 | |
|---|---|
| Accuracy | 43.2% |
| Cost | 644 |
| Alternative 9 | |
|---|---|
| Accuracy | 32.3% |
| Cost | 64 |
herbie shell --seed 2023263
(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))))