Average Error: 31.6 → 17.7
Time: 1.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.75406070697555614550103171070689226775 \cdot 10^{99}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.725651091581785482443039514213583051037 \cdot 10^{-210}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.336206432500624299310601884853873391011 \cdot 10^{-202}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 4.964655061894335407151343370923293101746 \cdot 10^{123}:\\ \;\;\;\;\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 -6.75406070697555614550103171070689226775 \cdot 10^{99}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le -1.725651091581785482443039514213583051037 \cdot 10^{-210}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{elif}\;x \le 1.336206432500624299310601884853873391011 \cdot 10^{-202}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 4.964655061894335407151343370923293101746 \cdot 10^{123}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r967715 = x;
        double r967716 = r967715 * r967715;
        double r967717 = y;
        double r967718 = r967717 * r967717;
        double r967719 = r967716 + r967718;
        double r967720 = sqrt(r967719);
        return r967720;
}

double f(double x, double y) {
        double r967721 = x;
        double r967722 = -6.754060706975556e+99;
        bool r967723 = r967721 <= r967722;
        double r967724 = -1.0;
        double r967725 = r967724 * r967721;
        double r967726 = -1.7256510915817855e-210;
        bool r967727 = r967721 <= r967726;
        double r967728 = r967721 * r967721;
        double r967729 = y;
        double r967730 = r967729 * r967729;
        double r967731 = r967728 + r967730;
        double r967732 = sqrt(r967731);
        double r967733 = 1.3362064325006243e-202;
        bool r967734 = r967721 <= r967733;
        double r967735 = 4.9646550618943354e+123;
        bool r967736 = r967721 <= r967735;
        double r967737 = r967736 ? r967732 : r967721;
        double r967738 = r967734 ? r967729 : r967737;
        double r967739 = r967727 ? r967732 : r967738;
        double r967740 = r967723 ? r967725 : r967739;
        return r967740;
}

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.6
Target17.4
Herbie17.7
\[\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 4 regimes
  2. if x < -6.754060706975556e+99

    1. Initial program 50.7

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

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

    if -6.754060706975556e+99 < x < -1.7256510915817855e-210 or 1.3362064325006243e-202 < x < 4.9646550618943354e+123

    1. Initial program 17.6

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

    if -1.7256510915817855e-210 < x < 1.3362064325006243e-202

    1. Initial program 31.1

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Taylor expanded around 0 33.2

      \[\leadsto \color{blue}{y}\]

    if 4.9646550618943354e+123 < x

    1. Initial program 56.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.75406070697555614550103171070689226775 \cdot 10^{99}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.725651091581785482443039514213583051037 \cdot 10^{-210}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.336206432500624299310601884853873391011 \cdot 10^{-202}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 4.964655061894335407151343370923293101746 \cdot 10^{123}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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