?

Average Error: 31.5 → 8.0
Time: 4.5s
Precision: binary64
Cost: 7376

?

\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\sqrt{x \cdot x + y \cdot y} \]
\[\begin{array}{l} \mathbf{if}\;y \leq 2.8 \cdot 10^{-179}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-165}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-116}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{+144}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
(FPCore (x y) :precision binary64 (sqrt (+ (* x x) (* y y))))
(FPCore (x y)
 :precision binary64
 (if (<= y 2.8e-179)
   (- x)
   (if (<= y 3.6e-165)
     y
     (if (<= y 1.8e-116)
       (- x)
       (if (<= y 5.6e+144) (sqrt (+ (* x x) (* y y))) y)))))
double code(double x, double y) {
	return sqrt(((x * x) + (y * y)));
}
double code(double x, double y) {
	double tmp;
	if (y <= 2.8e-179) {
		tmp = -x;
	} else if (y <= 3.6e-165) {
		tmp = y;
	} else if (y <= 1.8e-116) {
		tmp = -x;
	} else if (y <= 5.6e+144) {
		tmp = sqrt(((x * x) + (y * y)));
	} else {
		tmp = y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = sqrt(((x * x) + (y * y)))
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 2.8d-179) then
        tmp = -x
    else if (y <= 3.6d-165) then
        tmp = y
    else if (y <= 1.8d-116) then
        tmp = -x
    else if (y <= 5.6d+144) then
        tmp = sqrt(((x * x) + (y * y)))
    else
        tmp = y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	return Math.sqrt(((x * x) + (y * y)));
}
public static double code(double x, double y) {
	double tmp;
	if (y <= 2.8e-179) {
		tmp = -x;
	} else if (y <= 3.6e-165) {
		tmp = y;
	} else if (y <= 1.8e-116) {
		tmp = -x;
	} else if (y <= 5.6e+144) {
		tmp = Math.sqrt(((x * x) + (y * y)));
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y):
	return math.sqrt(((x * x) + (y * y)))
def code(x, y):
	tmp = 0
	if y <= 2.8e-179:
		tmp = -x
	elif y <= 3.6e-165:
		tmp = y
	elif y <= 1.8e-116:
		tmp = -x
	elif y <= 5.6e+144:
		tmp = math.sqrt(((x * x) + (y * y)))
	else:
		tmp = y
	return tmp
function code(x, y)
	return sqrt(Float64(Float64(x * x) + Float64(y * y)))
end
function code(x, y)
	tmp = 0.0
	if (y <= 2.8e-179)
		tmp = Float64(-x);
	elseif (y <= 3.6e-165)
		tmp = y;
	elseif (y <= 1.8e-116)
		tmp = Float64(-x);
	elseif (y <= 5.6e+144)
		tmp = sqrt(Float64(Float64(x * x) + Float64(y * y)));
	else
		tmp = y;
	end
	return tmp
end
function tmp = code(x, y)
	tmp = sqrt(((x * x) + (y * y)));
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 2.8e-179)
		tmp = -x;
	elseif (y <= 3.6e-165)
		tmp = y;
	elseif (y <= 1.8e-116)
		tmp = -x;
	elseif (y <= 5.6e+144)
		tmp = sqrt(((x * x) + (y * y)));
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_] := If[LessEqual[y, 2.8e-179], (-x), If[LessEqual[y, 3.6e-165], y, If[LessEqual[y, 1.8e-116], (-x), If[LessEqual[y, 5.6e+144], N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], y]]]]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{-179}:\\
\;\;\;\;-x\\

\mathbf{elif}\;y \leq 3.6 \cdot 10^{-165}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 1.8 \cdot 10^{-116}:\\
\;\;\;\;-x\\

\mathbf{elif}\;y \leq 5.6 \cdot 10^{+144}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{else}:\\
\;\;\;\;y\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.5
Target17.5
Herbie8.0
\[\begin{array}{l} \mathbf{if}\;x < -1.1236950826599826 \cdot 10^{+145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x < 1.116557621183362 \cdot 10^{+93}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if y < 2.8000000000000001e-179 or 3.59999999999999984e-165 < y < 1.79999999999999988e-116

    1. Initial program 30.3

      \[\sqrt{x \cdot x + y \cdot y} \]
    2. Taylor expanded in x around -inf 7.2

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Simplified7.2

      \[\leadsto \color{blue}{-x} \]
      Proof

      [Start]7.2

      \[ -1 \cdot x \]

      rational.json-simplify-2 [=>]7.2

      \[ \color{blue}{x \cdot -1} \]

      rational.json-simplify-8 [<=]7.2

      \[ \color{blue}{-x} \]

    if 2.8000000000000001e-179 < y < 3.59999999999999984e-165 or 5.60000000000000013e144 < y

    1. Initial program 59.9

      \[\sqrt{x \cdot x + y \cdot y} \]
    2. Taylor expanded in x around 0 6.8

      \[\leadsto \color{blue}{y} \]

    if 1.79999999999999988e-116 < y < 5.60000000000000013e144

    1. Initial program 10.1

      \[\sqrt{x \cdot x + y \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2.8 \cdot 10^{-179}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-165}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-116}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{+144}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternatives

Alternative 1
Error11.1
Cost524
\[\begin{array}{l} \mathbf{if}\;y \leq 2 \cdot 10^{-179}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-166}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-113}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 2
Error31.3
Cost64
\[y \]

Error

Reproduce?

herbie shell --seed 2023077 
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"
  :precision binary64

  :herbie-target
  (if (< x -1.1236950826599826e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (* x x) (* y y))) x))

  (sqrt (+ (* x x) (* y y))))