Average Error: 31.6 → 17.7
Time: 1.0s
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 r1040802 = x;
        double r1040803 = r1040802 * r1040802;
        double r1040804 = y;
        double r1040805 = r1040804 * r1040804;
        double r1040806 = r1040803 + r1040805;
        double r1040807 = sqrt(r1040806);
        return r1040807;
}

double f(double x, double y) {
        double r1040808 = x;
        double r1040809 = -6.754060706975556e+99;
        bool r1040810 = r1040808 <= r1040809;
        double r1040811 = -1.0;
        double r1040812 = r1040811 * r1040808;
        double r1040813 = -1.7256510915817855e-210;
        bool r1040814 = r1040808 <= r1040813;
        double r1040815 = r1040808 * r1040808;
        double r1040816 = y;
        double r1040817 = r1040816 * r1040816;
        double r1040818 = r1040815 + r1040817;
        double r1040819 = sqrt(r1040818);
        double r1040820 = 1.3362064325006243e-202;
        bool r1040821 = r1040808 <= r1040820;
        double r1040822 = 4.9646550618943354e+123;
        bool r1040823 = r1040808 <= r1040822;
        double r1040824 = r1040823 ? r1040819 : r1040808;
        double r1040825 = r1040821 ? r1040816 : r1040824;
        double r1040826 = r1040814 ? r1040819 : r1040825;
        double r1040827 = r1040810 ? r1040812 : r1040826;
        return r1040827;
}

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))))