Average Error: 15.4 → 0.2
Time: 5.1s
Precision: binary64
\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1033926414358677:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{\left(1 + \sqrt{0.5}\right) + \frac{\frac{-0.25}{x}}{\sqrt{0.5}}}\\ \mathbf{elif}\;x \leq 0.025962973167688124:\\ \;\;\;\;\mathsf{fma}\left({x}^{6}, 0.0673828125, \mathsf{fma}\left(x, x \cdot 0.125, \mathsf{fma}\left({x}^{4}, -0.0859375, {x}^{8} \cdot -0.056243896484375\right)\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 (<= x -1.1033926414358677)
   (/ (+ 0.5 (/ 0.5 x)) (+ (+ 1.0 (sqrt 0.5)) (/ (/ -0.25 x) (sqrt 0.5))))
   (if (<= x 0.025962973167688124)
     (fma
      (pow x 6.0)
      0.0673828125
      (fma
       x
       (* x 0.125)
       (fma (pow x 4.0) -0.0859375 (* (pow x 8.0) -0.056243896484375))))
     (/
      (+ 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 (x <= -1.1033926414358677) {
		tmp = (0.5 + (0.5 / x)) / ((1.0 + sqrt(0.5)) + ((-0.25 / x) / sqrt(0.5)));
	} else if (x <= 0.025962973167688124) {
		tmp = fma(pow(x, 6.0), 0.0673828125, fma(x, (x * 0.125), fma(pow(x, 4.0), -0.0859375, (pow(x, 8.0) * -0.056243896484375))));
	} 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 (x <= -1.1033926414358677)
		tmp = Float64(Float64(0.5 + Float64(0.5 / x)) / Float64(Float64(1.0 + sqrt(0.5)) + Float64(Float64(-0.25 / x) / sqrt(0.5))));
	elseif (x <= 0.025962973167688124)
		tmp = fma((x ^ 6.0), 0.0673828125, fma(x, Float64(x * 0.125), fma((x ^ 4.0), -0.0859375, Float64((x ^ 8.0) * -0.056243896484375))));
	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[x, -1.1033926414358677], N[(N[(0.5 + N[(0.5 / x), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.25 / x), $MachinePrecision] / N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.025962973167688124], N[(N[Power[x, 6.0], $MachinePrecision] * 0.0673828125 + N[(x * N[(x * 0.125), $MachinePrecision] + N[(N[Power[x, 4.0], $MachinePrecision] * -0.0859375 + N[(N[Power[x, 8.0], $MachinePrecision] * -0.056243896484375), $MachinePrecision]), $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}\;x \leq -1.1033926414358677:\\
\;\;\;\;\frac{0.5 + \frac{0.5}{x}}{\left(1 + \sqrt{0.5}\right) + \frac{\frac{-0.25}{x}}{\sqrt{0.5}}}\\

\mathbf{elif}\;x \leq 0.025962973167688124:\\
\;\;\;\;\mathsf{fma}\left({x}^{6}, 0.0673828125, \mathsf{fma}\left(x, x \cdot 0.125, \mathsf{fma}\left({x}^{4}, -0.0859375, {x}^{8} \cdot -0.056243896484375\right)\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 3 regimes
  2. if x < -1.10339264143586768

    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)}}}} \]
    4. Taylor expanded in x around -inf 0.6

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

      \[\leadsto \frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{\color{blue}{\left(1 + \sqrt{0.5}\right) - \frac{\frac{0.25}{x}}{\sqrt{0.5}}}} \]
    6. Taylor expanded in x around -inf 0.6

      \[\leadsto \frac{\color{blue}{0.5 + 0.5 \cdot \frac{1}{x}}}{\left(1 + \sqrt{0.5}\right) - \frac{\frac{0.25}{x}}{\sqrt{0.5}}} \]
    7. Simplified0.6

      \[\leadsto \frac{\color{blue}{0.5 + \frac{0.5}{x}}}{\left(1 + \sqrt{0.5}\right) - \frac{\frac{0.25}{x}}{\sqrt{0.5}}} \]

    if -1.10339264143586768 < x < 0.0259629731676881241

    1. Initial program 29.9

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

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

      \[\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)}}}} \]
    4. Taylor expanded in x around 0 0.1

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

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

    if 0.0259629731676881241 < 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 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.1033926414358677:\\ \;\;\;\;\frac{0.5 + \frac{0.5}{x}}{\left(1 + \sqrt{0.5}\right) + \frac{\frac{-0.25}{x}}{\sqrt{0.5}}}\\ \mathbf{elif}\;x \leq 0.025962973167688124:\\ \;\;\;\;\mathsf{fma}\left({x}^{6}, 0.0673828125, \mathsf{fma}\left(x, x \cdot 0.125, \mathsf{fma}\left({x}^{4}, -0.0859375, {x}^{8} \cdot -0.056243896484375\right)\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 2022150 
(FPCore (x)
  :name "Given's Rotation SVD example, simplified"
  :precision binary64
  (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))