Average Error: 31.5 → 18.0
Time: 9.6s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.940119593462783780503740532731557409155 \cdot 10^{70}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.149380376403675710903737768625835202966 \cdot 10^{95}:\\ \;\;\;\;\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 -1.940119593462783780503740532731557409155 \cdot 10^{70}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.149380376403675710903737768625835202966 \cdot 10^{95}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r40123236 = x;
        double r40123237 = r40123236 * r40123236;
        double r40123238 = y;
        double r40123239 = r40123238 * r40123238;
        double r40123240 = r40123237 + r40123239;
        double r40123241 = sqrt(r40123240);
        return r40123241;
}

double f(double x, double y) {
        double r40123242 = x;
        double r40123243 = -1.9401195934627838e+70;
        bool r40123244 = r40123242 <= r40123243;
        double r40123245 = -r40123242;
        double r40123246 = 1.1493803764036757e+95;
        bool r40123247 = r40123242 <= r40123246;
        double r40123248 = y;
        double r40123249 = r40123248 * r40123248;
        double r40123250 = r40123242 * r40123242;
        double r40123251 = r40123249 + r40123250;
        double r40123252 = sqrt(r40123251);
        double r40123253 = r40123247 ? r40123252 : r40123242;
        double r40123254 = r40123244 ? r40123245 : r40123253;
        return r40123254;
}

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.5
Target17.7
Herbie18.0
\[\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.9401195934627838e+70

    1. Initial program 46.3

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

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

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

    if -1.9401195934627838e+70 < x < 1.1493803764036757e+95

    1. Initial program 21.8

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

    if 1.1493803764036757e+95 < x

    1. Initial program 49.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.940119593462783780503740532731557409155 \cdot 10^{70}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.149380376403675710903737768625835202966 \cdot 10^{95}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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