\[ \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} + e^{b}\\
t_1 := \mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+166}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
↓
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ (exp a) (exp b)))
(t_1 (+ (log1p (exp a)) (/ b (+ (exp a) 1.0)))))
(if (<= t_0 2.0) t_1 (if (<= t_0 5e+166) (log1p (exp b)) t_1))))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 t_1 = log1p(exp(a)) + (b / (exp(a) + 1.0));
double tmp;
if (t_0 <= 2.0) {
tmp = t_1;
} else if (t_0 <= 5e+166) {
tmp = log1p(exp(b));
} else {
tmp = t_1;
}
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 t_1 = Math.log1p(Math.exp(a)) + (b / (Math.exp(a) + 1.0));
double tmp;
if (t_0 <= 2.0) {
tmp = t_1;
} else if (t_0 <= 5e+166) {
tmp = Math.log1p(Math.exp(b));
} else {
tmp = t_1;
}
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)
t_1 = math.log1p(math.exp(a)) + (b / (math.exp(a) + 1.0))
tmp = 0
if t_0 <= 2.0:
tmp = t_1
elif t_0 <= 5e+166:
tmp = math.log1p(math.exp(b))
else:
tmp = t_1
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))
t_1 = Float64(log1p(exp(a)) + Float64(b / Float64(exp(a) + 1.0)))
tmp = 0.0
if (t_0 <= 2.0)
tmp = t_1;
elseif (t_0 <= 5e+166)
tmp = log1p(exp(b));
else
tmp = t_1;
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]}, Block[{t$95$1 = N[(N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision] + N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$1, If[LessEqual[t$95$0, 5e+166], N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision], t$95$1]]]]
\log \left(e^{a} + e^{b}\right)
↓
\begin{array}{l}
t_0 := e^{a} + e^{b}\\
t_1 := \mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+166}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Alternatives
| Alternative 1 |
|---|
| Error | 0.8 |
|---|
| Cost | 25924 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
\]
| Alternative 2 |
|---|
| 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^{b}\right)\\
\end{array}
\]
| Alternative 3 |
|---|
| Error | 1.8 |
|---|
| Cost | 13636 |
|---|
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \left(b \cdot \left(b \cdot 0.125\right) + \log 2\right)\\
\end{array}
\]
| Alternative 4 |
|---|
| Error | 27.8 |
|---|
| Cost | 6852 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -86526.87079063947:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\]
| Alternative 5 |
|---|
| Error | 2.2 |
|---|
| Cost | 6852 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -86526.87079063947:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\]
| Alternative 6 |
|---|
| Error | 27.9 |
|---|
| Cost | 6724 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -86526.87079063947:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;\log \left(a + 2\right)\\
\end{array}
\]
| Alternative 7 |
|---|
| Error | 27.8 |
|---|
| Cost | 6724 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -86526.87079063947:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;\log \left(b + 2\right)\\
\end{array}
\]
| Alternative 8 |
|---|
| Error | 28.2 |
|---|
| Cost | 6596 |
|---|
\[\begin{array}{l}
\mathbf{if}\;a \leq -86526.87079063947:\\
\;\;\;\;\frac{b}{2}\\
\mathbf{else}:\\
\;\;\;\;\log 2\\
\end{array}
\]
| Alternative 9 |
|---|
| Error | 56.3 |
|---|
| Cost | 192 |
|---|
\[\frac{b}{2}
\]