?

Average Error: 31.9 → 7.9
Time: 4.0s
Precision: binary64
Cost: 7112

?

\[ \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 \cdot 10^{-192}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+21}:\\ \;\;\;\;\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 2e-192) (- x) (if (<= y 6e+21) (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 <= 2e-192) {
		tmp = -x;
	} else if (y <= 6e+21) {
		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 <= 2d-192) then
        tmp = -x
    else if (y <= 6d+21) 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 <= 2e-192) {
		tmp = -x;
	} else if (y <= 6e+21) {
		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 <= 2e-192:
		tmp = -x
	elif y <= 6e+21:
		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 <= 2e-192)
		tmp = Float64(-x);
	elseif (y <= 6e+21)
		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 <= 2e-192)
		tmp = -x;
	elseif (y <= 6e+21)
		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, 2e-192], (-x), If[LessEqual[y, 6e+21], 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 \cdot 10^{-192}:\\
\;\;\;\;-x\\

\mathbf{elif}\;y \leq 6 \cdot 10^{+21}:\\
\;\;\;\;\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.9
Target17.7
Herbie7.9
\[\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.0000000000000002e-192

    1. Initial program 31.8

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

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

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

      [Start]3.2

      \[ -1 \cdot x \]

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]3.2

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

      rational_best_oopsla_all_46_json_45_simplify-94 [<=]3.2

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

    if 2.0000000000000002e-192 < y < 6e21

    1. Initial program 15.3

      \[\sqrt{x \cdot x + y \cdot y} \]

    if 6e21 < y

    1. Initial program 42.1

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

      \[\leadsto \color{blue}{y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2 \cdot 10^{-192}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+21}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternatives

Alternative 1
Error10.7
Cost524
\[\begin{array}{l} \mathbf{if}\;x \leq -1.32 \cdot 10^{-20}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -8.6 \cdot 10^{-35}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-108}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 2
Error31.6
Cost64
\[y \]

Error

Reproduce?

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