\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\]
↓
\[\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - \sqrt{\frac{0.25}{1 + x \cdot x}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\
\end{array}
\]
(FPCore (x)
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
↓
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 1.2)
(fma (* x 0.125) x (* -0.0859375 (pow x 4.0)))
(/
(- 0.5 (sqrt (/ 0.25 (+ 1.0 (* x x)))))
(+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))))double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
↓
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.2) {
tmp = fma((x * 0.125), x, (-0.0859375 * pow(x, 4.0)));
} else {
tmp = (0.5 - sqrt((0.25 / (1.0 + (x * x))))) / (1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x)))));
}
return tmp;
}
function code(x)
return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x))))))
end
↓
function code(x)
tmp = 0.0
if (hypot(1.0, x) <= 1.2)
tmp = fma(Float64(x * 0.125), x, Float64(-0.0859375 * (x ^ 4.0)));
else
tmp = Float64(Float64(0.5 - sqrt(Float64(0.25 / Float64(1.0 + Float64(x * x))))) / Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))));
end
return tmp
end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
↓
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.2], N[(N[(x * 0.125), $MachinePrecision] * x + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 - N[Sqrt[N[(0.25 / N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
↓
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - \sqrt{\frac{0.25}{1 + x \cdot x}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\
\end{array}
Alternatives
| Alternative 1 |
|---|
| Error | 0.23% |
|---|
| Cost | 26756 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\
\end{array}
\]
| Alternative 2 |
|---|
| Error | 0.69% |
|---|
| Cost | 13828 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.64:\\
\;\;\;\;\frac{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 - \frac{0.5}{x}}}\\
\mathbf{elif}\;x \leq 0.0024:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
\end{array}
\]
| Alternative 3 |
|---|
| Error | 1.1% |
|---|
| Cost | 13576 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.1:\\
\;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\
\mathbf{elif}\;x \leq 0.0024:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(0.125 + -0.0859375 \cdot \left(x \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
\end{array}
\]
| Alternative 4 |
|---|
| Error | 1.09% |
|---|
| Cost | 13576 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.1:\\
\;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\
\mathbf{elif}\;x \leq 0.0024:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
\end{array}
\]
| Alternative 5 |
|---|
| Error | 1.23% |
|---|
| Cost | 13316 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(0.125 + -0.0859375 \cdot \left(x \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\
\end{array}
\]
| Alternative 6 |
|---|
| Error | 0.95% |
|---|
| Cost | 7496 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.1:\\
\;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\
\mathbf{elif}\;x \leq 1.1:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(0.125 + -0.0859375 \cdot \left(x \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{0.5}{x}}}\\
\end{array}
\]
| Alternative 7 |
|---|
| Error | 1.98% |
|---|
| Cost | 6857 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \lor \neg \left(x \leq 1.1\right):\\
\;\;\;\;1 - \sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(0.125 + -0.0859375 \cdot \left(x \cdot x\right)\right)\\
\end{array}
\]
| Alternative 8 |
|---|
| Error | 39.38% |
|---|
| Cost | 968 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.15:\\
\;\;\;\;\frac{0.5 - \frac{0.5}{x}}{2}\\
\mathbf{elif}\;x \leq 1.1:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(0.125 + -0.0859375 \cdot \left(x \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.25\\
\end{array}
\]
| Alternative 9 |
|---|
| Error | 39.63% |
|---|
| Cost | 584 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.4:\\
\;\;\;\;0.25\\
\mathbf{elif}\;x \leq 1.4:\\
\;\;\;\;0.125 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;0.25\\
\end{array}
\]
| Alternative 10 |
|---|
| Error | 39.63% |
|---|
| Cost | 584 |
|---|
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.8:\\
\;\;\;\;\frac{0.5 - \frac{0.5}{x}}{2}\\
\mathbf{elif}\;x \leq 1.4:\\
\;\;\;\;0.125 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;0.25\\
\end{array}
\]
| Alternative 11 |
|---|
| Error | 49.83% |
|---|
| Cost | 320 |
|---|
\[0.125 \cdot \left(x \cdot x\right)
\]
| Alternative 12 |
|---|
| Error | 73.32% |
|---|
| Cost | 64 |
|---|
\[0
\]