Average Error: 32.0 → 18.1
Time: 5.8s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.199115232773121436978557182122313209889 \cdot 10^{121}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -9.538446928549385159760190961856882540607 \cdot 10^{-200}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 2.446990464932721506135775225301175117932 \cdot 10^{-197}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 3.937572631944601419338780453027731481475 \cdot 10^{124}:\\ \;\;\;\;\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.199115232773121436978557182122313209889 \cdot 10^{121}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 2.446990464932721506135775225301175117932 \cdot 10^{-197}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 3.937572631944601419338780453027731481475 \cdot 10^{124}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r551125 = x;
        double r551126 = r551125 * r551125;
        double r551127 = y;
        double r551128 = r551127 * r551127;
        double r551129 = r551126 + r551128;
        double r551130 = sqrt(r551129);
        return r551130;
}

double f(double x, double y) {
        double r551131 = x;
        double r551132 = -1.1991152327731214e+121;
        bool r551133 = r551131 <= r551132;
        double r551134 = -1.0;
        double r551135 = r551134 * r551131;
        double r551136 = -9.538446928549385e-200;
        bool r551137 = r551131 <= r551136;
        double r551138 = r551131 * r551131;
        double r551139 = y;
        double r551140 = r551139 * r551139;
        double r551141 = r551138 + r551140;
        double r551142 = sqrt(r551141);
        double r551143 = 2.4469904649327215e-197;
        bool r551144 = r551131 <= r551143;
        double r551145 = 3.9375726319446014e+124;
        bool r551146 = r551131 <= r551145;
        double r551147 = r551146 ? r551142 : r551131;
        double r551148 = r551144 ? r551139 : r551147;
        double r551149 = r551137 ? r551142 : r551148;
        double r551150 = r551133 ? r551135 : r551149;
        return r551150;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.0
Target17.7
Herbie18.1
\[\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 < -1.1991152327731214e+121

    1. Initial program 55.2

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

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

    if -1.1991152327731214e+121 < x < -9.538446928549385e-200 or 2.4469904649327215e-197 < x < 3.9375726319446014e+124

    1. Initial program 18.3

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

    if -9.538446928549385e-200 < x < 2.4469904649327215e-197

    1. Initial program 31.0

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

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

    if 3.9375726319446014e+124 < x

    1. Initial program 57.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.199115232773121436978557182122313209889 \cdot 10^{121}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -9.538446928549385159760190961856882540607 \cdot 10^{-200}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 2.446990464932721506135775225301175117932 \cdot 10^{-197}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 3.937572631944601419338780453027731481475 \cdot 10^{124}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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