?

Average Error: 30.7 → 0.4
Time: 1.9s
Precision: binary64
Cost: 6788

?

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

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


\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 < -9.999999999999969e-311

    1. Initial program 30.8

      \[\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

      [Start]0.4

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.4

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]0.4

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

    if -9.999999999999969e-311 < x

    1. Initial program 30.5

      \[\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.
  4. Final simplification0.4

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

Alternatives

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

Error

Reproduce?

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