\[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\]
↓
\[\begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -10:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x - \frac{x}{\frac{-1 - \mathsf{hypot}\left(1, x\right)}{x}}\right), x\right)\\
\end{array}
\]
(FPCore (x)
:precision binary64
(copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
↓
(FPCore (x)
:precision binary64
(if (<= (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x) -10.0)
(copysign (log (/ 1.0 (- (hypot 1.0 x) x))) x)
(copysign (log1p (- x (/ x (/ (- -1.0 (hypot 1.0 x)) x)))) x)))
double code(double x) {
return copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
}
↓
double code(double x) {
double tmp;
if (copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x) <= -10.0) {
tmp = copysign(log((1.0 / (hypot(1.0, x) - x))), x);
} else {
tmp = copysign(log1p((x - (x / ((-1.0 - hypot(1.0, x)) / x)))), x);
}
return tmp;
}
public static double code(double x) {
return Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
}
↓
public static double code(double x) {
double tmp;
if (Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x) <= -10.0) {
tmp = Math.copySign(Math.log((1.0 / (Math.hypot(1.0, x) - x))), x);
} else {
tmp = Math.copySign(Math.log1p((x - (x / ((-1.0 - Math.hypot(1.0, x)) / x)))), x);
}
return tmp;
}
def code(x):
return math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x)
↓
def code(x):
tmp = 0
if math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x) <= -10.0:
tmp = math.copysign(math.log((1.0 / (math.hypot(1.0, x) - x))), x)
else:
tmp = math.copysign(math.log1p((x - (x / ((-1.0 - math.hypot(1.0, x)) / x)))), x)
return tmp
function code(x)
return copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x)
end
↓
function code(x)
tmp = 0.0
if (copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x) <= -10.0)
tmp = copysign(log(Float64(1.0 / Float64(hypot(1.0, x) - x))), x);
else
tmp = copysign(log1p(Float64(x - Float64(x / Float64(Float64(-1.0 - hypot(1.0, x)) / x)))), x);
end
return tmp
end
code[x_] := N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
↓
code[x_] := If[LessEqual[N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], -10.0], N[With[{TMP1 = Abs[N[Log[N[(1.0 / N[(N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], N[With[{TMP1 = Abs[N[Log[1 + N[(x - N[(x / N[(N[(-1.0 - N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]]
\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
↓
\begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -10:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x - \frac{x}{\frac{-1 - \mathsf{hypot}\left(1, x\right)}{x}}\right), x\right)\\
\end{array}
Alternatives
| Alternative 1 |
|---|
| Error | 0.2 |
|---|
| Cost | 19784 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.26:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.00096:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\
\end{array}
\]
| Alternative 2 |
|---|
| Error | 0.0 |
|---|
| Cost | 19784 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.00094:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.00096:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\
\end{array}
\]
| Alternative 3 |
|---|
| Error | 0.3 |
|---|
| Cost | 19780 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.25:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) + -1\right)\right), x\right)\\
\end{array}
\]
| Alternative 4 |
|---|
| Error | 0.3 |
|---|
| Cost | 13832 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.3:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 1.26:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x - \frac{x}{x \cdot -0.5 + \frac{-2}{x}}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\
\end{array}
\]
| Alternative 5 |
|---|
| Error | 0.8 |
|---|
| Cost | 13828 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.3:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x - \frac{x}{-1 + \frac{-0.5 - x}{x \cdot x}}\right), x\right)\\
\end{array}
\]
| Alternative 6 |
|---|
| Error | 0.3 |
|---|
| Cost | 13576 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.26:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 0.96:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\
\end{array}
\]
| Alternative 7 |
|---|
| Error | 0.4 |
|---|
| Cost | 13512 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.26:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 1.26:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\
\end{array}
\]
| Alternative 8 |
|---|
| Error | 11.3 |
|---|
| Cost | 13320 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -3.2:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\
\mathbf{elif}\;x \leq 1.26:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\
\end{array}
\]
| Alternative 9 |
|---|
| Error | 0.5 |
|---|
| Cost | 13320 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.26:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{elif}\;x \leq 1.26:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\
\end{array}
\]
| Alternative 10 |
|---|
| Error | 22.3 |
|---|
| Cost | 13124 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\
\end{array}
\]
| Alternative 11 |
|---|
| Error | 26.1 |
|---|
| Cost | 13060 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq 1.58:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\
\end{array}
\]
| Alternative 12 |
|---|
| Error | 30.2 |
|---|
| Cost | 6528 |
|---|
\[\mathsf{copysign}\left(x, x\right)
\]