Average Error: 15.3 → 0.2
Time: 7.7s
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.25}{\mathsf{fma}\left(x, x, 1\right)}\\ t_1 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0000000000000013:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, -0.0859375, 0.125 \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{0.0625 - \sqrt{{t_0}^{4}}}{0.25 - t_0} \cdot \frac{1}{t_1}\right) \cdot \frac{1}{1 + \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.25 (fma x x 1.0))) (t_1 (+ 0.5 (/ 0.5 (hypot 1.0 x)))))
   (if (<= (hypot 1.0 x) 1.0000000000000013)
     (fma (pow x 4.0) -0.0859375 (* 0.125 (* x x)))
     (*
      (* (/ (- 0.0625 (sqrt (pow t_0 4.0))) (- 0.25 t_0)) (/ 1.0 t_1))
      (/ 1.0 (+ 1.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.25 / fma(x, x, 1.0);
	double t_1 = 0.5 + (0.5 / hypot(1.0, x));
	double tmp;
	if (hypot(1.0, x) <= 1.0000000000000013) {
		tmp = fma(pow(x, 4.0), -0.0859375, (0.125 * (x * x)));
	} else {
		tmp = (((0.0625 - sqrt(pow(t_0, 4.0))) / (0.25 - t_0)) * (1.0 / t_1)) * (1.0 / (1.0 + sqrt(t_1)));
	}
	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)
	t_0 = Float64(-0.25 / fma(x, x, 1.0))
	t_1 = Float64(0.5 + Float64(0.5 / hypot(1.0, x)))
	tmp = 0.0
	if (hypot(1.0, x) <= 1.0000000000000013)
		tmp = fma((x ^ 4.0), -0.0859375, Float64(0.125 * Float64(x * x)));
	else
		tmp = Float64(Float64(Float64(Float64(0.0625 - sqrt((t_0 ^ 4.0))) / Float64(0.25 - t_0)) * Float64(1.0 / t_1)) * Float64(1.0 / Float64(1.0 + sqrt(t_1))));
	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_] := Block[{t$95$0 = N[(-0.25 / N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0000000000000013], N[(N[Power[x, 4.0], $MachinePrecision] * -0.0859375 + N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.0625 - N[Sqrt[N[Power[t$95$0, 4.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(0.25 - t$95$0), $MachinePrecision]), $MachinePrecision] * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(1.0 + N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
t_0 := \frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}\\
t_1 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0000000000000013:\\
\;\;\;\;\mathsf{fma}\left({x}^{4}, -0.0859375, 0.125 \cdot \left(x \cdot x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{0.0625 - \sqrt{{t_0}^{4}}}{0.25 - t_0} \cdot \frac{1}{t_1}\right) \cdot \frac{1}{1 + \sqrt{t_1}}\\


\end{array}

Error

Bits error versus x

Derivation

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

    1. Initial program 30.4

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

      \[\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}{0.125 \cdot {x}^{2} - 0.0859375 \cdot {x}^{4}} \]
    4. Simplified0.0

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

    if 1.0000000000000013 < (hypot.f64 1 x)

    1. Initial program 1.4

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

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

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

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

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

      \[\leadsto \left(\frac{0.0625 - \color{blue}{\sqrt{{\left(\frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}\right)}^{4}}}}{0.25 - \frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}} \cdot \frac{1}{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{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 1.0000000000000013:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, -0.0859375, 0.125 \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{0.0625 - \sqrt{{\left(\frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}\right)}^{4}}}{0.25 - \frac{-0.25}{\mathsf{fma}\left(x, x, 1\right)}} \cdot \frac{1}{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\ \end{array} \]

Reproduce

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