Average Error: 30.9 → 0.7
Time: 5.2s
Precision: binary64
Cost: 13380
\[\sqrt{2 \cdot \left(x \cdot x\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.355249987510172 \cdot 10^{-301}:\\ \;\;\;\;x \cdot \left(-\sqrt{2}\right)\\ \mathbf{else}:\\ \;\;\;\;{2}^{0.25} \cdot \left(x \cdot {2}^{0.25}\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (sqrt (* 2.0 (* x x))))
(FPCore (x)
 :precision binary64
 (if (<= x -1.355249987510172e-301)
   (* x (- (sqrt 2.0)))
   (* (pow 2.0 0.25) (* x (pow 2.0 0.25)))))
double code(double x) {
	return sqrt((2.0 * (x * x)));
}
double code(double x) {
	double tmp;
	if (x <= -1.355249987510172e-301) {
		tmp = x * -sqrt(2.0);
	} else {
		tmp = pow(2.0, 0.25) * (x * pow(2.0, 0.25));
	}
	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 <= (-1.355249987510172d-301)) then
        tmp = x * -sqrt(2.0d0)
    else
        tmp = (2.0d0 ** 0.25d0) * (x * (2.0d0 ** 0.25d0))
    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 <= -1.355249987510172e-301) {
		tmp = x * -Math.sqrt(2.0);
	} else {
		tmp = Math.pow(2.0, 0.25) * (x * Math.pow(2.0, 0.25));
	}
	return tmp;
}
def code(x):
	return math.sqrt((2.0 * (x * x)))
def code(x):
	tmp = 0
	if x <= -1.355249987510172e-301:
		tmp = x * -math.sqrt(2.0)
	else:
		tmp = math.pow(2.0, 0.25) * (x * math.pow(2.0, 0.25))
	return tmp
function code(x)
	return sqrt(Float64(2.0 * Float64(x * x)))
end
function code(x)
	tmp = 0.0
	if (x <= -1.355249987510172e-301)
		tmp = Float64(x * Float64(-sqrt(2.0)));
	else
		tmp = Float64((2.0 ^ 0.25) * Float64(x * (2.0 ^ 0.25)));
	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 <= -1.355249987510172e-301)
		tmp = x * -sqrt(2.0);
	else
		tmp = (2.0 ^ 0.25) * (x * (2.0 ^ 0.25));
	end
	tmp_2 = tmp;
end
code[x_] := N[Sqrt[N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -1.355249987510172e-301], N[(x * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision], N[(N[Power[2.0, 0.25], $MachinePrecision] * N[(x * N[Power[2.0, 0.25], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\sqrt{2 \cdot \left(x \cdot x\right)}
\begin{array}{l}
\mathbf{if}\;x \leq -1.355249987510172 \cdot 10^{-301}:\\
\;\;\;\;x \cdot \left(-\sqrt{2}\right)\\

\mathbf{else}:\\
\;\;\;\;{2}^{0.25} \cdot \left(x \cdot {2}^{0.25}\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 x < -1.3552499875101719e-301

    1. Initial program 31.0

      \[\sqrt{2 \cdot \left(x \cdot x\right)} \]
    2. Taylor expanded in x around -inf 0.4

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

      \[\leadsto \color{blue}{x \cdot \left(-\sqrt{2}\right)} \]
      Proof
      (*.f64 x (neg.f64 (sqrt.f64 2))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 x (sqrt.f64 2)))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite<= *-commutative_binary64 (*.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 -1.3552499875101719e-301 < x

    1. Initial program 30.9

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

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

      \[\leadsto \color{blue}{{2}^{0.25} \cdot \left({2}^{0.25} \cdot x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

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

Alternatives

Alternative 1
Error1.3
Cost19584
\[{\left(\sqrt[3]{2 \cdot x} \cdot \sqrt[3]{x}\right)}^{1.5} \]
Alternative 2
Error0.7
Cost13252
\[\begin{array}{l} \mathbf{if}\;x \leq -1.355249987510172 \cdot 10^{-301}:\\ \;\;\;\;x \cdot \left(-\sqrt{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot x} \cdot \sqrt{x}\\ \end{array} \]
Alternative 3
Error0.7
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq -1.355249987510172 \cdot 10^{-301}:\\ \;\;\;\;x \cdot \left(-\sqrt{2}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{2}\\ \end{array} \]
Alternative 4
Error31.1
Cost6592
\[x \cdot \sqrt{2} \]

Error

Reproduce

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