Average Error: 30.2 → 0.1
Time: 14.4s
Precision: binary64
Cost: 14024
\[\sqrt{\left(2 \cdot x\right) \cdot x} \]
\[\begin{array}{l} t_0 := \left(x + x\right) \cdot x\\ t_1 := t_0 \ne 0\\ \mathbf{if}\;t_1:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_1:\\ \;\;\;\;\mathsf{hypot}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;{\left({t_0}^{-0.5}\right)}^{-1}\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left|x\right|\\ \end{array} \]
(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* (+ x x) x)) (t_1 (!= t_0 0.0)))
   (if t_1
     (if t_1 (hypot x x) (pow (pow t_0 -0.5) -1.0))
     (* (sqrt 2.0) (fabs x)))))
double code(double x) {
	return sqrt(((2.0 * x) * x));
}
double code(double x) {
	double t_0 = (x + x) * x;
	int t_1 = t_0 != 0.0;
	double tmp_1;
	if (t_1) {
		double tmp_2;
		if (t_1) {
			tmp_2 = hypot(x, x);
		} else {
			tmp_2 = pow(pow(t_0, -0.5), -1.0);
		}
		tmp_1 = tmp_2;
	} else {
		tmp_1 = sqrt(2.0) * fabs(x);
	}
	return tmp_1;
}
public static double code(double x) {
	return Math.sqrt(((2.0 * x) * x));
}
public static double code(double x) {
	double t_0 = (x + x) * x;
	boolean t_1 = t_0 != 0.0;
	double tmp_1;
	if (t_1) {
		double tmp_2;
		if (t_1) {
			tmp_2 = Math.hypot(x, x);
		} else {
			tmp_2 = Math.pow(Math.pow(t_0, -0.5), -1.0);
		}
		tmp_1 = tmp_2;
	} else {
		tmp_1 = Math.sqrt(2.0) * Math.abs(x);
	}
	return tmp_1;
}
def code(x):
	return math.sqrt(((2.0 * x) * x))
def code(x):
	t_0 = (x + x) * x
	t_1 = t_0 != 0.0
	tmp_1 = 0
	if t_1:
		tmp_2 = 0
		if t_1:
			tmp_2 = math.hypot(x, x)
		else:
			tmp_2 = math.pow(math.pow(t_0, -0.5), -1.0)
		tmp_1 = tmp_2
	else:
		tmp_1 = math.sqrt(2.0) * math.fabs(x)
	return tmp_1
function code(x)
	return sqrt(Float64(Float64(2.0 * x) * x))
end
function code(x)
	t_0 = Float64(Float64(x + x) * x)
	t_1 = t_0 != 0.0
	tmp_1 = 0.0
	if (t_1)
		tmp_2 = 0.0
		if (t_1)
			tmp_2 = hypot(x, x);
		else
			tmp_2 = (t_0 ^ -0.5) ^ -1.0;
		end
		tmp_1 = tmp_2;
	else
		tmp_1 = Float64(sqrt(2.0) * abs(x));
	end
	return tmp_1
end
function tmp = code(x)
	tmp = sqrt(((2.0 * x) * x));
end
function tmp_4 = code(x)
	t_0 = (x + x) * x;
	t_1 = t_0 ~= 0.0;
	tmp_2 = 0.0;
	if (t_1)
		tmp_3 = 0.0;
		if (t_1)
			tmp_3 = hypot(x, x);
		else
			tmp_3 = (t_0 ^ -0.5) ^ -1.0;
		end
		tmp_2 = tmp_3;
	else
		tmp_2 = sqrt(2.0) * abs(x);
	end
	tmp_4 = tmp_2;
end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[(x + x), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = Unequal[t$95$0, 0.0]}, If[t$95$1, If[t$95$1, N[Sqrt[x ^ 2 + x ^ 2], $MachinePrecision], N[Power[N[Power[t$95$0, -0.5], $MachinePrecision], -1.0], $MachinePrecision]], N[(N[Sqrt[2.0], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]]]]
\sqrt{\left(2 \cdot x\right) \cdot x}
\begin{array}{l}
t_0 := \left(x + x\right) \cdot x\\
t_1 := t_0 \ne 0\\
\mathbf{if}\;t_1:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t_1:\\
\;\;\;\;\mathsf{hypot}\left(x, x\right)\\

\mathbf{else}:\\
\;\;\;\;{\left({t_0}^{-0.5}\right)}^{-1}\\


\end{array}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{2} \cdot \left|x\right|\\


\end{array}

Error

Derivation

  1. Initial program 30.2

    \[\sqrt{\left(2 \cdot x\right) \cdot x} \]
  2. Applied egg-rr16.4

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\left(x + x\right) \cdot x \ne 0:\\ \;\;\;\;\frac{1}{{\left(\left(x + x\right) \cdot x\right)}^{-0.5}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left|x\right|\\ } \end{array}} \]
  3. Applied egg-rr0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x + x\right) \cdot x \ne 0:\\ \;\;\;\;\color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\left(x + x\right) \cdot x \ne 0:\\ \;\;\;\;\mathsf{hypot}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;{\left({\left(\left(x + x\right) \cdot x\right)}^{-0.5}\right)}^{-1}\\ } \end{array}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot \left|x\right|\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost12992
\[\sqrt{2} \cdot \left|x\right| \]
Alternative 2
Error0.4
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{x \cdot -2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot x\\ \end{array} \]
Alternative 3
Error0.4
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\left(-x\right) \cdot \sqrt{2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot x\\ \end{array} \]
Alternative 4
Error31.1
Cost6592
\[\sqrt{2} \cdot x \]

Error

Reproduce

herbie shell --seed 2023010 
(FPCore (x)
  :name "sqrt B (should all be same)"
  :precision binary64
  (sqrt (* (* 2.0 x) x)))