Math FPCore C Java Python 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^{+248}:\\
\;\;\;\;\mathsf{log1p}\left(e^{x}\right) - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(x - x \cdot 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+248)
(- (log1p (exp x)) (* x y))
(+ (- x (* x 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+248) {
tmp = log1p(exp(x)) - (x * y);
} else {
tmp = (x - (x * y)) + log(2.0);
}
return tmp;
}
public static double code(double x, double y) {
return Math.log((1.0 + Math.exp(x))) - (x * y);
}
↓
public static double code(double x, double y) {
double tmp;
if ((Math.log((1.0 + Math.exp(x))) - (x * y)) <= 1e+248) {
tmp = Math.log1p(Math.exp(x)) - (x * y);
} else {
tmp = (x - (x * y)) + Math.log(2.0);
}
return tmp;
}
def code(x, y):
return math.log((1.0 + math.exp(x))) - (x * y)
↓
def code(x, y):
tmp = 0
if (math.log((1.0 + math.exp(x))) - (x * y)) <= 1e+248:
tmp = math.log1p(math.exp(x)) - (x * y)
else:
tmp = (x - (x * y)) + math.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+248)
tmp = Float64(log1p(exp(x)) - Float64(x * y));
else
tmp = Float64(Float64(x - Float64(x * 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+248], N[(N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(x - N[(x * 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^{+248}:\\
\;\;\;\;\mathsf{log1p}\left(e^{x}\right) - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(x - x \cdot y\right) + \log 2\\
\end{array}
Alternatives Alternative 1 Accuracy 99.7% Cost 26436
\[\begin{array}{l}
\mathbf{if}\;\log \left(1 + e^{x}\right) - x \cdot y \leq 10^{+248}:\\
\;\;\;\;\mathsf{log1p}\left(e^{x}\right) - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(x - x \cdot y\right) + \log 2\\
\end{array}
\]
Alternative 2 Accuracy 88.9% Cost 6984
\[\begin{array}{l}
\mathbf{if}\;x \leq -58:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;x \leq 1.4:\\
\;\;\;\;\log 2 - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 3 Accuracy 89.2% Cost 6980
\[\begin{array}{l}
\mathbf{if}\;x \leq -2.05:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\log 2 + x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 4 Accuracy 99.1% Cost 6980
\[\begin{array}{l}
\mathbf{if}\;x \leq -2.05:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - x \cdot y\right) + \log 2\\
\end{array}
\]
Alternative 5 Accuracy 76.4% Cost 6728
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.02 \cdot 10^{-39}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-47}:\\
\;\;\;\;\log 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 6 Accuracy 52.4% Cost 452
\[\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-310}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 - y\right)\\
\end{array}
\]
Alternative 7 Accuracy 50.2% Cost 256
\[x \cdot \left(-y\right)
\]
Alternative 8 Accuracy 5.4% Cost 192
\[x \cdot 0.5
\]