Average Error: 31.5 → 18.5
Time: 1.5s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.97733214615282287 \cdot 10^{89}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -2.6982430225033068 \cdot 10^{-174}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 3.7706602894998885 \cdot 10^{-238}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.6531905343411006 \cdot 10^{78}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -9.97733214615282287 \cdot 10^{89}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le -2.6982430225033068 \cdot 10^{-174}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{elif}\;x \le 3.7706602894998885 \cdot 10^{-238}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 1.6531905343411006 \cdot 10^{78}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double code(double x, double y) {
	return sqrt(((x * x) + (y * y)));
}
double code(double x, double y) {
	double temp;
	if ((x <= -9.977332146152823e+89)) {
		temp = (-1.0 * x);
	} else {
		double temp_1;
		if ((x <= -2.6982430225033068e-174)) {
			temp_1 = sqrt(((x * x) + (y * y)));
		} else {
			double temp_2;
			if ((x <= 3.7706602894998885e-238)) {
				temp_2 = y;
			} else {
				double temp_3;
				if ((x <= 1.6531905343411006e+78)) {
					temp_3 = sqrt(((x * x) + (y * y)));
				} else {
					temp_3 = x;
				}
				temp_2 = temp_3;
			}
			temp_1 = temp_2;
		}
		temp = temp_1;
	}
	return temp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.5
Target18.1
Herbie18.5
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659983 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.11655762118336204 \cdot 10^{93}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if x < -9.977332146152823e+89

    1. Initial program 49.1

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

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

    if -9.977332146152823e+89 < x < -2.6982430225033068e-174 or 3.7706602894998885e-238 < x < 1.6531905343411006e+78

    1. Initial program 18.3

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

    if -2.6982430225033068e-174 < x < 3.7706602894998885e-238

    1. Initial program 32.0

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

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

    if 1.6531905343411006e+78 < x

    1. Initial program 48.4

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

      \[\leadsto \color{blue}{x}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification18.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.97733214615282287 \cdot 10^{89}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -2.6982430225033068 \cdot 10^{-174}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 3.7706602894998885 \cdot 10^{-238}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.6531905343411006 \cdot 10^{78}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

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

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