?

Average Error: 51.8% → 99.4%
Time: 6.6s
Precision: binary64
Cost: 13252.00

?

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

    1. Initial program 51.8

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

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

      [Start]51.8

      \[ \sqrt{2 \cdot {x}^{2}} \]

      unpow2 [=>]51.8

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

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

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

      [Start]99.3

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

      *-commutative [<=]99.3

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

      mul-1-neg [=>]99.3

      \[ \color{blue}{-x \cdot \sqrt{2}} \]

      *-commutative [=>]99.3

      \[ -\color{blue}{\sqrt{2} \cdot x} \]

      distribute-rgt-neg-in [=>]99.3

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

    if -4.999999999999985e-310 < x

    1. Initial program 51.8

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

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

      [Start]51.8

      \[ \sqrt{2 \cdot {x}^{2}} \]

      unpow2 [=>]51.8

      \[ \sqrt{2 \cdot \color{blue}{\left(x \cdot x\right)}} \]
    3. Applied egg-rr99.4

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

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

Alternatives

Alternative 1
Error99.0%
Cost25856.00
\[{\left(\sqrt{\left|\sqrt{2} \cdot x\right|}\right)}^{2} \]
Alternative 2
Error97.9%
Cost19584.00
\[{\left(\sqrt[3]{2 \cdot x} \cdot \sqrt[3]{x}\right)}^{1.5} \]
Alternative 3
Error99.3%
Cost6788.00
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{2} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot x\\ \end{array} \]
Alternative 4
Error51.4%
Cost6592.00
\[\sqrt{2} \cdot x \]

Error

Reproduce?

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