Average Error: 31.7 → 17.5
Time: 940.0ms
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.4667592323261061 \cdot 10^{131}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.3722084465878742 \cdot 10^{86}:\\ \;\;\;\;\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.4667592323261061 \cdot 10^{131}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.3722084465878742 \cdot 10^{86}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r672134 = x;
        double r672135 = r672134 * r672134;
        double r672136 = y;
        double r672137 = r672136 * r672136;
        double r672138 = r672135 + r672137;
        double r672139 = sqrt(r672138);
        return r672139;
}

double f(double x, double y) {
        double r672140 = x;
        double r672141 = -1.4667592323261061e+131;
        bool r672142 = r672140 <= r672141;
        double r672143 = -1.0;
        double r672144 = r672143 * r672140;
        double r672145 = 1.3722084465878742e+86;
        bool r672146 = r672140 <= r672145;
        double r672147 = r672140 * r672140;
        double r672148 = y;
        double r672149 = r672148 * r672148;
        double r672150 = r672147 + r672149;
        double r672151 = sqrt(r672150);
        double r672152 = r672146 ? r672151 : r672140;
        double r672153 = r672142 ? r672144 : r672152;
        return r672153;
}

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.7
Target17.4
Herbie17.5
\[\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 3 regimes
  2. if x < -1.4667592323261061e+131

    1. Initial program 58.9

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

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

    if -1.4667592323261061e+131 < x < 1.3722084465878742e+86

    1. Initial program 21.0

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

    if 1.3722084465878742e+86 < x

    1. Initial program 50.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.4667592323261061 \cdot 10^{131}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.3722084465878742 \cdot 10^{86}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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