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 5 \cdot 10^{+302}:\\
\;\;\;\;\mathsf{fma}\left(x, -y, \mathsf{log1p}\left(e^{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\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)) 5e+302)
(fma x (- y) (log1p (exp x)))
(* x (- 0.5 y)))) 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)) <= 5e+302) {
tmp = fma(x, -y, log1p(exp(x)));
} else {
tmp = x * (0.5 - y);
}
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)) <= 5e+302)
tmp = fma(x, Float64(-y), log1p(exp(x)));
else
tmp = Float64(x * Float64(0.5 - y));
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], 5e+302], N[(x * (-y) + N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x * N[(0.5 - y), $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 5 \cdot 10^{+302}:\\
\;\;\;\;\mathsf{fma}\left(x, -y, \mathsf{log1p}\left(e^{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
Alternatives Alternative 1 Accuracy 89.7% Cost 32772
\[\begin{array}{l}
\mathbf{if}\;\log \left(1 + e^{x}\right) - x \cdot y \leq 5 \cdot 10^{+302}:\\
\;\;\;\;\mathsf{fma}\left(x, -y, \mathsf{log1p}\left(e^{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 2 Accuracy 89.7% Cost 26436
\[\begin{array}{l}
\mathbf{if}\;\log \left(1 + e^{x}\right) - x \cdot y \leq 5 \cdot 10^{+302}:\\
\;\;\;\;\mathsf{log1p}\left(e^{x}\right) - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 3 Accuracy 74.9% Cost 7257
\[\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -3.4 \cdot 10^{-52}:\\
\;\;\;\;\log 2\\
\mathbf{elif}\;x \leq -2.8 \cdot 10^{-97}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-171} \lor \neg \left(x \leq 5.8 \cdot 10^{-136}\right) \land x \leq 6.7 \cdot 10^{-46}:\\
\;\;\;\;\log 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 4 Accuracy 74.8% Cost 7257
\[\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -1.36 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -5.5 \cdot 10^{-51}:\\
\;\;\;\;\log 2 + x \cdot 0.5\\
\mathbf{elif}\;x \leq -1.05 \cdot 10^{-97}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-171} \lor \neg \left(x \leq 3.2 \cdot 10^{-136}\right) \land x \leq 5.5 \cdot 10^{-47}:\\
\;\;\;\;\log 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 5 Accuracy 87.9% Cost 6984
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.52 \cdot 10^{+29}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;x \leq 1.4:\\
\;\;\;\;\log 2 - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 6 Accuracy 88.1% Cost 6980
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.52 \cdot 10^{+29}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right) + \log 2\\
\end{array}
\]
Alternative 7 Accuracy 52.9% Cost 452
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-300}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 8 Accuracy 50.7% Cost 256
\[y \cdot \left(-x\right)
\]
Alternative 9 Accuracy 5.3% Cost 192
\[x \cdot 0.5
\]