Average Error: 15.2 → 0.0
Time: 16.4s
Precision: binary64
Cost: 171908
\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
\[\begin{array}{l} t_0 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ t_1 := \mathsf{hypot}\left(1, {t_0}^{0.25}\right)\\ t_2 := \frac{0.5}{t_1}\\ t_3 := \frac{\frac{1}{\mathsf{hypot}\left(1, x\right)}}{t_1}\\ \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{0.5}{1 + \sqrt{t_0}}, t_3 \cdot \frac{-0.5}{t_1}\right) + \mathsf{fma}\left(\frac{\frac{-1}{\mathsf{hypot}\left(1, x\right)}}{t_1}, t_2, t_3 \cdot t_2\right)\\ \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 (/ 0.5 (hypot 1.0 x))))
        (t_1 (hypot 1.0 (pow t_0 0.25)))
        (t_2 (/ 0.5 t_1))
        (t_3 (/ (/ 1.0 (hypot 1.0 x)) t_1)))
   (if (<= (hypot 1.0 x) 1.0005)
     (+
      (* 0.125 (pow x 2.0))
      (+ (* 0.0673828125 (pow x 6.0)) (* -0.0859375 (pow x 4.0))))
     (+
      (fma 1.0 (/ 0.5 (+ 1.0 (sqrt t_0))) (* t_3 (/ -0.5 t_1)))
      (fma (/ (/ -1.0 (hypot 1.0 x)) t_1) t_2 (* t_3 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 + (0.5 / hypot(1.0, x));
	double t_1 = hypot(1.0, pow(t_0, 0.25));
	double t_2 = 0.5 / t_1;
	double t_3 = (1.0 / hypot(1.0, x)) / t_1;
	double tmp;
	if (hypot(1.0, x) <= 1.0005) {
		tmp = (0.125 * pow(x, 2.0)) + ((0.0673828125 * pow(x, 6.0)) + (-0.0859375 * pow(x, 4.0)));
	} else {
		tmp = fma(1.0, (0.5 / (1.0 + sqrt(t_0))), (t_3 * (-0.5 / t_1))) + fma(((-1.0 / hypot(1.0, x)) / t_1), t_2, (t_3 * 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 + Float64(0.5 / hypot(1.0, x)))
	t_1 = hypot(1.0, (t_0 ^ 0.25))
	t_2 = Float64(0.5 / t_1)
	t_3 = Float64(Float64(1.0 / hypot(1.0, x)) / t_1)
	tmp = 0.0
	if (hypot(1.0, x) <= 1.0005)
		tmp = Float64(Float64(0.125 * (x ^ 2.0)) + Float64(Float64(0.0673828125 * (x ^ 6.0)) + Float64(-0.0859375 * (x ^ 4.0))));
	else
		tmp = Float64(fma(1.0, Float64(0.5 / Float64(1.0 + sqrt(t_0))), Float64(t_3 * Float64(-0.5 / t_1))) + fma(Float64(Float64(-1.0 / hypot(1.0, x)) / t_1), t_2, Float64(t_3 * 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[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[1.0 ^ 2 + N[Power[t$95$0, 0.25], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(0.5 / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0005], N[(N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.0673828125 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 * N[(0.5 / N[(1.0 + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$3 * N[(-0.5 / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision] * t$95$2 + N[(t$95$3 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
t_0 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_1 := \mathsf{hypot}\left(1, {t_0}^{0.25}\right)\\
t_2 := \frac{0.5}{t_1}\\
t_3 := \frac{\frac{1}{\mathsf{hypot}\left(1, x\right)}}{t_1}\\
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\
\;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{0.5}{1 + \sqrt{t_0}}, t_3 \cdot \frac{-0.5}{t_1}\right) + \mathsf{fma}\left(\frac{\frac{-1}{\mathsf{hypot}\left(1, x\right)}}{t_1}, t_2, t_3 \cdot t_2\right)\\


\end{array}

Error

Derivation

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

    1. Initial program 29.5

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

      \[\leadsto \color{blue}{1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \]
      Proof
      (-.f64 1 (sqrt.f64 (+.f64 1/2 (/.f64 1/2 (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (Rewrite<= metadata-eval (*.f64 1 1/2)) (/.f64 1/2 (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (*.f64 1 1/2) (/.f64 (Rewrite<= metadata-eval (*.f64 1 1/2)) (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (*.f64 1 1/2) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (hypot.f64 1 x)) 1/2))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 1/2 (+.f64 1 (/.f64 1 (hypot.f64 1 x))))))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in x around 0 0.1

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

    if 1.00049999999999994 < (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)}}} \]
      Proof
      (-.f64 1 (sqrt.f64 (+.f64 1/2 (/.f64 1/2 (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (Rewrite<= metadata-eval (*.f64 1 1/2)) (/.f64 1/2 (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (*.f64 1 1/2) (/.f64 (Rewrite<= metadata-eval (*.f64 1 1/2)) (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (+.f64 (*.f64 1 1/2) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (hypot.f64 1 x)) 1/2))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (sqrt.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 1/2 (+.f64 1 (/.f64 1 (hypot.f64 1 x))))))): 0 points increase in error, 0 points decrease in error
    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(1, \frac{0.5}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}, -\frac{\frac{1}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)}\right) + \mathsf{fma}\left(-\frac{\frac{1}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)}, \frac{0.5}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)}, \frac{\frac{1}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)}\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.0005:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{0.5}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}, \frac{\frac{1}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)} \cdot \frac{-0.5}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)}\right) + \mathsf{fma}\left(\frac{\frac{-1}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)}, \frac{0.5}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)}, \frac{\frac{1}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{0.25}\right)}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.0
Cost46532
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{\mathsf{fma}\left({\left(\frac{0.25}{1 + x \cdot x}\right)}^{0.3333333333333333}, \sqrt[3]{\frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}, 0.5\right)}}\\ \end{array} \]
Alternative 2
Error0.0
Cost39684
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{e^{\log \left(0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}}\\ \end{array} \]
Alternative 3
Error0.3
Cost33092
\[\begin{array}{l} t_0 := 0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\\ t_1 := 1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \mathbf{if}\;x \leq -0.03901317679118908:\\ \;\;\;\;\frac{e^{\log t_0}}{t_1}\\ \mathbf{elif}\;x \leq 6.820343214013506 \cdot 10^{-11}:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{t_1}{t_0}}\\ \end{array} \]
Alternative 4
Error0.0
Cost26884
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\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} \]
Alternative 5
Error0.0
Cost26756
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\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} \]
Alternative 6
Error1.0
Cost20360
\[\begin{array}{l} \mathbf{if}\;x \leq -47137.75285091917:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 6.820343214013506 \cdot 10^{-11}:\\ \;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \end{array} \]
Alternative 7
Error1.3
Cost13576
\[\begin{array}{l} t_0 := \frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{if}\;x \leq -47137.75285091917:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.820343214013506 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, -0.0859375, 0.125 \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error1.0
Cost13576
\[\begin{array}{l} \mathbf{if}\;x \leq -47137.75285091917:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 6.820343214013506 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, -0.0859375, 0.125 \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \end{array} \]
Alternative 9
Error1.3
Cost7240
\[\begin{array}{l} t_0 := \frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{if}\;x \leq -47137.75285091917:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.820343214013506 \cdot 10^{-11}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot -0.0859375, 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error1.4
Cost6984
\[\begin{array}{l} t_0 := \frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{if}\;x \leq -47137.75285091917:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.820343214013506 \cdot 10^{-11}:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error1.9
Cost6856
\[\begin{array}{l} t_0 := 1 - \sqrt{0.5}\\ \mathbf{if}\;x \leq -47137.75285091917:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.820343214013506 \cdot 10^{-11}:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error26.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -47137.75285091917:\\ \;\;\;\;0.18181818181818182\\ \mathbf{elif}\;x \leq 6.820343214013506 \cdot 10^{-11}:\\ \;\;\;\;x \cdot \left(x \cdot 0.125\right)\\ \mathbf{else}:\\ \;\;\;\;0.18181818181818182\\ \end{array} \]
Alternative 13
Error26.3
Cost576
\[\frac{1}{5.5 + \frac{8}{x \cdot x}} \]
Alternative 14
Error56.4
Cost64
\[0.18181818181818182 \]

Error

Reproduce

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