\[ \begin{array}{c}[a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\log \left(e^{a} + e^{b}\right)
\]
↓
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 5 \cdot 10^{-192}:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\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) 5e-192) (/ b (+ 2.0 (expm1 a))) (log (+ (exp a) (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) <= 5e-192) {
tmp = b / (2.0 + expm1(a));
} else {
tmp = log((exp(a) + 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) <= 5e-192) {
tmp = b / (2.0 + Math.expm1(a));
} else {
tmp = Math.log((Math.exp(a) + 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) <= 5e-192:
tmp = b / (2.0 + math.expm1(a))
else:
tmp = math.log((math.exp(a) + 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) <= 5e-192)
tmp = Float64(b / Float64(2.0 + expm1(a)));
else
tmp = log(Float64(exp(a) + 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], 5e-192], N[(b / N[(2.0 + N[(Exp[a] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\log \left(e^{a} + e^{b}\right)
↓
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 5 \cdot 10^{-192}:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
Alternatives
| Alternative 1 |
|---|
| Error | 1.5 |
|---|
| Cost | 25928 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 5 \cdot 10^{-219}:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{elif}\;e^{a} \leq 1:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
\]
| Alternative 2 |
|---|
| Error | 1.1 |
|---|
| Cost | 19648 |
|---|
\[\mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}
\]
| Alternative 3 |
|---|
| Error | 1.5 |
|---|
| Cost | 19396 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 5 \cdot 10^{-219}:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\
\end{array}
\]
| Alternative 4 |
|---|
| Error | 1.4 |
|---|
| Cost | 19392 |
|---|
\[\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)
\]
| Alternative 5 |
|---|
| Error | 1.2 |
|---|
| Cost | 13636 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -36:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + \left(e^{a} + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\right)\right)\\
\end{array}
\]
| Alternative 6 |
|---|
| Error | 1.8 |
|---|
| Cost | 7108 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -1.4:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{b + 2} + \log \left(b + 2\right)\\
\end{array}
\]
| Alternative 7 |
|---|
| Error | 27.9 |
|---|
| Cost | 6852 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + \left(a + 2\right)\right)\\
\end{array}
\]
| Alternative 8 |
|---|
| Error | 27.9 |
|---|
| Cost | 6852 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(1 + \left(a + b\right)\right)\\
\end{array}
\]
| Alternative 9 |
|---|
| Error | 1.8 |
|---|
| Cost | 6852 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(1 + \left(a + b\right)\right)\\
\end{array}
\]
| Alternative 10 |
|---|
| Error | 28.3 |
|---|
| Cost | 6724 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(a + 2\right)\\
\end{array}
\]
| Alternative 11 |
|---|
| Error | 28.6 |
|---|
| Cost | 6596 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -115:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\]
| Alternative 12 |
|---|
| Error | 56.3 |
|---|
| Cost | 192 |
|---|
\[b \cdot 0.5
\]