Average Error: 30.2 → 0.4
Time: 9.6s
Precision: binary64
Cost: 19716
\[\sqrt{{x}^{2} + {x}^{2}} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-\frac{x \cdot \sqrt[3]{\sqrt{2}}}{\sqrt[3]{0.5}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot x\\ \end{array} \]
(FPCore (x) :precision binary64 (sqrt (+ (pow x 2.0) (pow x 2.0))))
(FPCore (x)
 :precision binary64
 (if (<= x -5e-310)
   (- (/ (* x (cbrt (sqrt 2.0))) (cbrt 0.5)))
   (* (sqrt 2.0) x)))
double code(double x) {
	return sqrt((pow(x, 2.0) + pow(x, 2.0)));
}
double code(double x) {
	double tmp;
	if (x <= -5e-310) {
		tmp = -((x * cbrt(sqrt(2.0))) / cbrt(0.5));
	} else {
		tmp = sqrt(2.0) * x;
	}
	return tmp;
}
public static double code(double x) {
	return Math.sqrt((Math.pow(x, 2.0) + Math.pow(x, 2.0)));
}
public static double code(double x) {
	double tmp;
	if (x <= -5e-310) {
		tmp = -((x * Math.cbrt(Math.sqrt(2.0))) / Math.cbrt(0.5));
	} else {
		tmp = Math.sqrt(2.0) * x;
	}
	return tmp;
}
function code(x)
	return sqrt(Float64((x ^ 2.0) + (x ^ 2.0)))
end
function code(x)
	tmp = 0.0
	if (x <= -5e-310)
		tmp = Float64(-Float64(Float64(x * cbrt(sqrt(2.0))) / cbrt(0.5)));
	else
		tmp = Float64(sqrt(2.0) * x);
	end
	return tmp
end
code[x_] := N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -5e-310], (-N[(N[(x * N[Power[N[Sqrt[2.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] / N[Power[0.5, 1/3], $MachinePrecision]), $MachinePrecision]), N[(N[Sqrt[2.0], $MachinePrecision] * x), $MachinePrecision]]
\sqrt{{x}^{2} + {x}^{2}}
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-\frac{x \cdot \sqrt[3]{\sqrt{2}}}{\sqrt[3]{0.5}}\\

\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 < -4.999999999999985e-310

    1. Initial program 30.3

      \[\sqrt{{x}^{2} + {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 x} \]
      Proof
    4. Applied egg-rr0.3

      \[\leadsto -\color{blue}{\frac{x \cdot \sqrt[3]{\sqrt{2}}}{\sqrt[3]{0.5}}} \]

    if -4.999999999999985e-310 < x

    1. Initial program 30.1

      \[\sqrt{{x}^{2} + {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.

Alternatives

Alternative 1
Error0.4
Cost6788
\[\begin{array}{l} t_0 := \sqrt{2} \cdot x\\ \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-t_0\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.4
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\ \;\;\;\;-\frac{x}{\sqrt{0.5}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot x\\ \end{array} \]
Alternative 3
Error31.1
Cost6592
\[\sqrt{2} \cdot x \]
Alternative 4
Error61.6
Cost64
\[0 \]

Error

Reproduce

herbie shell --seed 2023010 
(FPCore (x)
  :name "sqrt E (should all be same)"
  :precision binary64
  (sqrt (+ (pow x 2.0) (pow x 2.0))))