\[ \begin{array}{c}[a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\log \left(e^{a} + e^{b}\right)
\]
↓
\[\begin{array}{l}
t_0 := e^{a} + 1\\
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-19}:\\
\;\;\;\;\frac{b}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\log \left(t_0 + \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) 1.0)))
(if (<= (exp a) 2e-19) (/ b t_0) (log (+ t_0 (expm1 b))))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
↓
double code(double a, double b) {
double t_0 = exp(a) + 1.0;
double tmp;
if (exp(a) <= 2e-19) {
tmp = b / t_0;
} else {
tmp = log((t_0 + expm1(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 t_0 = Math.exp(a) + 1.0;
double tmp;
if (Math.exp(a) <= 2e-19) {
tmp = b / t_0;
} else {
tmp = Math.log((t_0 + Math.expm1(b)));
}
return tmp;
}
def code(a, b):
return math.log((math.exp(a) + math.exp(b)))
↓
def code(a, b):
t_0 = math.exp(a) + 1.0
tmp = 0
if math.exp(a) <= 2e-19:
tmp = b / t_0
else:
tmp = math.log((t_0 + math.expm1(b)))
return tmp
function code(a, b)
return log(Float64(exp(a) + exp(b)))
end
↓
function code(a, b)
t_0 = Float64(exp(a) + 1.0)
tmp = 0.0
if (exp(a) <= 2e-19)
tmp = Float64(b / t_0);
else
tmp = log(Float64(t_0 + expm1(b)));
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] + 1.0), $MachinePrecision]}, If[LessEqual[N[Exp[a], $MachinePrecision], 2e-19], N[(b / t$95$0), $MachinePrecision], N[Log[N[(t$95$0 + N[(Exp[b] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\log \left(e^{a} + e^{b}\right)
↓
\begin{array}{l}
t_0 := e^{a} + 1\\
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-19}:\\
\;\;\;\;\frac{b}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\log \left(t_0 + \mathsf{expm1}\left(b\right)\right)\\
\end{array}
Alternatives
| Alternative 1 |
|---|
| Error | 1.1 |
|---|
| Cost | 83712 |
|---|
\[\begin{array}{l}
t_0 := \mathsf{log1p}\left(e^{a}\right)\\
t_1 := \sqrt[3]{t_0}\\
t_0 + \frac{b}{{\left(e^{{\left({\left(\sqrt[3]{t_1}\right)}^{3}\right)}^{2}}\right)}^{t_1}}
\end{array}
\]
| Alternative 2 |
|---|
| Error | 0.8 |
|---|
| Cost | 25924 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-19}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
\]
| Alternative 3 |
|---|
| Error | 1.1 |
|---|
| Cost | 19648 |
|---|
\[\mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}
\]
| Alternative 4 |
|---|
| Error | 1.6 |
|---|
| Cost | 19396 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
\]
| Alternative 5 |
|---|
| Error | 1.5 |
|---|
| Cost | 19396 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\end{array}
\]
| Alternative 6 |
|---|
| Error | 2.0 |
|---|
| Cost | 13252 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.05:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;a \cdot 0.5 + \log 2\\
\end{array}
\]
| Alternative 7 |
|---|
| Error | 32.5 |
|---|
| Cost | 6720 |
|---|
\[\log 2 + b \cdot 0.5
\]
| Alternative 8 |
|---|
| Error | 32.7 |
|---|
| Cost | 6592 |
|---|
\[\log \left(b + 2\right)
\]
| Alternative 9 |
|---|
| Error | 33.0 |
|---|
| Cost | 6464 |
|---|
\[\log 2
\]
| Alternative 10 |
|---|
| Error | 62.3 |
|---|
| Cost | 192 |
|---|
\[a \cdot 0.5
\]