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

\mathbf{else}:\\
\;\;\;\;\sqrt{x \cdot 2} \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 < -2.2637850116368028e-307

    1. Initial program 30.5

      \[\sqrt{2 \cdot {x}^{2}} \]
    2. Simplified30.5

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(x \cdot x\right)}} \]
      Proof
      (sqrt.f64 (*.f64 2 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (sqrt.f64 (*.f64 2 (Rewrite<= unpow2_binary64 (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr30.9

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

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

      \[\leadsto \color{blue}{\sqrt{2} \cdot \left(-x\right)} \]
      Proof
      (*.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 2) x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 (sqrt.f64 2) x))): 0 points increase in error, 0 points decrease in error

    if -2.2637850116368028e-307 < x

    1. Initial program 30.8

      \[\sqrt{2 \cdot {x}^{2}} \]
    2. Simplified30.8

      \[\leadsto \color{blue}{\sqrt{2 \cdot \left(x \cdot x\right)}} \]
      Proof
      (sqrt.f64 (*.f64 2 (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (sqrt.f64 (*.f64 2 (Rewrite<= unpow2_binary64 (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.5

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

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

Alternatives

Alternative 1
Error1.2
Cost39040
\[\left(\sqrt[3]{x} \cdot \sqrt[3]{x \cdot 2}\right) \cdot \sqrt{{\left(\sqrt[3]{x \cdot \sqrt{2}}\right)}^{2}} \]
Alternative 2
Error1.2
Cost38912
\[{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x \cdot \sqrt{2}}\right) \cdot \sqrt[3]{\sqrt{2}}\right)}^{1.5} \]
Alternative 3
Error1.3
Cost32704
\[\begin{array}{l} t_0 := \sqrt[3]{x} \cdot \sqrt[3]{x \cdot 2}\\ t_0 \cdot \sqrt{t_0} \end{array} \]
Alternative 4
Error1.3
Cost19584
\[{\left(\sqrt[3]{x} \cdot \sqrt[3]{x \cdot 2}\right)}^{1.5} \]
Alternative 5
Error0.5
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq -2.263785011636803 \cdot 10^{-307}:\\ \;\;\;\;x \cdot \left(-\sqrt{2}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{2}\\ \end{array} \]
Alternative 6
Error30.9
Cost6592
\[x \cdot \sqrt{2} \]

Error

Reproduce

herbie shell --seed 2022294 
(FPCore (x)
  :name "sqrt D"
  :precision binary64
  (sqrt (* 2.0 (pow x 2.0))))