Average Error: 15.7 → 0.4
Time: 4.8s
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:\\ \;\;\;\;\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} \]
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;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 30.4

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

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

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

      \[\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}{0.125 \cdot {x}^{2} - 0.0859375 \cdot {x}^{4}} \]
    6. Simplified0

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

    if 1 < (hypot.f64 1 x)

    1. Initial program 1.7

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

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

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

      \[\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 clear-num_binary640.7

      \[\leadsto \color{blue}{\frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    6. Applied add-sqr-sqrt_binary640.7

      \[\leadsto \frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{0.5 - \color{blue}{\sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}} \]
    7. Applied *-un-lft-identity_binary640.7

      \[\leadsto \frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{\color{blue}{1 \cdot 0.5} - \sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
    8. Applied prod-diff_binary640.7

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

    \[\leadsto \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}:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{\mathsf{fma}\left(1, 0.5, -\sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) + \mathsf{fma}\left(-\sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}, \sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}, \sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}}\\ \end{array} \]

Reproduce

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)))))))