Average Error: 30.3 → 0.6
Time: 4.8s
Precision: binary64
Cost: 19780
\[\sqrt{2 \cdot \left(x \cdot x\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -9.254274339146283 \cdot 10^{-305}:\\ \;\;\;\;{2}^{0.25} \cdot \left(\sqrt{\sqrt{2}} \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot x} \cdot \sqrt{x}\\ \end{array} \]
(FPCore (x) :precision binary64 (sqrt (* 2.0 (* x x))))
(FPCore (x)
 :precision binary64
 (if (<= x -9.254274339146283e-305)
   (* (pow 2.0 0.25) (* (sqrt (sqrt 2.0)) (- x)))
   (* (sqrt (* 2.0 x)) (sqrt x))))
double code(double x) {
	return sqrt((2.0 * (x * x)));
}
double code(double x) {
	double tmp;
	if (x <= -9.254274339146283e-305) {
		tmp = pow(2.0, 0.25) * (sqrt(sqrt(2.0)) * -x);
	} else {
		tmp = sqrt((2.0 * x)) * sqrt(x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((2.0d0 * (x * x)))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-9.254274339146283d-305)) then
        tmp = (2.0d0 ** 0.25d0) * (sqrt(sqrt(2.0d0)) * -x)
    else
        tmp = sqrt((2.0d0 * x)) * sqrt(x)
    end if
    code = tmp
end function
public static double code(double x) {
	return Math.sqrt((2.0 * (x * x)));
}
public static double code(double x) {
	double tmp;
	if (x <= -9.254274339146283e-305) {
		tmp = Math.pow(2.0, 0.25) * (Math.sqrt(Math.sqrt(2.0)) * -x);
	} else {
		tmp = Math.sqrt((2.0 * x)) * Math.sqrt(x);
	}
	return tmp;
}
def code(x):
	return math.sqrt((2.0 * (x * x)))
def code(x):
	tmp = 0
	if x <= -9.254274339146283e-305:
		tmp = math.pow(2.0, 0.25) * (math.sqrt(math.sqrt(2.0)) * -x)
	else:
		tmp = math.sqrt((2.0 * x)) * math.sqrt(x)
	return tmp
function code(x)
	return sqrt(Float64(2.0 * Float64(x * x)))
end
function code(x)
	tmp = 0.0
	if (x <= -9.254274339146283e-305)
		tmp = Float64((2.0 ^ 0.25) * Float64(sqrt(sqrt(2.0)) * Float64(-x)));
	else
		tmp = Float64(sqrt(Float64(2.0 * x)) * sqrt(x));
	end
	return tmp
end
function tmp = code(x)
	tmp = sqrt((2.0 * (x * x)));
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -9.254274339146283e-305)
		tmp = (2.0 ^ 0.25) * (sqrt(sqrt(2.0)) * -x);
	else
		tmp = sqrt((2.0 * x)) * sqrt(x);
	end
	tmp_2 = tmp;
end
code[x_] := N[Sqrt[N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -9.254274339146283e-305], N[(N[Power[2.0, 0.25], $MachinePrecision] * N[(N[Sqrt[N[Sqrt[2.0], $MachinePrecision]], $MachinePrecision] * (-x)), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\sqrt{2 \cdot \left(x \cdot x\right)}
\begin{array}{l}
\mathbf{if}\;x \leq -9.254274339146283 \cdot 10^{-305}:\\
\;\;\;\;{2}^{0.25} \cdot \left(\sqrt{\sqrt{2}} \cdot \left(-x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot x} \cdot \sqrt{x}\\


\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 x < -9.2542743391462826e-305

    1. Initial program 30.3

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{x \cdot \sqrt{2}}\right)}^{3}} \]
    3. Applied egg-rr62.6

      \[\leadsto \color{blue}{{2}^{0.25} \cdot \left({2}^{0.25} \cdot x\right)} \]
    4. Applied egg-rr30.4

      \[\leadsto {2}^{0.25} \cdot \color{blue}{\sqrt{\left(x \cdot x\right) \cdot \sqrt{2}}} \]
    5. Taylor expanded in x around -inf 0.4

      \[\leadsto {2}^{0.25} \cdot \color{blue}{\left(-1 \cdot \left(\sqrt{\sqrt{2}} \cdot x\right)\right)} \]
    6. Simplified0.4

      \[\leadsto {2}^{0.25} \cdot \color{blue}{\left(\sqrt{\sqrt{2}} \cdot \left(-x\right)\right)} \]
      Proof
      (*.f64 (sqrt.f64 (sqrt.f64 2)) (neg.f64 x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (sqrt.f64 (sqrt.f64 2)) x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 (sqrt.f64 (sqrt.f64 2)) x))): 0 points increase in error, 0 points decrease in error

    if -9.2542743391462826e-305 < x

    1. Initial program 30.3

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

      \[\leadsto \color{blue}{\sqrt{2 \cdot x} \cdot \sqrt{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.254274339146283 \cdot 10^{-305}:\\ \;\;\;\;{2}^{0.25} \cdot \left(\sqrt{\sqrt{2}} \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot x} \cdot \sqrt{x}\\ \end{array} \]

Alternatives

Alternative 1
Error1.4
Cost25984
\[{\left(\sqrt{\sqrt[3]{2 \cdot x} \cdot \sqrt[3]{x}}\right)}^{3} \]
Alternative 2
Error1.3
Cost25856
\[{\left(\left|\sqrt[3]{x \cdot \sqrt{2}}\right|\right)}^{3} \]
Alternative 3
Error0.6
Cost13252
\[\begin{array}{l} \mathbf{if}\;x \leq -9.254274339146283 \cdot 10^{-305}:\\ \;\;\;\;\sqrt{2} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot x} \cdot \sqrt{x}\\ \end{array} \]
Alternative 4
Error0.6
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq -9.254274339146283 \cdot 10^{-305}:\\ \;\;\;\;\sqrt{2} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{2}\\ \end{array} \]
Alternative 5
Error31.5
Cost6592
\[x \cdot \sqrt{2} \]

Error

Reproduce

herbie shell --seed 2022311 
(FPCore (x)
  :name "sqrt C"
  :precision binary64
  (sqrt (* 2.0 (* x x))))