Average Error: 31.5 → 18.1
Time: 1.9s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.810291952691062 \cdot 10^{115}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -6.2167173716269886 \cdot 10^{-264}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 2.95065728572471767 \cdot 10^{-235}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 2.97128001067495674 \cdot 10^{26}:\\ \;\;\;\;\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 -5.810291952691062 \cdot 10^{115}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 2.95065728572471767 \cdot 10^{-235}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 2.97128001067495674 \cdot 10^{26}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r713192 = x;
        double r713193 = r713192 * r713192;
        double r713194 = y;
        double r713195 = r713194 * r713194;
        double r713196 = r713193 + r713195;
        double r713197 = sqrt(r713196);
        return r713197;
}

double f(double x, double y) {
        double r713198 = x;
        double r713199 = -5.810291952691062e+115;
        bool r713200 = r713198 <= r713199;
        double r713201 = -1.0;
        double r713202 = r713201 * r713198;
        double r713203 = -6.216717371626989e-264;
        bool r713204 = r713198 <= r713203;
        double r713205 = r713198 * r713198;
        double r713206 = y;
        double r713207 = r713206 * r713206;
        double r713208 = r713205 + r713207;
        double r713209 = sqrt(r713208);
        double r713210 = 2.9506572857247177e-235;
        bool r713211 = r713198 <= r713210;
        double r713212 = 2.9712800106749567e+26;
        bool r713213 = r713198 <= r713212;
        double r713214 = r713213 ? r713209 : r713198;
        double r713215 = r713211 ? r713206 : r713214;
        double r713216 = r713204 ? r713209 : r713215;
        double r713217 = r713200 ? r713202 : r713216;
        return r713217;
}

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.5
Target17.3
Herbie18.1
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659983 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.11655762118336204 \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 < -5.810291952691062e+115

    1. Initial program 54.1

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

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

    if -5.810291952691062e+115 < x < -6.216717371626989e-264 or 2.9506572857247177e-235 < x < 2.9712800106749567e+26

    1. Initial program 20.2

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

    if -6.216717371626989e-264 < x < 2.9506572857247177e-235

    1. Initial program 29.6

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

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

    if 2.9712800106749567e+26 < x

    1. Initial program 42.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.810291952691062 \cdot 10^{115}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -6.2167173716269886 \cdot 10^{-264}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 2.95065728572471767 \cdot 10^{-235}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 2.97128001067495674 \cdot 10^{26}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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