Average Error: 31.6 → 18.7
Time: 1.0s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.8460535119133569 \cdot 10^{74}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.3504253849915568 \cdot 10^{-194}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -2.968956980813959 \cdot 10^{-266}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.19099635470288769 \cdot 10^{-228}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.08574889376971239 \cdot 10^{-190}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 3.98422560465703889 \cdot 10^{39}:\\ \;\;\;\;\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 -3.8460535119133569 \cdot 10^{74}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le -2.968956980813959 \cdot 10^{-266}:\\
\;\;\;\;y\\

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

\mathbf{elif}\;x \le 1.08574889376971239 \cdot 10^{-190}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 3.98422560465703889 \cdot 10^{39}:\\
\;\;\;\;\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 <= -3.846053511913357e+74)) {
		temp = (-1.0 * x);
	} else {
		double temp_1;
		if ((x <= -1.3504253849915568e-194)) {
			temp_1 = sqrt(((x * x) + (y * y)));
		} else {
			double temp_2;
			if ((x <= -2.968956980813959e-266)) {
				temp_2 = y;
			} else {
				double temp_3;
				if ((x <= 1.1909963547028877e-228)) {
					temp_3 = sqrt(((x * x) + (y * y)));
				} else {
					double temp_4;
					if ((x <= 1.0857488937697124e-190)) {
						temp_4 = y;
					} else {
						double temp_5;
						if ((x <= 3.984225604657039e+39)) {
							temp_5 = sqrt(((x * x) + (y * y)));
						} else {
							temp_5 = x;
						}
						temp_4 = temp_5;
					}
					temp_3 = temp_4;
				}
				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.6
Target17.8
Herbie18.7
\[\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 < -3.846053511913357e+74

    1. Initial program 47.2

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

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

    if -3.846053511913357e+74 < x < -1.3504253849915568e-194 or -2.968956980813959e-266 < x < 1.1909963547028877e-228 or 1.0857488937697124e-190 < x < 3.984225604657039e+39

    1. Initial program 20.9

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

    if -1.3504253849915568e-194 < x < -2.968956980813959e-266 or 1.1909963547028877e-228 < x < 1.0857488937697124e-190

    1. Initial program 31.4

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

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

    if 3.984225604657039e+39 < x

    1. Initial program 43.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.8460535119133569 \cdot 10^{74}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.3504253849915568 \cdot 10^{-194}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -2.968956980813959 \cdot 10^{-266}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.19099635470288769 \cdot 10^{-228}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.08574889376971239 \cdot 10^{-190}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 3.98422560465703889 \cdot 10^{39}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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