Average Error: 15.4 → 0.6
Time: 13.1s
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\\ t_2 := \sqrt{t_1}\\ t_3 := \left(1 + t_1\right) - t_2\\ t_4 := 1 + {t_1}^{1.5}\\ t_5 := \frac{t_0}{t_4}\\ \mathbf{if}\;x \leq -0.521386531283366:\\ \;\;\;\;\mathsf{fma}\left(\frac{0.5}{t_4}, t_3, t_3 \cdot \frac{\frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}{t_4}\right) + \mathsf{fma}\left(t_2 + \left(-1 + \left(-0.5 - t_0\right)\right), t_5, t_3 \cdot t_5\right)\\ \mathbf{elif}\;x \leq 7.218359721693619 \cdot 10^{-16}:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot 0.125, \mathsf{fma}\left({x}^{4}, -0.0859375, \mathsf{fma}\left({x}^{6}, 0.0673828125, {x}^{8} \cdot -0.056243896484375\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - t_0}{1 + t_2}\\ \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))
        (t_2 (sqrt t_1))
        (t_3 (- (+ 1.0 t_1) t_2))
        (t_4 (+ 1.0 (pow t_1 1.5)))
        (t_5 (/ t_0 t_4)))
   (if (<= x -0.521386531283366)
     (+
      (fma (/ 0.5 t_4) t_3 (* t_3 (/ (/ -0.5 (hypot 1.0 x)) t_4)))
      (fma (+ t_2 (+ -1.0 (- -0.5 t_0))) t_5 (* t_3 t_5)))
     (if (<= x 7.218359721693619e-16)
       (fma
        x
        (* x 0.125)
        (fma
         (pow x 4.0)
         -0.0859375
         (fma (pow x 6.0) 0.0673828125 (* (pow x 8.0) -0.056243896484375))))
       (/ (- 0.5 t_0) (+ 1.0 t_2))))))
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 t_2 = sqrt(t_1);
	double t_3 = (1.0 + t_1) - t_2;
	double t_4 = 1.0 + pow(t_1, 1.5);
	double t_5 = t_0 / t_4;
	double tmp;
	if (x <= -0.521386531283366) {
		tmp = fma((0.5 / t_4), t_3, (t_3 * ((-0.5 / hypot(1.0, x)) / t_4))) + fma((t_2 + (-1.0 + (-0.5 - t_0))), t_5, (t_3 * t_5));
	} else if (x <= 7.218359721693619e-16) {
		tmp = fma(x, (x * 0.125), fma(pow(x, 4.0), -0.0859375, fma(pow(x, 6.0), 0.0673828125, (pow(x, 8.0) * -0.056243896484375))));
	} else {
		tmp = (0.5 - t_0) / (1.0 + t_2);
	}
	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))
	t_1 = Float64(0.5 + t_0)
	t_2 = sqrt(t_1)
	t_3 = Float64(Float64(1.0 + t_1) - t_2)
	t_4 = Float64(1.0 + (t_1 ^ 1.5))
	t_5 = Float64(t_0 / t_4)
	tmp = 0.0
	if (x <= -0.521386531283366)
		tmp = Float64(fma(Float64(0.5 / t_4), t_3, Float64(t_3 * Float64(Float64(-0.5 / hypot(1.0, x)) / t_4))) + fma(Float64(t_2 + Float64(-1.0 + Float64(-0.5 - t_0))), t_5, Float64(t_3 * t_5)));
	elseif (x <= 7.218359721693619e-16)
		tmp = fma(x, Float64(x * 0.125), fma((x ^ 4.0), -0.0859375, fma((x ^ 6.0), 0.0673828125, Float64((x ^ 8.0) * -0.056243896484375))));
	else
		tmp = Float64(Float64(0.5 - t_0) / Float64(1.0 + t_2));
	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]}, Block[{t$95$1 = N[(0.5 + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[(N[(1.0 + t$95$1), $MachinePrecision] - t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[(1.0 + N[Power[t$95$1, 1.5], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$0 / t$95$4), $MachinePrecision]}, If[LessEqual[x, -0.521386531283366], N[(N[(N[(0.5 / t$95$4), $MachinePrecision] * t$95$3 + N[(t$95$3 * N[(N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] / t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$2 + N[(-1.0 + N[(-0.5 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$5 + N[(t$95$3 * t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.218359721693619e-16], N[(x * N[(x * 0.125), $MachinePrecision] + N[(N[Power[x, 4.0], $MachinePrecision] * -0.0859375 + N[(N[Power[x, 6.0], $MachinePrecision] * 0.0673828125 + N[(N[Power[x, 8.0], $MachinePrecision] * -0.056243896484375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 - t$95$0), $MachinePrecision] / N[(1.0 + t$95$2), $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)}\\
t_1 := 0.5 + t_0\\
t_2 := \sqrt{t_1}\\
t_3 := \left(1 + t_1\right) - t_2\\
t_4 := 1 + {t_1}^{1.5}\\
t_5 := \frac{t_0}{t_4}\\
\mathbf{if}\;x \leq -0.521386531283366:\\
\;\;\;\;\mathsf{fma}\left(\frac{0.5}{t_4}, t_3, t_3 \cdot \frac{\frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}{t_4}\right) + \mathsf{fma}\left(t_2 + \left(-1 + \left(-0.5 - t_0\right)\right), t_5, t_3 \cdot t_5\right)\\

\mathbf{elif}\;x \leq 7.218359721693619 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot 0.125, \mathsf{fma}\left({x}^{4}, -0.0859375, \mathsf{fma}\left({x}^{6}, 0.0673828125, {x}^{8} \cdot -0.056243896484375\right)\right)\right)\\

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


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if x < -0.521386531283365984

    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. Applied egg-rr0.0

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

    if -0.521386531283365984 < x < 7.21835972169361915e-16

    1. Initial program 29.2

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

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

      \[\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}{0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + \left(-0.056243896484375 \cdot {x}^{8} + -0.0859375 \cdot {x}^{4}\right)\right)} \]
    5. Simplified0.1

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

    if 7.21835972169361915e-16 < x

    1. Initial program 2.9

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

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
    3. Applied egg-rr2.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.6

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