?

Average Error: 15.5 → 0.1
Time: 12.3s
Precision: binary64
Cost: 27332

?

\[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)}\\ \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + \left(x \cdot x\right) \cdot 0.125\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{-0.25}{1 + x \cdot x}}{t_0 + {t_0}^{1.5}}\\ \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)))))
   (if (<= (hypot 1.0 x) 1.0005)
     (+ (* (pow x 4.0) -0.0859375) (* (* x x) 0.125))
     (/ (+ 0.25 (/ -0.25 (+ 1.0 (* x x)))) (+ t_0 (pow t_0 1.5))))))
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 tmp;
	if (hypot(1.0, x) <= 1.0005) {
		tmp = (pow(x, 4.0) * -0.0859375) + ((x * x) * 0.125);
	} else {
		tmp = (0.25 + (-0.25 / (1.0 + (x * x)))) / (t_0 + pow(t_0, 1.5));
	}
	return tmp;
}
public static double code(double x) {
	return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
public static double code(double x) {
	double t_0 = 0.5 + (0.5 / Math.hypot(1.0, x));
	double tmp;
	if (Math.hypot(1.0, x) <= 1.0005) {
		tmp = (Math.pow(x, 4.0) * -0.0859375) + ((x * x) * 0.125);
	} else {
		tmp = (0.25 + (-0.25 / (1.0 + (x * x)))) / (t_0 + Math.pow(t_0, 1.5));
	}
	return tmp;
}
def code(x):
	return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
def code(x):
	t_0 = 0.5 + (0.5 / math.hypot(1.0, x))
	tmp = 0
	if math.hypot(1.0, x) <= 1.0005:
		tmp = (math.pow(x, 4.0) * -0.0859375) + ((x * x) * 0.125)
	else:
		tmp = (0.25 + (-0.25 / (1.0 + (x * x)))) / (t_0 + math.pow(t_0, 1.5))
	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)))
	tmp = 0.0
	if (hypot(1.0, x) <= 1.0005)
		tmp = Float64(Float64((x ^ 4.0) * -0.0859375) + Float64(Float64(x * x) * 0.125));
	else
		tmp = Float64(Float64(0.25 + Float64(-0.25 / Float64(1.0 + Float64(x * x)))) / Float64(t_0 + (t_0 ^ 1.5)));
	end
	return tmp
end
function tmp = code(x)
	tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
