Average Error: 31.5 → 17.8
Time: 2.7s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.300285162304908517480300856336753809112 \cdot 10^{108}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.865924590141658442437285705670191540248 \cdot 10^{56}:\\ \;\;\;\;\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 -1.300285162304908517480300856336753809112 \cdot 10^{108}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.865924590141658442437285705670191540248 \cdot 10^{56}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r791529 = x;
        double r791530 = r791529 * r791529;
        double r791531 = y;
        double r791532 = r791531 * r791531;
        double r791533 = r791530 + r791532;
        double r791534 = sqrt(r791533);
        return r791534;
}

double f(double x, double y) {
        double r791535 = x;
        double r791536 = -1.3002851623049085e+108;
        bool r791537 = r791535 <= r791536;
        double r791538 = -1.0;
        double r791539 = r791538 * r791535;
        double r791540 = 1.8659245901416584e+56;
        bool r791541 = r791535 <= r791540;
        double r791542 = r791535 * r791535;
        double r791543 = y;
        double r791544 = r791543 * r791543;
        double r791545 = r791542 + r791544;
        double r791546 = sqrt(r791545);
        double r791547 = r791541 ? r791546 : r791535;
        double r791548 = r791537 ? r791539 : r791547;
        return r791548;
}

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.6
Herbie17.8
\[\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.3002851623049085e+108

    1. Initial program 52.3

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

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

    if -1.3002851623049085e+108 < x < 1.8659245901416584e+56

    1. Initial program 21.7

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

    if 1.8659245901416584e+56 < x

    1. Initial program 45.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.300285162304908517480300856336753809112 \cdot 10^{108}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.865924590141658442437285705670191540248 \cdot 10^{56}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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