?

Average Error: 32.0 → 8.7
Time: 2.5s
Precision: binary64
Cost: 7244

?

\[ \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 1.22 \cdot 10^{-229}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-176}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+77}:\\ \;\;\;\;\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 1.22e-229)
   (- x)
   (if (<= y 5e-176) y (if (<= y 5.8e+77) (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 <= 1.22e-229) {
		tmp = -x;
	} else if (y <= 5e-176) {
		tmp = y;
	} else if (y <= 5.8e+77) {
		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 <= 1.22d-229) then
        tmp = -x
    else if (y <= 5d-176) then
        tmp = y
    else if (y <= 5.8d+77) 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 <= 1.22e-229) {
		tmp = -x;
	} else if (y <= 5e-176) {
		tmp = y;
	} else if (y <= 5.8e+77) {
		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 <= 1.22e-229:
		tmp = -x
	elif y <= 5e-176:
		tmp = y
	elif y <= 5.8e+77:
		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 <= 1.22e-229)
		tmp = Float64(-x);
	elseif (y <= 5e-176)
		tmp = y;
	elseif (y <= 5.8e+77)
		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 <= 1.22e-229)
		tmp = -x;
	elseif (y <= 5e-176)
		tmp = y;
	elseif (y <= 5.8e+77)
		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, 1.22e-229], (-x), If[LessEqual[y, 5e-176], y, If[LessEqual[y, 5.8e+77], 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 1.22 \cdot 10^{-229}:\\
\;\;\;\;-x\\

\mathbf{elif}\;y \leq 5 \cdot 10^{-176}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 5.8 \cdot 10^{+77}:\\
\;\;\;\;\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

Original32.0
Target17.8
Herbie8.7
\[\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 < 1.21999999999999991e-229

    1. Initial program 31.7

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

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Simplified1.8

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

      [Start]1.8

      \[ -1 \cdot x \]

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

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

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

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

    if 1.21999999999999991e-229 < y < 5e-176 or 5.8000000000000003e77 < y

    1. Initial program 46.2

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

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

    if 5e-176 < y < 5.8000000000000003e77

    1. Initial program 13.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.22 \cdot 10^{-229}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-176}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+77}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternatives

Alternative 1
Error11.8
Cost524
\[\begin{array}{l} \mathbf{if}\;y \leq 1.22 \cdot 10^{-229}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-192}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-50}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 2
Error31.2
Cost64
\[y \]

Error

Reproduce?

herbie shell --seed 2023064 
(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))))