| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 25924 |
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)\\
\end{array}
\]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ (exp a) (exp b))))
(if (or (<= t_0 1.5) (not (<= t_0 2.1)))
(/ b (+ 2.0 (expm1 a)))
(log t_0))))double code(double a, double b) {
return log((exp(a) + exp(b)));
}
double code(double a, double b) {
double t_0 = exp(a) + exp(b);
double tmp;
if ((t_0 <= 1.5) || !(t_0 <= 2.1)) {
tmp = b / (2.0 + expm1(a));
} else {
tmp = log(t_0);
}
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 t_0 = Math.exp(a) + Math.exp(b);
double tmp;
if ((t_0 <= 1.5) || !(t_0 <= 2.1)) {
tmp = b / (2.0 + Math.expm1(a));
} else {
tmp = Math.log(t_0);
}
return tmp;
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
def code(a, b): t_0 = math.exp(a) + math.exp(b) tmp = 0 if (t_0 <= 1.5) or not (t_0 <= 2.1): tmp = b / (2.0 + math.expm1(a)) else: tmp = math.log(t_0) return tmp
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function code(a, b) t_0 = Float64(exp(a) + exp(b)) tmp = 0.0 if ((t_0 <= 1.5) || !(t_0 <= 2.1)) tmp = Float64(b / Float64(2.0 + expm1(a))); else tmp = log(t_0); end return tmp end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := Block[{t$95$0 = N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, 1.5], N[Not[LessEqual[t$95$0, 2.1]], $MachinePrecision]], N[(b / N[(2.0 + N[(Exp[a] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[t$95$0], $MachinePrecision]]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
t_0 := e^{a} + e^{b}\\
\mathbf{if}\;t_0 \leq 1.5 \lor \neg \left(t_0 \leq 2.1\right):\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\log t_0\\
\end{array}
Results
if (+.f64 (exp.f64 a) (exp.f64 b)) < 1.5 or 2.10000000000000009 < (+.f64 (exp.f64 a) (exp.f64 b)) Initial program 57.6
Taylor expanded in b around 0 1.9
Simplified1.7
[Start]1.9 | \[ \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}
\] |
|---|---|
log1p-def [=>]1.7 | \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)} + \frac{b}{1 + e^{a}}
\] |
Taylor expanded in b around inf 2.3
Simplified2.3
[Start]2.3 | \[ \frac{b}{1 + e^{a}}
\] |
|---|---|
+-commutative [=>]2.3 | \[ \frac{b}{\color{blue}{e^{a} + 1}}
\] |
metadata-eval [<=]2.3 | \[ \frac{b}{e^{a} + \color{blue}{\left(2 - 1\right)}}
\] |
associate--l+ [<=]2.3 | \[ \frac{b}{\color{blue}{\left(e^{a} + 2\right) - 1}}
\] |
+-commutative [<=]2.3 | \[ \frac{b}{\color{blue}{\left(2 + e^{a}\right)} - 1}
\] |
associate--l+ [=>]2.3 | \[ \frac{b}{\color{blue}{2 + \left(e^{a} - 1\right)}}
\] |
expm1-def [=>]2.3 | \[ \frac{b}{2 + \color{blue}{\mathsf{expm1}\left(a\right)}}
\] |
if 1.5 < (+.f64 (exp.f64 a) (exp.f64 b)) < 2.10000000000000009Initial program 0.0
Final simplification1.2
| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 25924 |
| Alternative 2 | |
|---|---|
| Error | 1.1 |
| Cost | 19648 |
| Alternative 3 | |
|---|---|
| Error | 1.7 |
| Cost | 19396 |
| Alternative 4 | |
|---|---|
| Error | 1.1 |
| Cost | 13636 |
| Alternative 5 | |
|---|---|
| Error | 1.8 |
| Cost | 13252 |
| Alternative 6 | |
|---|---|
| Error | 27.1 |
| Cost | 6852 |
| Alternative 7 | |
|---|---|
| Error | 27.4 |
| Cost | 6724 |
| Alternative 8 | |
|---|---|
| Error | 27.4 |
| Cost | 6724 |
| Alternative 9 | |
|---|---|
| Error | 27.7 |
| Cost | 6596 |
| Alternative 10 | |
|---|---|
| Error | 56.4 |
| Cost | 192 |
herbie shell --seed 2023083
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))