\[ \begin{array}{c}[a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\log \left(e^{a} + e^{b}\right)
\]
↓
\[\mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}
\]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
↓
(FPCore (a b) :precision binary64 (+ (log1p (exp a)) (/ b (+ (exp a) 1.0))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
↓
double code(double a, double b) {
return log1p(exp(a)) + (b / (exp(a) + 1.0));
}
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) {
return Math.log1p(Math.exp(a)) + (b / (Math.exp(a) + 1.0));
}
def code(a, b):
return math.log((math.exp(a) + math.exp(b)))
↓
def code(a, b):
return math.log1p(math.exp(a)) + (b / (math.exp(a) + 1.0))
function code(a, b)
return log(Float64(exp(a) + exp(b)))
end
↓
function code(a, b)
return Float64(log1p(exp(a)) + Float64(b / Float64(exp(a) + 1.0)))
end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
↓
code[a_, b_] := N[(N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision] + N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\log \left(e^{a} + e^{b}\right)
↓
\mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}
Alternatives
| Alternative 1 |
|---|
| Error | 98.3% |
|---|
| Cost | 20036.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 10^{-24}:\\
\;\;\;\;\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 2 |
|---|
| Error | 98.1% |
|---|
| Cost | 19652.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 10^{-24}:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + \left(b + 1\right)\right)\\
\end{array}
\]
| Alternative 3 |
|---|
| Error | 98.2% |
|---|
| Cost | 19392.00 |
|---|
\[\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)
\]
| Alternative 4 |
|---|
| Error | 97.7% |
|---|
| Cost | 13764.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 10^{-24}:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(0.5 + b \cdot -0.25\right) + \left(b \cdot 0.5 + \log 2\right)\\
\end{array}
\]
| Alternative 5 |
|---|
| Error | 97.7% |
|---|
| Cost | 7236.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(2 + \left(0.5 \cdot \left(b \cdot b\right) + \left(a + b\right)\right)\right)\\
\end{array}
\]
| Alternative 6 |
|---|
| Error | 57.4% |
|---|
| Cost | 6852.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -112:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\]
| Alternative 7 |
|---|
| Error | 97.2% |
|---|
| Cost | 6852.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -85:\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\]
| Alternative 8 |
|---|
| Error | 57.3% |
|---|
| Cost | 6724.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(a + 2\right)\\
\end{array}
\]
| Alternative 9 |
|---|
| Error | 57.3% |
|---|
| Cost | 6724.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -118:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\]
| Alternative 10 |
|---|
| Error | 56.8% |
|---|
| Cost | 6596.00 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -130:\\
\;\;\;\;b \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\]
| Alternative 11 |
|---|
| Error | 11.9% |
|---|
| Cost | 192.00 |
|---|
\[b \cdot 0.5
\]