Average Error: 32.0 → 18.1
Time: 3.8s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.488419020361885603121058718518165058597 \cdot 10^{90}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 321983510253822902678712615891538695684100:\\ \;\;\;\;\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 -3.488419020361885603121058718518165058597 \cdot 10^{90}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 321983510253822902678712615891538695684100:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r806656 = x;
        double r806657 = r806656 * r806656;
        double r806658 = y;
        double r806659 = r806658 * r806658;
        double r806660 = r806657 + r806659;
        double r806661 = sqrt(r806660);
        return r806661;
}

double f(double x, double y) {
        double r806662 = x;
        double r806663 = -3.4884190203618856e+90;
        bool r806664 = r806662 <= r806663;
        double r806665 = -1.0;
        double r806666 = r806665 * r806662;
        double r806667 = 3.219835102538229e+41;
        bool r806668 = r806662 <= r806667;
        double r806669 = r806662 * r806662;
        double r806670 = y;
        double r806671 = r806670 * r806670;
        double r806672 = r806669 + r806671;
        double r806673 = sqrt(r806672);
        double r806674 = r806668 ? r806673 : r806662;
        double r806675 = r806664 ? r806666 : r806674;
        return r806675;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.0
Target17.8
Herbie18.1
\[\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 < -3.4884190203618856e+90

    1. Initial program 50.6

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

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

    if -3.4884190203618856e+90 < x < 3.219835102538229e+41

    1. Initial program 21.9

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

    if 3.219835102538229e+41 < x

    1. Initial program 45.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.488419020361885603121058718518165058597 \cdot 10^{90}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 321983510253822902678712615891538695684100:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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