Average Error: 15.0 → 0.0
Time: 4.8s
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)}\\ \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.000005164413152:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot 0.125, \mathsf{fma}\left({x}^{6}, 0.0673828125, \mathsf{fma}\left({x}^{8}, -0.056243896484375, {x}^{4} \cdot -0.0859375\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 + t_0}}{0.5 - t_0}}\\ \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))))
   (if (<= (hypot 1.0 x) 1.000005164413152)
     (fma
      x
      (* x 0.125)
      (fma
       (pow x 6.0)
       0.0673828125
       (fma (pow x 8.0) -0.056243896484375 (* (pow x 4.0) -0.0859375))))
     (/ 1.0 (/ (+ 1.0 (sqrt (+ 0.5 t_0))) (- 0.5 t_0))))))
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 tmp;
	if (hypot(1.0, x) <= 1.000005164413152) {
		tmp = fma(x, (x * 0.125), fma(pow(x, 6.0), 0.0673828125, fma(pow(x, 8.0), -0.056243896484375, (pow(x, 4.0) * -0.0859375))));
	} else {
		tmp = 1.0 / ((1.0 + sqrt((0.5 + t_0))) / (0.5 - t_0));
	}
	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.5 / hypot(1.0, x))
	tmp = 0.0
	if (hypot(1.0, x) <= 1.000005164413152)
		tmp = fma(x, Float64(x * 0.125), fma((x ^ 6.0), 0.0673828125, fma((x ^ 8.0), -0.056243896484375, Float64((x ^ 4.0) * -0.0859375))));
	else
		tmp = Float64(1.0 / Float64(Float64(1.0 + sqrt(Float64(0.5 + t_0))) / Float64(0.5 - t_0)));
	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.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.000005164413152], N[(x * N[(x * 0.125), $MachinePrecision] + N[(N[Power[x, 6.0], $MachinePrecision] * 0.0673828125 + N[(N[Power[x, 8.0], $MachinePrecision] * -0.056243896484375 + N[(N[Power[x, 4.0], $MachinePrecision] * -0.0859375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(1.0 + N[Sqrt[N[(0.5 + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(0.5 - t$95$0), $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.5}{\mathsf{hypot}\left(1, x\right)}\\
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.000005164413152:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot 0.125, \mathsf{fma}\left({x}^{6}, 0.0673828125, \mathsf{fma}\left({x}^{8}, -0.056243896484375, {x}^{4} \cdot -0.0859375\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 + t_0}}{0.5 - t_0}}\\


\end{array}

Error

Bits error versus x

Derivation

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

    1. Initial program 29.6

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

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

      \[\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. 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)} \]
    5. Simplified0

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

    if 1.00000516441315201 < (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.1

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

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

Reproduce

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