| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 25924 |
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 10^{-61}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
\]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ b (+ (exp a) 1.0)) (if (<= (exp a) 0.99999999999996) (log1p (exp a)) (log1p (exp b)))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (exp(a) + 1.0);
} else if (exp(a) <= 0.99999999999996) {
tmp = log1p(exp(a));
} else {
tmp = log1p(exp(b));
}
return tmp;
}
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = b / (Math.exp(a) + 1.0);
} else if (Math.exp(a) <= 0.99999999999996) {
tmp = Math.log1p(Math.exp(a));
} else {
tmp = Math.log1p(Math.exp(b));
}
return tmp;
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (math.exp(a) + 1.0) elif math.exp(a) <= 0.99999999999996: tmp = math.log1p(math.exp(a)) else: tmp = math.log1p(math.exp(b)) return tmp
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(b / Float64(exp(a) + 1.0)); elseif (exp(a) <= 0.99999999999996) tmp = log1p(exp(a)); else tmp = log1p(exp(b)); end return tmp end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Exp[a], $MachinePrecision], 0.99999999999996], N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision], N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision]]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{elif}\;e^{a} \leq 0.99999999999996:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
Results
if (exp.f64 a) < 0.0Initial program 58.4
Taylor expanded in b around 0 0
Simplified0
[Start]0 | \[ \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}
\] |
|---|---|
log1p-def [=>]0 | \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)} + \frac{b}{1 + e^{a}}
\] |
Taylor expanded in b around inf 0
if 0.0 < (exp.f64 a) < 0.99999999999996003Initial program 6.6
Taylor expanded in b around 0 7.8
Simplified3.4
[Start]7.8 | \[ \log \left(1 + e^{a}\right)
\] |
|---|---|
log1p-def [=>]3.4 | \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)}
\] |
if 0.99999999999996003 < (exp.f64 a) Initial program 1.4
Taylor expanded in a around 0 1.4
Simplified1.4
[Start]1.4 | \[ \log \left(1 + e^{b}\right)
\] |
|---|---|
log1p-def [=>]1.4 | \[ \color{blue}{\mathsf{log1p}\left(e^{b}\right)}
\] |
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 25924 |
| Alternative 2 | |
|---|---|
| Error | 1.9 |
| Cost | 19908 |
| Alternative 3 | |
|---|---|
| Error | 1.5 |
| Cost | 19396 |
| Alternative 4 | |
|---|---|
| Error | 1.4 |
| Cost | 19392 |
| Alternative 5 | |
|---|---|
| Error | 1.6 |
| Cost | 13764 |
| Alternative 6 | |
|---|---|
| Error | 1.6 |
| Cost | 13636 |
| Alternative 7 | |
|---|---|
| Error | 2.0 |
| Cost | 13508 |
| Alternative 8 | |
|---|---|
| Error | 28.1 |
| Cost | 6852 |
| Alternative 9 | |
|---|---|
| Error | 1.9 |
| Cost | 6852 |
| Alternative 10 | |
|---|---|
| Error | 28.2 |
| Cost | 6724 |
| Alternative 11 | |
|---|---|
| Error | 28.5 |
| Cost | 6596 |
| Alternative 12 | |
|---|---|
| Error | 56.2 |
| Cost | 192 |
herbie shell --seed 2022356
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))