Math FPCore C Julia Wolfram TeX \[\log \left(1 + e^{x}\right) - x \cdot y
\]
↓
\[\begin{array}{l}
\mathbf{if}\;\log \left(1 + e^{x}\right) - x \cdot y \leq 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(x, -y, \mathsf{log1p}\left(e^{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right) + \log 2\\
\end{array}
\]
(FPCore (x y) :precision binary64 (- (log (+ 1.0 (exp x))) (* x y))) ↓
(FPCore (x y)
:precision binary64
(if (<= (- (log (+ 1.0 (exp x))) (* x y)) 1e+305)
(fma x (- y) (log1p (exp x)))
(+ (* x (- 0.5 y)) (log 2.0)))) double code(double x, double y) {
return log((1.0 + exp(x))) - (x * y);
}
↓
double code(double x, double y) {
double tmp;
if ((log((1.0 + exp(x))) - (x * y)) <= 1e+305) {
tmp = fma(x, -y, log1p(exp(x)));
} else {
tmp = (x * (0.5 - y)) + log(2.0);
}
return tmp;
}
function code(x, y)
return Float64(log(Float64(1.0 + exp(x))) - Float64(x * y))
end
↓
function code(x, y)
tmp = 0.0
if (Float64(log(Float64(1.0 + exp(x))) - Float64(x * y)) <= 1e+305)
tmp = fma(x, Float64(-y), log1p(exp(x)));
else
tmp = Float64(Float64(x * Float64(0.5 - y)) + log(2.0));
end
return tmp
end
code[x_, y_] := N[(N[Log[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
↓
code[x_, y_] := If[LessEqual[N[(N[Log[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], 1e+305], N[(x * (-y) + N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(0.5 - y), $MachinePrecision]), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\log \left(1 + e^{x}\right) - x \cdot y
↓
\begin{array}{l}
\mathbf{if}\;\log \left(1 + e^{x}\right) - x \cdot y \leq 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(x, -y, \mathsf{log1p}\left(e^{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right) + \log 2\\
\end{array}
Alternatives Alternative 1 Accuracy 90.0% Cost 32772
\[\begin{array}{l}
\mathbf{if}\;\log \left(1 + e^{x}\right) - x \cdot y \leq 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(x, -y, \mathsf{log1p}\left(e^{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right) + \log 2\\
\end{array}
\]
Alternative 2 Accuracy 90.0% Cost 26436
\[\begin{array}{l}
\mathbf{if}\;\log \left(1 + e^{x}\right) - x \cdot y \leq 10^{+305}:\\
\;\;\;\;\mathsf{log1p}\left(e^{x}\right) - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right) + \log 2\\
\end{array}
\]
Alternative 3 Accuracy 76.6% Cost 6984
\[\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-6}:\\
\;\;\;\;-x \cdot y\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-47}:\\
\;\;\;\;\log 2 + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 4 Accuracy 89.5% Cost 6980
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.4:\\
\;\;\;\;-x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right) + \log 2\\
\end{array}
\]
Alternative 5 Accuracy 87.6% Cost 6852
\[\begin{array}{l}
\mathbf{if}\;x \leq -52:\\
\;\;\;\;-x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\log 2 - x \cdot y\\
\end{array}
\]
Alternative 6 Accuracy 76.5% Cost 6728
\[\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{-6}:\\
\;\;\;\;-x \cdot y\\
\mathbf{elif}\;x \leq 1.02 \cdot 10^{-45}:\\
\;\;\;\;\log 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 7 Accuracy 53.1% Cost 580
\[\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;-x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - x \cdot y\\
\end{array}
\]
Alternative 8 Accuracy 53.1% Cost 452
\[\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;-x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 9 Accuracy 50.9% Cost 256
\[-x \cdot y
\]
Alternative 10 Accuracy 5.3% Cost 192
\[x \cdot 0.5
\]