?

Average Error: 30.4 → 0.4
Time: 7.4s
Precision: binary64
Cost: 6788

?

\[\sqrt{2 \cdot {x}^{2}} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-311}:\\ \;\;\;\;\sqrt{2} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot x\\ \end{array} \]
(FPCore (x) :precision binary64 (sqrt (* 2.0 (pow x 2.0))))
(FPCore (x)
 :precision binary64
 (if (<= x -2e-311) (* (sqrt 2.0) (- x)) (* (sqrt 2.0) x)))
double code(double x) {
	return sqrt((2.0 * pow(x, 2.0)));
}
double code(double x) {
	double tmp;
	if (x <= -2e-311) {
		tmp = sqrt(2.0) * -x;
	} else {
		tmp = sqrt(2.0) * 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 <= (-2d-311)) then
        tmp = sqrt(2.0d0) * -x
    else
        tmp = sqrt(2.0d0) * 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 <= -2e-311) {
		tmp = Math.sqrt(2.0) * -x;
	} else {
		tmp = Math.sqrt(2.0) * x;
	}
	return tmp;
}
def code(x):
	return math.sqrt((2.0 * math.pow(x, 2.0)))
def code(x):
	tmp = 0
	if x <= -2e-311:
		tmp = math.sqrt(2.0) * -x
	else:
		tmp = math.sqrt(2.0) * x
	return tmp
function code(x)
	return sqrt(Float64(2.0 * (x ^ 2.0)))
end
function code(x)
	tmp = 0.0
	if (x <= -2e-311)
		tmp = Float64(sqrt(2.0) * Float64(-x));
	else
		tmp = Float64(sqrt(2.0) * 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 <= -2e-311)
		tmp = sqrt(2.0) * -x;
	else
		tmp = sqrt(2.0) * 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, -2e-311], N[(N[Sqrt[2.0], $MachinePrecision] * (-x)), $MachinePrecision], N[(N[Sqrt[2.0], $MachinePrecision] * x), $MachinePrecision]]
\sqrt{2 \cdot {x}^{2}}
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-311}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{2} \cdot 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 < -1.9999999999999e-311

    1. Initial program 30.1

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

      [Start]0.4

      \[ -1 \cdot \left(\sqrt{2} \cdot x\right) \]

      rational.json-simplify-43 [=>]0.4

      \[ \color{blue}{\sqrt{2} \cdot \left(x \cdot -1\right)} \]

      rational.json-simplify-9 [=>]0.4

      \[ \sqrt{2} \cdot \color{blue}{\left(-x\right)} \]

    if -1.9999999999999e-311 < x

    1. Initial program 30.7

      \[\sqrt{2 \cdot {x}^{2}} \]
    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 -2 \cdot 10^{-311}:\\ \;\;\;\;\sqrt{2} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot x\\ \end{array} \]

Alternatives

Alternative 1
Error31.1
Cost6592
\[\sqrt{2} \cdot x \]

Error

Reproduce?

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