Average Error: 31.1 → 17.2
Time: 1.9s
Precision: binary64
Cost: 8132
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \leq -4.1162129695124836 \cdot 10^{+151}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -2.1964806768619867 \cdot 10^{-223}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \leq 2.11287353661743 \cdot 10^{-238}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 7.549554504255097 \cdot 10^{+118}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \leq -4.1162129695124836 \cdot 10^{+151}:\\
\;\;\;\;-y\\

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

\mathbf{elif}\;y \leq 2.11287353661743 \cdot 10^{-238}:\\
\;\;\;\;-x\\

\mathbf{elif}\;y \leq 7.549554504255097 \cdot 10^{+118}:\\
\;\;\;\;\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 -4.1162129695124836e+151)
   (- y)
   (if (<= y -2.1964806768619867e-223)
     (sqrt (+ (* x x) (* y y)))
     (if (<= y 2.11287353661743e-238)
       (- x)
       (if (<= y 7.549554504255097e+118) (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 <= -4.1162129695124836e+151) {
		tmp = -y;
	} else if (y <= -2.1964806768619867e-223) {
		tmp = sqrt((x * x) + (y * y));
	} else if (y <= 2.11287353661743e-238) {
		tmp = -x;
	} else if (y <= 7.549554504255097e+118) {
		tmp = sqrt((x * x) + (y * y));
	} else {
		tmp = y;
	}
	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.1
Target17.2
Herbie17.2
\[\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}\]

Alternatives

Alternative 1
Error25.7
Cost1027
\[\begin{array}{l} \mathbf{if}\;y \leq -2.8415552706869677 \cdot 10^{-93}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 8.015064203069834 \cdot 10^{-242}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 210377114512.3621:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]
Alternative 2
Error26.5
Cost706
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4908880737490054 \cdot 10^{-151}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 4099513107437.5083:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]
Alternative 3
Error36.8
Cost1027
\[\begin{array}{l} \mathbf{if}\;x \leq 3.303349602246751 \cdot 10^{-148}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 5.865007045303084 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.532214216476038 \cdot 10^{-37}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
Alternative 4
Error46.0
Cost385
\[\begin{array}{l} \mathbf{if}\;x \leq -3.007955690093281 \cdot 10^{-307}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
Alternative 5
Error60.5
Cost64
\[1\]

Error

Derivation

  1. Split input into 4 regimes
  2. if y < -4.11621296951248365e151

    1. Initial program 63.7

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

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

      \[\leadsto \color{blue}{-y}\]
    4. Simplified7.0

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

    if -4.11621296951248365e151 < y < -2.1964806768619867e-223 or 2.1128735366174298e-238 < y < 7.549554504255097e118

    1. Initial program 18.1

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Simplified18.1

      \[\leadsto \color{blue}{\sqrt{x \cdot x + y \cdot y}}\]

    if -2.1964806768619867e-223 < y < 2.1128735366174298e-238

    1. Initial program 30.4

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

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

      \[\leadsto \color{blue}{-x}\]
    4. Simplified32.4

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

    if 7.549554504255097e118 < y

    1. Initial program 54.8

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

      \[\leadsto \color{blue}{y}\]
    3. Simplified9.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.1162129695124836 \cdot 10^{+151}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -2.1964806768619867 \cdot 10^{-223}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \leq 2.11287353661743 \cdot 10^{-238}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 7.549554504255097 \cdot 10^{+118}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]

Reproduce

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