Average Error: 31.7 → 18.1
Time: 2.0s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -3.4362841072323272 \cdot 10^{150}:\\ \;\;\;\;-1 \cdot y\\ \mathbf{elif}\;y \le -1.7874287404230692 \cdot 10^{-225}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 5.8993776144081826 \cdot 10^{-308}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \le 2.4345784437110915 \cdot 10^{-199}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;y \le 1.7970794289179904 \cdot 10^{-166}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \le 1.0688990210562475 \cdot 10^{-162}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;y \le 2.23402097896517821 \cdot 10^{109}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -3.4362841072323272 \cdot 10^{150}:\\
\;\;\;\;-1 \cdot y\\

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

\mathbf{elif}\;y \le 5.8993776144081826 \cdot 10^{-308}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \le 2.4345784437110915 \cdot 10^{-199}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;y \le 1.7970794289179904 \cdot 10^{-166}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \le 1.0688990210562475 \cdot 10^{-162}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;y \le 2.23402097896517821 \cdot 10^{109}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{else}:\\
\;\;\;\;y\\

\end{array}
double f(double x, double y) {
        double r740318 = x;
        double r740319 = r740318 * r740318;
        double r740320 = y;
        double r740321 = r740320 * r740320;
        double r740322 = r740319 + r740321;
        double r740323 = sqrt(r740322);
        return r740323;
}

double f(double x, double y) {
        double r740324 = y;
        double r740325 = -3.436284107232327e+150;
        bool r740326 = r740324 <= r740325;
        double r740327 = -1.0;
        double r740328 = r740327 * r740324;
        double r740329 = -1.7874287404230692e-225;
        bool r740330 = r740324 <= r740329;
        double r740331 = x;
        double r740332 = r740331 * r740331;
        double r740333 = r740324 * r740324;
        double r740334 = r740332 + r740333;
        double r740335 = sqrt(r740334);
        double r740336 = 5.899377614408183e-308;
        bool r740337 = r740324 <= r740336;
        double r740338 = 2.4345784437110915e-199;
        bool r740339 = r740324 <= r740338;
        double r740340 = r740327 * r740331;
        double r740341 = 1.7970794289179904e-166;
        bool r740342 = r740324 <= r740341;
        double r740343 = 1.0688990210562475e-162;
        bool r740344 = r740324 <= r740343;
        double r740345 = 2.2340209789651782e+109;
        bool r740346 = r740324 <= r740345;
        double r740347 = r740346 ? r740335 : r740324;
        double r740348 = r740344 ? r740340 : r740347;
        double r740349 = r740342 ? r740331 : r740348;
        double r740350 = r740339 ? r740340 : r740349;
        double r740351 = r740337 ? r740331 : r740350;
        double r740352 = r740330 ? r740335 : r740351;
        double r740353 = r740326 ? r740328 : r740352;
        return r740353;
}

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.7
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 5 regimes
  2. if y < -3.436284107232327e+150

    1. Initial program 62.6

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied flip-+64.0

      \[\leadsto \sqrt{\color{blue}{\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}{x \cdot x - y \cdot y}}}\]
    4. Simplified64.0

      \[\leadsto \sqrt{\frac{\color{blue}{\left(-{y}^{3}\right) \cdot y + {x}^{4}}}{x \cdot x - y \cdot y}}\]
    5. Taylor expanded around -inf 8.8

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

    if -3.436284107232327e+150 < y < -1.7874287404230692e-225 or 1.0688990210562475e-162 < y < 2.2340209789651782e+109

    1. Initial program 17.2

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

    if -1.7874287404230692e-225 < y < 5.899377614408183e-308 or 2.4345784437110915e-199 < y < 1.7970794289179904e-166

    1. Initial program 31.5

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

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

    if 5.899377614408183e-308 < y < 2.4345784437110915e-199 or 1.7970794289179904e-166 < y < 1.0688990210562475e-162

    1. Initial program 31.3

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

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

    if 2.2340209789651782e+109 < y

    1. Initial program 53.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.4362841072323272 \cdot 10^{150}:\\ \;\;\;\;-1 \cdot y\\ \mathbf{elif}\;y \le -1.7874287404230692 \cdot 10^{-225}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 5.8993776144081826 \cdot 10^{-308}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \le 2.4345784437110915 \cdot 10^{-199}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;y \le 1.7970794289179904 \cdot 10^{-166}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \le 1.0688990210562475 \cdot 10^{-162}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;y \le 2.23402097896517821 \cdot 10^{109}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]

Reproduce

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