Average Error: 15.6 → 0.2
Time: 3.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 2:\\ \;\;\;\;\mathsf{fma}\left(0.125, x \cdot x, \mathsf{fma}\left(0.0673828125, {x}^{6}, {x}^{4} \cdot -0.0859375\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \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) 2.0)
   (fma
    0.125
    (* x x)
    (fma 0.0673828125 (pow x 6.0) (* (pow x 4.0) -0.0859375)))
   (/
    (+ 0.5 (/ -0.5 (hypot 1.0 x)))
    (+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))))
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) <= 2.0) {
		tmp = fma(0.125, (x * x), fma(0.0673828125, pow(x, 6.0), (pow(x, 4.0) * -0.0859375)));
	} else {
		tmp = (0.5 + (-0.5 / hypot(1.0, x))) / (1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x)))));
	}
	return tmp;
}
function code(x)
	return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x))))))
end
function code(x)
	tmp = 0.0
	if (hypot(1.0, x) <= 2.0)
		tmp = fma(0.125, Float64(x * x), fma(0.0673828125, (x ^ 6.0), Float64((x ^ 4.0) * -0.0859375)));
	else
		tmp = Float64(Float64(0.5 + Float64(-0.5 / hypot(1.0, x))) / Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))));
	end
	return tmp
end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 2.0], N[(0.125 * N[(x * x), $MachinePrecision] + N[(0.0673828125 * N[Power[x, 6.0], $MachinePrecision] + N[(N[Power[x, 4.0], $MachinePrecision] * -0.0859375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
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 2:\\
\;\;\;\;\mathsf{fma}\left(0.125, x \cdot x, \mathsf{fma}\left(0.0673828125, {x}^{6}, {x}^{4} \cdot -0.0859375\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\


\end{array}

Error

Bits error versus x

Derivation

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

    1. Initial program 30.0

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

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

      \[\leadsto \color{blue}{\left(0.0673828125 \cdot {x}^{6} + 0.125 \cdot {x}^{2}\right) - 0.0859375 \cdot {x}^{4}} \]
    4. Simplified0.3

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

    if 2 < (hypot.f64 1 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{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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