end
function tmp_2 = code(x)
	t_0 = 0.5 + (0.5 / hypot(1.0, x));
	tmp = 0.0;
	if (hypot(1.0, x) <= 1.0005)
		tmp = ((x ^ 4.0) * -0.0859375) + ((x * x) * 0.125);
	else
		tmp = (0.25 + (-0.25 / (1.0 + (x * x)))) / (t_0 + (t_0 ^ 1.5));
	end
	tmp_2 = 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]}, If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0005], N[(N[(N[Power[x, 4.0], $MachinePrecision] * -0.0859375), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision], N[(N[(0.25 + N[(-0.25 / N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[Power[t$95$0, 1.5], $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)}\\
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\
\;\;\;\;{x}^{4} \cdot -0.0859375 + \left(x \cdot x\right) \cdot 0.125\\

\mathbf{else}:\\
\;\;\;\;\frac{0.25 + \frac{-0.25}{1 + x \cdot x}}{t_0 + {t_0}^{1.5}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

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

    1. Initial program 29.8

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

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

      [Start]29.8

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

      distribute-lft-in [=>]29.8

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

      metadata-eval [=>]29.8

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

      associate-*r/ [=>]29.8

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

      metadata-eval [=>]29.8

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{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} + -0.0859375 \cdot {x}^{4}} \]
    5. Simplified0.1

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

      [Start]0.1

      \[ 0.125 \cdot {x}^{2} + -0.0859375 \cdot {x}^{4} \]

      *-commutative [=>]0.1

      \[ \color{blue}{{x}^{2} \cdot 0.125} + -0.0859375 \cdot {x}^{4} \]

      fma-def [=>]0.1

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

      unpow2 [=>]0.1

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

      *-commutative [=>]0.1

      \[ \mathsf{fma}\left(x \cdot x, 0.125, \color{blue}{{x}^{4} \cdot -0.0859375}\right) \]
    6. Applied egg-rr0.1

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

    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

      [Start]1.0

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

      distribute-lft-in [=>]1.0

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

      metadata-eval [=>]1.0

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

      associate-*r/ [=>]1.0

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

      metadata-eval [=>]1.0

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

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

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

      [Start]0.0

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

      /-rgt-identity [<=]0.0

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

      /-rgt-identity [=>]0.0

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

      +-commutative [=>]0.0

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

      *-commutative [=>]0.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0005:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + \left(x \cdot x\right) \cdot 0.125\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25 + \frac{-0.25}{1 + x \cdot x}}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) + {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{1.5}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost20424
\[\begin{array}{l} t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\ \mathbf{if}\;x \leq -1.12:\\ \;\;\;\;\frac{1}{1 + \sqrt{0.5 + \frac{-0.5}{x}}} \cdot \left(0.5 + \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.0019:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + \left(x \cdot x\right) \cdot 0.125\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 - t_0}{1 + \sqrt{0.5 + t_0}}\\ \end{array} \]
Alternative 2
Error0.4
Cost13576
\[\begin{array}{l} \mathbf{if}\;x \leq -1.12:\\ \;\;\;\;\frac{1}{1 + \sqrt{0.5 + \frac{-0.5}{x}}} \cdot \left(0.5 + \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.0027:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + \left(x \cdot x\right) \cdot 0.125\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\ \end{array} \]
Alternative 3
Error0.6
Cost7496
\[\begin{array}{l} t_0 := 0.5 + \frac{-0.5}{x}\\ \mathbf{if}\;x \leq -1.12:\\ \;\;\;\;1 - \sqrt{t_0}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + \left(x \cdot x\right) \cdot 0.125\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{1 + \sqrt{0.5 + \frac{0.5}{x}}}\\ \end{array} \]
Alternative 4
Error0.3
Cost7496
\[\begin{array}{l} t_0 := 0.5 + \frac{-0.5}{x}\\ t_1 := 0.5 + \frac{0.5}{x}\\ \mathbf{if}\;x \leq -1.12:\\ \;\;\;\;\frac{1}{1 + \sqrt{t_0}} \cdot t_1\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + \left(x \cdot x\right) \cdot 0.125\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{1 + \sqrt{t_1}}\\ \end{array} \]
Alternative 5
Error0.8
Cost7304
\[\begin{array}{l} \mathbf{if}\;x \leq -1.12:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{-0.5}{x}}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;{x}^{4} \cdot -0.0859375 + \left(x \cdot x\right) \cdot 0.125\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x}}\\ \end{array} \]
Alternative 6
Error1.1
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5:\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{elif}\;x \leq 1.82:\\ \;\;\;\;\frac{1}{5.5 + \left(\frac{8}{x \cdot x} + \left(x \cdot x\right) \cdot -0.53125\right)}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x}}\\ \end{array} \]
Alternative 7
Error1.1
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{-0.5}{x}}\\ \mathbf{elif}\;x \leq 1.82:\\ \;\;\;\;\frac{1}{5.5 + \left(\frac{8}{x \cdot x} + \left(x \cdot x\right) \cdot -0.53125\right)}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{x}}\\ \end{array} \]
Alternative 8
Error1.0
Cost6985
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \lor \neg \left(x \leq 2.5\right):\\ \;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{5.5 + \left(\frac{8}{x \cdot x} + \left(x \cdot x\right) \cdot -0.53125\right)}\\ \end{array} \]
Alternative 9
Error1.5
Cost6857
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \lor \neg \left(x \leq 2.5\right):\\ \;\;\;\;1 - \sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{5.5 + \left(\frac{8}{x \cdot x} + \left(x \cdot x\right) \cdot -0.53125\right)}\\ \end{array} \]
Alternative 10
Error25.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.2:\\ \;\;\;\;0.18181818181818182\\ \mathbf{elif}\;x \leq 1.2:\\ \;\;\;\;\left(x \cdot x\right) \cdot 0.125\\ \mathbf{else}:\\ \;\;\;\;0.18181818181818182\\ \end{array} \]
Alternative 11
Error25.9
Cost576
\[\frac{1}{5.5 + \frac{8}{x \cdot x}} \]
Alternative 12
Error40.6
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-77}:\\ \;\;\;\;0.18181818181818182\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-77}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.18181818181818182\\ \end{array} \]
Alternative 13
Error56.5
Cost64
\[0.18181818181818182 \]

Error

Reproduce?

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