Average Error: 15.3 → 0.2
Time: 5.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 + t_0}\\ \mathbf{if}\;x \leq -0.010110969448982569:\\ \;\;\;\;\frac{\log \left(e^{0.5 - t_0}\right)}{t_1}\\ \mathbf{elif}\;x \leq 1.3900848933172312:\\ \;\;\;\;\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{\log \left(\mathsf{fma}\left(\frac{e^{0.5}}{x}, -0.5, e^{0.5}\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 + t_0}\\
\mathbf{if}\;x \leq -0.010110969448982569:\\
\;\;\;\;\frac{\log \left(e^{0.5 - t_0}\right)}{t_1}\\

\mathbf{elif}\;x \leq 1.3900848933172312:\\
\;\;\;\;\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{\log \left(\mathsf{fma}\left(\frac{e^{0.5}}{x}, -0.5, e^{0.5}\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 t_0)))))
   (if (<= x -0.010110969448982569)
     (/ (log (exp (- 0.5 t_0))) t_1)
     (if (<= x 1.3900848933172312)
       (fma
        (pow x 6.0)
        0.0673828125
        (fma x (* x 0.125) (* (pow x 4.0) -0.0859375)))
       (/ (log (fma (/ (exp 0.5) x) -0.5 (exp 0.5))) 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 + t_0);
	double tmp;
	if (x <= -0.010110969448982569) {
		tmp = log(exp(0.5 - t_0)) / t_1;
	} else if (x <= 1.3900848933172312) {
		tmp = fma(pow(x, 6.0), 0.0673828125, fma(x, (x * 0.125), (pow(x, 4.0) * -0.0859375)));
	} else {
		tmp = log(fma((exp(0.5) / x), -0.5, exp(0.5))) / t_1;
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    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 add-log-exp_binary640.1

      \[\leadsto \frac{0.5 - \color{blue}{\log \left(e^{\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 add-log-exp_binary640.1

      \[\leadsto \frac{\color{blue}{\log \left(e^{0.5}\right)} - \log \left(e^{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    7. Applied diff-log_binary640.1

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{0.5}}{e^{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    8. Simplified0.1

      \[\leadsto \frac{\log \color{blue}{\left(e^{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)}}} \]

    if -0.010110969448982569 < x < 1.3900848933172312

    1. Initial program 29.7

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

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Applied flip--_binary6429.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. Simplified29.6

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

      \[\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.3900848933172312 < 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 add-log-exp_binary640.0

      \[\leadsto \frac{0.5 - \color{blue}{\log \left(e^{\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 add-log-exp_binary640.0

      \[\leadsto \frac{\color{blue}{\log \left(e^{0.5}\right)} - \log \left(e^{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    7. Applied diff-log_binary640.0

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{0.5}}{e^{\frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    8. Taylor expanded in x around inf 0.5

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

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{fma}\left(\frac{e^{0.5}}{x}, -0.5, e^{0.5}\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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.010110969448982569:\\ \;\;\;\;\frac{\log \left(e^{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 1.3900848933172312:\\ \;\;\;\;\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{\log \left(\mathsf{fma}\left(\frac{e^{0.5}}{x}, -0.5, e^{0.5}\right)\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]

Reproduce

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