Average Error: 15.5 → 0.2
Time: 5.4s
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\\ \mathbf{if}\;x \leq -0.00010956238046010226:\\ \;\;\;\;\frac{t_1}{1 + \log \left(e^{\sqrt{0.5 + t_0}}\right)}\\ \mathbf{elif}\;x \leq 0.00012153717904520032:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{1 + \frac{\sqrt{0.25 - t_0 \cdot t_0}}{\sqrt{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 := 0.5 - t_0\\
\mathbf{if}\;x \leq -0.00010956238046010226:\\
\;\;\;\;\frac{t_1}{1 + \log \left(e^{\sqrt{0.5 + t_0}}\right)}\\

\mathbf{elif}\;x \leq 0.00012153717904520032:\\
\;\;\;\;0.125 \cdot {x}^{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{1 + \frac{\sqrt{0.25 - t_0 \cdot t_0}}{\sqrt{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 (- 0.5 t_0)))
   (if (<= x -0.00010956238046010226)
     (/ t_1 (+ 1.0 (log (exp (sqrt (+ 0.5 t_0))))))
     (if (<= x 0.00012153717904520032)
       (* 0.125 (pow x 2.0))
       (/ t_1 (+ 1.0 (/ (sqrt (- 0.25 (* t_0 t_0))) (sqrt 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 = 0.5 - t_0;
	double tmp;
	if (x <= -0.00010956238046010226) {
		tmp = t_1 / (1.0 + log(exp(sqrt(0.5 + t_0))));
	} else if (x <= 0.00012153717904520032) {
		tmp = 0.125 * pow(x, 2.0);
	} else {
		tmp = t_1 / (1.0 + (sqrt(0.25 - (t_0 * t_0)) / sqrt(t_1)));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if x < -1.0956238046010226e-4

    1. Initial program 1.2

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

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

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

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

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

    if -1.0956238046010226e-4 < x < 1.21537179045200323e-4

    1. Initial program 30.2

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

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Taylor expanded in x around 0 0.2

      \[\leadsto \color{blue}{0.125 \cdot {x}^{2}} \]

    if 1.21537179045200323e-4 < 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)}}} \]
    5. Applied flip-+_binary640.1

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

      \[\leadsto \frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \color{blue}{\frac{\sqrt{0.5 \cdot 0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{\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.00010956238046010226:\\ \;\;\;\;\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \log \left(e^{\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\right)}\\ \mathbf{elif}\;x \leq 0.00012153717904520032:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \frac{\sqrt{0.25 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{\sqrt{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}\\ \end{array} \]

Reproduce

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