Average Error: 15.5 → 0.2
Time: 15.7s
Precision: binary64
\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
\[\begin{array}{l} t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ t_1 := 0.5 + t_0\\ t_2 := 1 + \sqrt{t_1}\\ \mathbf{if}\;x \leq -1.1194795210131447:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{t_2}\\ \mathbf{elif}\;x \leq 0.0028247687920924316:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot 0.125, {x}^{4} \cdot -0.0859375\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.125 - {t_0}^{3}}{t_2 \cdot \mathsf{fma}\left(t_0, t_1, 0.25\right)}\\ \end{array} \]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_1 := 0.5 + t_0\\
t_2 := 1 + \sqrt{t_1}\\
\mathbf{if}\;x \leq -1.1194795210131447:\\
\;\;\;\;\frac{0.5 + \frac{0.5}{x}}{t_2}\\

\mathbf{elif}\;x \leq 0.0028247687920924316:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot 0.125, {x}^{4} \cdot -0.0859375\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{0.125 - {t_0}^{3}}{t_2 \cdot \mathsf{fma}\left(t_0, t_1, 0.25\right)}\\


\end{array}
(FPCore (x)
 :precision binary64
 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ 0.5 (hypot 1.0 x))) (t_1 (+ 0.5 t_0)) (t_2 (+ 1.0 (sqrt t_1))))
   (if (<= x -1.1194795210131447)
     (/ (+ 0.5 (/ 0.5 x)) t_2)
     (if (<= x 0.0028247687920924316)
       (fma x (* x 0.125) (* (pow x 4.0) -0.0859375))
       (/ (- 0.125 (pow t_0 3.0)) (* t_2 (fma t_0 t_1 0.25)))))))
double code(double x) {
	return 1.0 - sqrt(0.5 * (1.0 + (1.0 / hypot(1.0, x))));
}
double code(double x) {
	double t_0 = 0.5 / hypot(1.0, x);
	double t_1 = 0.5 + t_0;
	double t_2 = 1.0 + sqrt(t_1);
	double tmp;
	if (x <= -1.1194795210131447) {
		tmp = (0.5 + (0.5 / x)) / t_2;
	} else if (x <= 0.0028247687920924316) {
		tmp = fma(x, (x * 0.125), (pow(x, 4.0) * -0.0859375));
	} else {
		tmp = (0.125 - pow(t_0, 3.0)) / (t_2 * fma(t_0, t_1, 0.25));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

  1. Split input into 3 regimes
  2. if x < -1.1194795210131447

    1. Initial program 1.0

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Simplified1.0

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Applied flip--_binary641.0

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    4. Simplified0.0

      \[\leadsto \frac{\color{blue}{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    5. Taylor expanded in x around -inf 0.3

      \[\leadsto \frac{\color{blue}{0.5 + 0.5 \cdot \frac{1}{x}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Simplified0.3

      \[\leadsto \frac{\color{blue}{0.5 + \frac{0.5}{x}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]

    if -1.1194795210131447 < x < 0.0028247687920924316

    1. Initial program 30.0

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Simplified30.0

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Applied flip--_binary6430.0

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    4. Simplified30.0

      \[\leadsto \frac{\color{blue}{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    5. Taylor expanded in x around 0 0.2

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2} - 0.0859375 \cdot {x}^{4}} \]
    6. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x \cdot 0.125, {x}^{4} \cdot -0.0859375\right)} \]

    if 0.0028247687920924316 < x

    1. Initial program 1.0

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
    2. Simplified1.0

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Applied flip--_binary641.1

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    4. Simplified0.1

      \[\leadsto \frac{\color{blue}{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    5. Applied flip3--_binary640.1

      \[\leadsto \frac{\color{blue}{\frac{{0.5}^{3} - {\left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}{0.5 \cdot 0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    6. Applied associate-/l/_binary640.1

      \[\leadsto \color{blue}{\frac{{0.5}^{3} - {\left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}{\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(0.5 \cdot 0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)\right)}} \]
    7. Simplified0.1

      \[\leadsto \frac{{0.5}^{3} - {\left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)}, 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}, 0.25\right) \cdot \left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.1194795210131447:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \mathbf{elif}\;x \leq 0.0028247687920924316:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot 0.125, {x}^{4} \cdot -0.0859375\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.125 - {\left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}{\left(1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \mathsf{fma}\left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)}, 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}, 0.25\right)}\\ \end{array} \]

Reproduce

herbie shell --seed 2021280 
(FPCore (x)
  :name "Given's Rotation SVD example, simplified"
  :precision binary64
  (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))