?

Average Error: 31.9 → 8.0
Time: 3.2s
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 8.6 \cdot 10^{-133}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+90}:\\ \;\;\;\;\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 8.6e-133) (- x) (if (<= y 6.2e+90) (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 <= 8.6e-133) {
		tmp = -x;
	} else if (y <= 6.2e+90) {
		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 <= 8.6d-133) then
        tmp = -x
    else if (y <= 6.2d+90) 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 <= 8.6e-133) {
		tmp = -x;
	} else if (y <= 6.2e+90) {
		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 <= 8.6e-133:
		tmp = -x
	elif y <= 6.2e+90:
		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 <= 8.6e-133)
		tmp = Float64(-x);
	elseif (y <= 6.2e+90)
		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 <= 8.6e-133)
		tmp = -x;
	elseif (y <= 6.2e+90)
		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, 8.6e-133], (-x), If[LessEqual[y, 6.2e+90], 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 8.6 \cdot 10^{-133}:\\
\;\;\;\;-x\\

\mathbf{elif}\;y \leq 6.2 \cdot 10^{+90}:\\
\;\;\;\;\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.9
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 < 8.60000000000000032e-133

    1. Initial program 31.3

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

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

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

      [Start]7.1

      \[ -1 \cdot x \]

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

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

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

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

    if 8.60000000000000032e-133 < y < 6.19999999999999977e90

    1. Initial program 10.9

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

    if 6.19999999999999977e90 < y

    1. Initial program 49.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 8.6 \cdot 10^{-133}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+90}:\\ \;\;\;\;\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 7.2 \cdot 10^{-81}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-33}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 0.014:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 2
Error31.2
Cost64
\[y \]

Error

Reproduce?

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