Average Error: 30.6 → 0.4
Time: 4.0s
Precision: binary64
\[\sqrt{\left(2 \cdot x\right) \cdot x} \]
\[\begin{array}{l} t_0 := x \cdot \sqrt{2}\\ \mathbf{if}\;x \leq -1.04069420257774 \cdot 10^{-310}:\\ \;\;\;\;-t_0\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* x (sqrt 2.0))))
   (if (<= x -1.04069420257774e-310) (- t_0) t_0)))
double code(double x) {
	return sqrt(((2.0 * x) * x));
}
double code(double x) {
	double t_0 = x * sqrt(2.0);
	double tmp;
	if (x <= -1.04069420257774e-310) {
		tmp = -t_0;
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = x * sqrt(2.0d0)
    if (x <= (-1.04069420257774d-310)) then
        tmp = -t_0
    else
        tmp = t_0
    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 t_0 = x * Math.sqrt(2.0);
	double tmp;
	if (x <= -1.04069420257774e-310) {
		tmp = -t_0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	return math.sqrt(((2.0 * x) * x))
def code(x):
	t_0 = x * math.sqrt(2.0)
	tmp = 0
	if x <= -1.04069420257774e-310:
		tmp = -t_0
	else:
		tmp = t_0
	return tmp
function code(x)
	return sqrt(Float64(Float64(2.0 * x) * x))
end
function code(x)
	t_0 = Float64(x * sqrt(2.0))
	tmp = 0.0
	if (x <= -1.04069420257774e-310)
		tmp = Float64(-t_0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x)
	tmp = sqrt(((2.0 * x) * x));
end
function tmp_2 = code(x)
	t_0 = x * sqrt(2.0);
	tmp = 0.0;
	if (x <= -1.04069420257774e-310)
		tmp = -t_0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(x * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.04069420257774e-310], (-t$95$0), t$95$0]]
\sqrt{\left(2 \cdot x\right) \cdot x}
\begin{array}{l}
t_0 := x \cdot \sqrt{2}\\
\mathbf{if}\;x \leq -1.04069420257774 \cdot 10^{-310}:\\
\;\;\;\;-t_0\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus x

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.040694202577743e-310

    1. Initial program 30.6

      \[\sqrt{\left(2 \cdot x\right) \cdot x} \]
    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}{-\sqrt{2} \cdot x} \]

    if -1.040694202577743e-310 < x

    1. Initial program 30.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.04069420257774 \cdot 10^{-310}:\\ \;\;\;\;-x \cdot \sqrt{2}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{2}\\ \end{array} \]

Reproduce

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