Average Error: 15.5 → 0.0
Time: 4.0s
Precision: binary64
\[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.0000000485669474:\\ \;\;\;\;\mathsf{fma}\left({x}^{6}, 0.0673828125, \mathsf{fma}\left(x, x \cdot 0.125, {x}^{4} \cdot -0.0859375\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ \frac{0.5 - t_0}{1 + \sqrt{0.5 + t_0}} \end{array}\\ \end{array} \]
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.0000000485669474:\\
\;\;\;\;\mathsf{fma}\left({x}^{6}, 0.0673828125, \mathsf{fma}\left(x, x \cdot 0.125, {x}^{4} \cdot -0.0859375\right)\right)\\

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

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if (hypot.f64 1 x) < 1.0000000485669474

    1. Initial program 30.3

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

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

      \[\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.3

      \[\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.0

      \[\leadsto \color{blue}{\left(0.0673828125 \cdot {x}^{6} + 0.125 \cdot {x}^{2}\right) - 0.0859375 \cdot {x}^{4}} \]
    6. Simplified0.0

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

    if 1.0000000485669474 < (hypot.f64 1 x)

    1. Initial program 1.1

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

      \[\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)}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0000000485669474:\\ \;\;\;\;\mathsf{fma}\left({x}^{6}, 0.0673828125, \mathsf{fma}\left(x, x \cdot 0.125, {x}^{4} \cdot -0.0859375\right)\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} \]

Reproduce

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