Average Error: 30.9 → 17.2
Time: 2.7s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.637979099701820103283669167726628154584 \cdot 10^{53}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.637979099701820103283669167726628154584 \cdot 10^{53}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r689184 = x;
        double r689185 = r689184 * r689184;
        double r689186 = y;
        double r689187 = r689186 * r689186;
        double r689188 = r689185 + r689187;
        double r689189 = sqrt(r689188);
        return r689189;
}

double f(double x, double y) {
        double r689190 = x;
        double r689191 = -9.850726757232305e+116;
        bool r689192 = r689190 <= r689191;
        double r689193 = -r689190;
        double r689194 = 5.63797909970182e+53;
        bool r689195 = r689190 <= r689194;
        double r689196 = y;
        double r689197 = r689196 * r689196;
        double r689198 = r689190 * r689190;
        double r689199 = r689197 + r689198;
        double r689200 = sqrt(r689199);
        double r689201 = r689195 ? r689200 : r689190;
        double r689202 = r689192 ? r689193 : r689201;
        return r689202;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.9
Target17.0
Herbie17.2
\[\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 < -9.850726757232305e+116

    1. Initial program 55.5

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

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

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

    if -9.850726757232305e+116 < x < 5.63797909970182e+53

    1. Initial program 20.7

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

    if 5.63797909970182e+53 < x

    1. Initial program 43.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.637979099701820103283669167726628154584 \cdot 10^{53}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.1236950826599826e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (* x x) (* y y))) x))

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