Average Error: 31.1 → 17.6
Time: 2.6s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.17080433873193748647548036270335902417 \cdot 10^{152}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 371427111337525632:\\ \;\;\;\;\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 -7.17080433873193748647548036270335902417 \cdot 10^{152}:\\
\;\;\;\;-x\\

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

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

\end{array}
double f(double x, double y) {
        double r870040 = x;
        double r870041 = r870040 * r870040;
        double r870042 = y;
        double r870043 = r870042 * r870042;
        double r870044 = r870041 + r870043;
        double r870045 = sqrt(r870044);
        return r870045;
}

double f(double x, double y) {
        double r870046 = x;
        double r870047 = -7.1708043387319375e+152;
        bool r870048 = r870046 <= r870047;
        double r870049 = -r870046;
        double r870050 = 3.714271113375256e+17;
        bool r870051 = r870046 <= r870050;
        double r870052 = r870046 * r870046;
        double r870053 = y;
        double r870054 = r870053 * r870053;
        double r870055 = r870052 + r870054;
        double r870056 = sqrt(r870055);
        double r870057 = r870051 ? r870056 : r870046;
        double r870058 = r870048 ? r870049 : r870057;
        return r870058;
}

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.1
Target17.0
Herbie17.6
\[\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 < -7.1708043387319375e+152

    1. Initial program 63.7

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

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

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

    if -7.1708043387319375e+152 < x < 3.714271113375256e+17

    1. Initial program 21.0

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

    if 3.714271113375256e+17 < x

    1. Initial program 41.2

      \[\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 simplification17.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.17080433873193748647548036270335902417 \cdot 10^{152}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 371427111337525632:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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