Average Error: 15.6 → 0.0
Time: 6.0s
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 := \sqrt{t_1}\\ \mathbf{if}\;x \leq -0.0108257881037984:\\ \;\;\;\;\left(1 - {t_1}^{1.5}\right) \cdot \sqrt{{\left(1.5 + \left(t_0 + t_2\right)\right)}^{-2}}\\ \mathbf{elif}\;x \leq 0.010586867664495958:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, -0.0859375, \mathsf{fma}\left(0.125, x \cdot x, 0.0673828125 \cdot {x}^{6}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + t_2} \cdot {\left(\frac{1}{0.5 - t_0}\right)}^{-1}\\ \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 := \sqrt{t_1}\\
\mathbf{if}\;x \leq -0.0108257881037984:\\
\;\;\;\;\left(1 - {t_1}^{1.5}\right) \cdot \sqrt{{\left(1.5 + \left(t_0 + t_2\right)\right)}^{-2}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + t_2} \cdot {\left(\frac{1}{0.5 - t_0}\right)}^{-1}\\


\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 (sqrt t_1)))
   (if (<= x -0.0108257881037984)
     (* (- 1.0 (pow t_1 1.5)) (sqrt (pow (+ 1.5 (+ t_0 t_2)) -2.0)))
     (if (<= x 0.010586867664495958)
       (fma
        (pow x 4.0)
        -0.0859375
        (fma 0.125 (* x x) (* 0.0673828125 (pow x 6.0))))
       (* (/ 1.0 (+ 1.0 t_2)) (pow (/ 1.0 (- 0.5 t_0)) -1.0))))))
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 = sqrt(t_1);
	double tmp;
	if (x <= -0.0108257881037984) {
		tmp = (1.0 - pow(t_1, 1.5)) * sqrt(pow((1.5 + (t_0 + t_2)), -2.0));
	} else if (x <= 0.010586867664495958) {
		tmp = fma(pow(x, 4.0), -0.0859375, fma(0.125, (x * x), (0.0673828125 * pow(x, 6.0))));
	} else {
		tmp = (1.0 / (1.0 + t_2)) * pow((1.0 / (0.5 - t_0)), -1.0);
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    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 egg-rr1.0

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

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

    if -0.0108257881037984 < x < 0.01058686766449596

    1. Initial program 30.1

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

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. 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}} \]
    4. Simplified0.0

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

    if 0.01058686766449596 < 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 egg-rr0.0

      \[\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)}}}} \]
    4. Applied egg-rr0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.0108257881037984:\\ \;\;\;\;\left(1 - {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{1.5}\right) \cdot \sqrt{{\left(1.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}^{-2}}\\ \mathbf{elif}\;x \leq 0.010586867664495958:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, -0.0859375, \mathsf{fma}\left(0.125, x \cdot x, 0.0673828125 \cdot {x}^{6}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \cdot {\left(\frac{1}{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{-1}\\ \end{array} \]

Reproduce

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