Average Error: 31.8 → 18.0
Time: 3.5s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.133795376408894095114882696362622107441 \cdot 10^{79}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.844559323175136428258475744554794771695 \cdot 10^{102}:\\ \;\;\;\;\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 -4.133795376408894095114882696362622107441 \cdot 10^{79}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.844559323175136428258475744554794771695 \cdot 10^{102}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r41453176 = x;
        double r41453177 = r41453176 * r41453176;
        double r41453178 = y;
        double r41453179 = r41453178 * r41453178;
        double r41453180 = r41453177 + r41453179;
        double r41453181 = sqrt(r41453180);
        return r41453181;
}

double f(double x, double y) {
        double r41453182 = x;
        double r41453183 = -4.133795376408894e+79;
        bool r41453184 = r41453182 <= r41453183;
        double r41453185 = -r41453182;
        double r41453186 = 2.8445593231751364e+102;
        bool r41453187 = r41453182 <= r41453186;
        double r41453188 = y;
        double r41453189 = r41453188 * r41453188;
        double r41453190 = r41453182 * r41453182;
        double r41453191 = r41453189 + r41453190;
        double r41453192 = sqrt(r41453191);
        double r41453193 = r41453187 ? r41453192 : r41453182;
        double r41453194 = r41453184 ? r41453185 : r41453193;
        return r41453194;
}

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.8
Target17.9
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 < -4.133795376408894e+79

    1. Initial program 49.2

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

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

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

    if -4.133795376408894e+79 < x < 2.8445593231751364e+102

    1. Initial program 21.7

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

    if 2.8445593231751364e+102 < x

    1. Initial program 52.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.133795376408894095114882696362622107441 \cdot 10^{79}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.844559323175136428258475744554794771695 \cdot 10^{102}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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