Average Error: 31.9 → 17.6
Time: 958.0ms
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.16501881147335996 \cdot 10^{142}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.23653280905907259 \cdot 10^{138}:\\ \;\;\;\;\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.16501881147335996 \cdot 10^{142}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 9.23653280905907259 \cdot 10^{138}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r1033503 = x;
        double r1033504 = r1033503 * r1033503;
        double r1033505 = y;
        double r1033506 = r1033505 * r1033505;
        double r1033507 = r1033504 + r1033506;
        double r1033508 = sqrt(r1033507);
        return r1033508;
}

double f(double x, double y) {
        double r1033509 = x;
        double r1033510 = -9.16501881147336e+142;
        bool r1033511 = r1033509 <= r1033510;
        double r1033512 = -1.0;
        double r1033513 = r1033512 * r1033509;
        double r1033514 = 9.236532809059073e+138;
        bool r1033515 = r1033509 <= r1033514;
        double r1033516 = r1033509 * r1033509;
        double r1033517 = y;
        double r1033518 = r1033517 * r1033517;
        double r1033519 = r1033516 + r1033518;
        double r1033520 = sqrt(r1033519);
        double r1033521 = r1033515 ? r1033520 : r1033509;
        double r1033522 = r1033511 ? r1033513 : r1033521;
        return r1033522;
}

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.7
Herbie17.6
\[\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 3 regimes
  2. if x < -9.16501881147336e+142

    1. Initial program 61.3

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

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

    if -9.16501881147336e+142 < x < 9.236532809059073e+138

    1. Initial program 20.9

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

    if 9.236532809059073e+138 < x

    1. Initial program 59.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.16501881147335996 \cdot 10^{142}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.23653280905907259 \cdot 10^{138}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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