Average Error: 31.7 → 18.0
Time: 3.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.176665368798762034403420210926666921837 \cdot 10^{117}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.048565751089651352045129138343128122191 \cdot 10^{96}:\\ \;\;\;\;\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 -2.176665368798762034403420210926666921837 \cdot 10^{117}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.048565751089651352045129138343128122191 \cdot 10^{96}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r517500 = x;
        double r517501 = r517500 * r517500;
        double r517502 = y;
        double r517503 = r517502 * r517502;
        double r517504 = r517501 + r517503;
        double r517505 = sqrt(r517504);
        return r517505;
}

double f(double x, double y) {
        double r517506 = x;
        double r517507 = -2.176665368798762e+117;
        bool r517508 = r517506 <= r517507;
        double r517509 = -1.0;
        double r517510 = r517509 * r517506;
        double r517511 = 1.0485657510896514e+96;
        bool r517512 = r517506 <= r517511;
        double r517513 = r517506 * r517506;
        double r517514 = y;
        double r517515 = r517514 * r517514;
        double r517516 = r517513 + r517515;
        double r517517 = sqrt(r517516);
        double r517518 = r517512 ? r517517 : r517506;
        double r517519 = r517508 ? r517510 : r517518;
        return r517519;
}

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.7
Target18.0
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 < -2.176665368798762e+117

    1. Initial program 54.5

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

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

    if -2.176665368798762e+117 < x < 1.0485657510896514e+96

    1. Initial program 21.6

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

    if 1.0485657510896514e+96 < x

    1. Initial program 51.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.176665368798762034403420210926666921837 \cdot 10^{117}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.048565751089651352045129138343128122191 \cdot 10^{96}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019298 
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"
  :precision binary64

  :herbie-target
  (if (< x -1.123695082659983e145) (- x) (if (< x 1.11655762118336204e93) (sqrt (+ (* x x) (* y y))) x))

  (sqrt (+ (* x x) (* y y))))