?

Average Error: 15.6 → 0.6
Time: 4.3s
Precision: binary64
Cost: 20036

?

\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \]
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\ \;\;\;\;0.125 \cdot {x}^{2} + -0.0859375 \cdot {x}^{4}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\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 (<= (hypot 1.0 x) 1.2)
   (+ (* 0.125 (pow x 2.0)) (* -0.0859375 (pow x 4.0)))
   (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (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 (hypot(1.0, x) <= 1.2) {
		tmp = (0.125 * pow(x, 2.0)) + (-0.0859375 * pow(x, 4.0));
	} else {
		tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
	}
	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 tmp;
	if (Math.hypot(1.0, x) <= 1.2) {
		tmp = (0.125 * Math.pow(x, 2.0)) + (-0.0859375 * Math.pow(x, 4.0));
	} else {
		tmp = 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
	}
	return tmp;
}
def code(x):
	return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
def code(x):
	tmp = 0
	if math.hypot(1.0, x) <= 1.2:
		tmp = (0.125 * math.pow(x, 2.0)) + (-0.0859375 * math.pow(x, 4.0))
	else:
		tmp = 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.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 (hypot(1.0, x) <= 1.2)
		tmp = Float64(Float64(0.125 * (x ^ 2.0)) + Float64(-0.0859375 * (x ^ 4.0)));
	else
		tmp = Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x))))));
	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)
	tmp = 0.0;
	if (hypot(1.0, x) <= 1.2)
		tmp = (0.125 * (x ^ 2.0)) + (-0.0859375 * (x ^ 4.0));
	else
		tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
	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_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.2], N[(N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.2:\\
\;\;\;\;0.125 \cdot {x}^{2} + -0.0859375 \cdot {x}^{4}\\

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


\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.19999999999999996

    1. Initial program 30.6

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

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

      [Start]30.6

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]30.6

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

      metadata-eval [<=]30.6

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

      metadata-eval [<=]30.6

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

      rational_best_oopsla_all_46_json_45_simplify-11 [=>]30.6

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

      rational_best_oopsla_all_46_json_45_simplify-87 [<=]30.6

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

      rational_best_oopsla_all_46_json_45_simplify-13 [=>]30.6

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

      metadata-eval [=>]30.6

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

      metadata-eval [=>]30.6

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]30.6

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

      metadata-eval [=>]30.6

      \[ 1 - \sqrt{0.5 - \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \color{blue}{-0.5}} \]
    3. Taylor expanded in x around 0 0.3

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

    if 1.19999999999999996 < (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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

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

Alternatives

Alternative 1
Error0.8
Cost13640
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1:\\ \;\;\;\;1 - \sqrt{0.5 - \frac{-1}{x} \cdot -0.5}\\ \mathbf{elif}\;x \leq 1.1:\\ \;\;\;\;0.125 \cdot {x}^{2} + -0.0859375 \cdot {x}^{4}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 - \frac{1}{x} \cdot -0.5}\\ \end{array} \]
Alternative 2
Error1.0
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;1 - \sqrt{0.5 - \frac{-1}{x} \cdot -0.5}\\ \mathbf{elif}\;x \leq 1.22:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5 - \frac{1}{x} \cdot -0.5}\\ \end{array} \]
Alternative 3
Error1.2
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;1 - \sqrt{0.5 - \frac{-1}{x} \cdot -0.5}\\ \mathbf{elif}\;x \leq 1.52:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;1 - \sqrt{0.5}\\ \end{array} \]
Alternative 4
Error1.4
Cost6920
\[\begin{array}{l} t_0 := 1 - \sqrt{0.5}\\ \mathbf{if}\;x \leq -1.55:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.52:\\ \;\;\;\;0.125 \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error31.3
Cost6592
\[1 - \sqrt{0.5} \]

Error

Reproduce?

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