Average Error: 15.4 → 0.0
Time: 6.2s
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 := 1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \mathbf{if}\;x \leq -0.027965099262194516:\\ \;\;\;\;\frac{\mathsf{fma}\left(1, 0.5, t_0\right)}{t_1}\\ \mathbf{elif}\;x \leq 0.028761853505194473:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, 0.125, {x}^{6} \cdot 0.0673828125\right) - \mathsf{fma}\left({x}^{4}, 0.0859375, {x}^{8} \cdot 0.056243896484375\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(0.5 + t_0\right)\right)}{t_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 := 1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
\mathbf{if}\;x \leq -0.027965099262194516:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, 0.5, t_0\right)}{t_1}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(0.5 + t_0\right)\right)}{t_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 (+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x)))))))
   (if (<= x -0.027965099262194516)
     (/ (fma 1.0 0.5 t_0) t_1)
     (if (<= x 0.028761853505194473)
       (-
        (fma (* x x) 0.125 (* (pow x 6.0) 0.0673828125))
        (fma (pow x 4.0) 0.0859375 (* (pow x 8.0) 0.056243896484375)))
       (/ (log1p (expm1 (+ 0.5 t_0))) t_1)))))
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 = 1.0 + sqrt(0.5 + (0.5 / hypot(1.0, x)));
	double tmp;
	if (x <= -0.027965099262194516) {
		tmp = fma(1.0, 0.5, t_0) / t_1;
	} else if (x <= 0.028761853505194473) {
		tmp = fma((x * x), 0.125, (pow(x, 6.0) * 0.0673828125)) - fma(pow(x, 4.0), 0.0859375, (pow(x, 8.0) * 0.056243896484375));
	} else {
		tmp = log1p(expm1(0.5 + t_0)) / t_1;
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    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.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 *-un-lft-identity_binary640.1

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

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

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

    if -0.027965099262194516 < x < 0.028761853505194473

    1. Initial program 29.8

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

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

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

      \[\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) - \left(0.0859375 \cdot {x}^{4} + 0.056243896484375 \cdot {x}^{8}\right)} \]
    6. Simplified0.0

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

    if 0.028761853505194473 < 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.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. Applied log1p-expm1-u_binary640.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.027965099262194516:\\ \;\;\;\;\frac{\mathsf{fma}\left(1, 0.5, \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \mathbf{elif}\;x \leq 0.028761853505194473:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, 0.125, {x}^{6} \cdot 0.0673828125\right) - \mathsf{fma}\left({x}^{4}, 0.0859375, {x}^{8} \cdot 0.056243896484375\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right)\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]

Reproduce

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