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:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot 0.125, {x}^{4} \cdot -0.0859375\right)\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_1 := \sqrt{t_0}\\
t_2 := t_1 \cdot t_1\\
\frac{1}{\frac{1 + \sqrt{0.5 + t_0}}{\mathsf{fma}\left(1, 0.5, -t_2\right) + \mathsf{fma}\left(-t_1, t_1, t_2\right)}}
\end{array}\\
\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.0)
(fma x (* x 0.125) (* (pow x 4.0) -0.0859375))
(let* ((t_0 (/ 0.5 (hypot 1.0 x))) (t_1 (sqrt t_0)) (t_2 (* t_1 t_1)))
(/
1.0
(/
(+ 1.0 (sqrt (+ 0.5 t_0)))
(+ (fma 1.0 0.5 (- t_2)) (fma (- t_1) t_1 t_2)))))))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.0) {
tmp = fma(x, (x * 0.125), (pow(x, 4.0) * -0.0859375));
} else {
double t_0 = 0.5 / hypot(1.0, x);
double t_1 = sqrt(t_0);
double t_2 = t_1 * t_1;
tmp = 1.0 / ((1.0 + sqrt(0.5 + t_0)) / (fma(1.0, 0.5, -t_2) + fma(-t_1, t_1, t_2)));
}
return tmp;
}



Bits error versus x
if (hypot.f64 1 x) < 1Initial program 30.4
Simplified30.4
Applied flip--_binary6430.4
Simplified30.4
Taylor expanded in x around 0 0.0
Simplified0
if 1 < (hypot.f64 1 x) Initial program 1.7
Simplified1.7
Applied flip--_binary641.7
Simplified0.7
Applied clear-num_binary640.7
Applied add-sqr-sqrt_binary640.7
Applied *-un-lft-identity_binary640.7
Applied prod-diff_binary640.7
Final simplification0.4
herbie shell --seed 2021329
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))