Average Error: 31.8 → 17.2
Time: 4.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.815000942687335399540629803602323238426 \cdot 10^{146}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 3.315991764196220167239997200279477919386 \cdot 10^{127}:\\ \;\;\;\;\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.815000942687335399540629803602323238426 \cdot 10^{146}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 3.315991764196220167239997200279477919386 \cdot 10^{127}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r634532 = x;
        double r634533 = r634532 * r634532;
        double r634534 = y;
        double r634535 = r634534 * r634534;
        double r634536 = r634533 + r634535;
        double r634537 = sqrt(r634536);
        return r634537;
}

double f(double x, double y) {
        double r634538 = x;
        double r634539 = -7.815000942687335e+146;
        bool r634540 = r634538 <= r634539;
        double r634541 = -1.0;
        double r634542 = r634541 * r634538;
        double r634543 = 3.31599176419622e+127;
        bool r634544 = r634538 <= r634543;
        double r634545 = r634538 * r634538;
        double r634546 = y;
        double r634547 = r634546 * r634546;
        double r634548 = r634545 + r634547;
        double r634549 = sqrt(r634548);
        double r634550 = r634544 ? r634549 : r634538;
        double r634551 = r634540 ? r634542 : r634550;
        return r634551;
}

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.4
Herbie17.2
\[\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.815000942687335e+146

    1. Initial program 62.0

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

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

    if -7.815000942687335e+146 < x < 3.31599176419622e+127

    1. Initial program 20.7

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

    if 3.31599176419622e+127 < x

    1. Initial program 56.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.815000942687335399540629803602323238426 \cdot 10^{146}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 3.315991764196220167239997200279477919386 \cdot 10^{127}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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