Average Error: 31.9 → 17.5
Time: 2.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.284483376836890693595922335560233872799 \cdot 10^{136}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 9.242348626981343105629292534441998064595 \cdot 10^{127}:\\ \;\;\;\;\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 -1.284483376836890693595922335560233872799 \cdot 10^{136}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 9.242348626981343105629292534441998064595 \cdot 10^{127}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r501106 = x;
        double r501107 = r501106 * r501106;
        double r501108 = y;
        double r501109 = r501108 * r501108;
        double r501110 = r501107 + r501109;
        double r501111 = sqrt(r501110);
        return r501111;
}

double f(double x, double y) {
        double r501112 = x;
        double r501113 = -1.2844833768368907e+136;
        bool r501114 = r501112 <= r501113;
        double r501115 = -r501112;
        double r501116 = 9.242348626981343e+127;
        bool r501117 = r501112 <= r501116;
        double r501118 = r501112 * r501112;
        double r501119 = y;
        double r501120 = r501119 * r501119;
        double r501121 = r501118 + r501120;
        double r501122 = sqrt(r501121);
        double r501123 = r501117 ? r501122 : r501112;
        double r501124 = r501114 ? r501115 : r501123;
        return r501124;
}

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.9
Target17.6
Herbie17.5
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659982632437974301616192301785 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.116557621183362039388201959321597704512 \cdot 10^{93}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.2844833768368907e+136

    1. Initial program 58.5

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

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

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

    if -1.2844833768368907e+136 < x < 9.242348626981343e+127

    1. Initial program 21.1

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

    if 9.242348626981343e+127 < x

    1. Initial program 57.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.284483376836890693595922335560233872799 \cdot 10^{136}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 9.242348626981343105629292534441998064595 \cdot 10^{127}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.123695082659983e145) (- x) (if (< x 1.11655762118336204e93) (sqrt (+ (* x x) (* y y))) x))

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