Average Error: 31.6 → 18.9
Time: 2.5s
Precision: binary64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7569446232380357 \cdot 10^{+114}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -4.576170092116779 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \leq -5.047961066574088 \cdot 10^{-113}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 5.63142386051803 \cdot 10^{+118}:\\ \;\;\;\;\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 \leq -2.7569446232380357 \cdot 10^{+114}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \leq -4.576170092116779 \cdot 10^{-56}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{elif}\;x \leq -5.047961066574088 \cdot 10^{-113}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \leq 5.63142386051803 \cdot 10^{+118}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
(FPCore (x y) :precision binary64 (sqrt (+ (* x x) (* y y))))
(FPCore (x y)
 :precision binary64
 (if (<= x -2.7569446232380357e+114)
   (- x)
   (if (<= x -4.576170092116779e-56)
     (sqrt (+ (* x x) (* y y)))
     (if (<= x -5.047961066574088e-113)
       y
       (if (<= x 5.63142386051803e+118) (sqrt (+ (* x x) (* y y))) x)))))
double code(double x, double y) {
	return ((double) sqrt(((double) (((double) (x * x)) + ((double) (y * y))))));
}
double code(double x, double y) {
	double tmp;
	if ((x <= -2.7569446232380357e+114)) {
		tmp = ((double) -(x));
	} else {
		double tmp_1;
		if ((x <= -4.576170092116779e-56)) {
			tmp_1 = ((double) sqrt(((double) (((double) (x * x)) + ((double) (y * y))))));
		} else {
			double tmp_2;
			if ((x <= -5.047961066574088e-113)) {
				tmp_2 = y;
			} else {
				double tmp_3;
				if ((x <= 5.63142386051803e+118)) {
					tmp_3 = ((double) sqrt(((double) (((double) (x * x)) + ((double) (y * y))))));
				} else {
					tmp_3 = x;
				}
				tmp_2 = tmp_3;
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	return tmp;
}

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.6
Herbie18.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 4 regimes
  2. if x < -2.75694462323803569e114

    1. Initial program 54.5

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

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

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

    if -2.75694462323803569e114 < x < -4.57617009211677922e-56 or -5.04796106657408782e-113 < x < 5.63142386051802992e118

    1. Initial program 21.5

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

    if -4.57617009211677922e-56 < x < -5.04796106657408782e-113

    1. Initial program 14.8

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

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

    if 5.63142386051802992e118 < x

    1. Initial program 55.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.7569446232380357 \cdot 10^{+114}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -4.576170092116779 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \leq -5.047961066574088 \cdot 10^{-113}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 5.63142386051803 \cdot 10^{+118}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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