Average Error: 31.4 → 17.2
Time: 9.5s
Precision: 64
\[\sqrt{{x}^{2} + {y}^{2}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.303209947657204342880384766533788360025 \cdot 10^{84}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.943934747643531875760607600817076209382 \cdot 10^{128}:\\ \;\;\;\;\sqrt{{x}^{2} + {y}^{2}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{{x}^{2} + {y}^{2}}
\begin{array}{l}
\mathbf{if}\;x \le -3.303209947657204342880384766533788360025 \cdot 10^{84}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.943934747643531875760607600817076209382 \cdot 10^{128}:\\
\;\;\;\;\sqrt{{x}^{2} + {y}^{2}}\\

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

\end{array}
double f(double x, double y) {
        double r806536 = x;
        double r806537 = 2.0;
        double r806538 = pow(r806536, r806537);
        double r806539 = y;
        double r806540 = pow(r806539, r806537);
        double r806541 = r806538 + r806540;
        double r806542 = sqrt(r806541);
        return r806542;
}

double f(double x, double y) {
        double r806543 = x;
        double r806544 = -3.3032099476572043e+84;
        bool r806545 = r806543 <= r806544;
        double r806546 = -r806543;
        double r806547 = 1.943934747643532e+128;
        bool r806548 = r806543 <= r806547;
        double r806549 = 2.0;
        double r806550 = pow(r806543, r806549);
        double r806551 = y;
        double r806552 = pow(r806551, r806549);
        double r806553 = r806550 + r806552;
        double r806554 = sqrt(r806553);
        double r806555 = r806548 ? r806554 : r806543;
        double r806556 = r806545 ? r806546 : r806555;
        return r806556;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if x < -3.3032099476572043e+84

    1. Initial program 48.4

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

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

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

    if -3.3032099476572043e+84 < x < 1.943934747643532e+128

    1. Initial program 21.1

      \[\sqrt{{x}^{2} + {y}^{2}}\]

    if 1.943934747643532e+128 < x

    1. Initial program 57.0

      \[\sqrt{{x}^{2} + {y}^{2}}\]
    2. Taylor expanded around inf 8.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.303209947657204342880384766533788360025 \cdot 10^{84}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.943934747643531875760607600817076209382 \cdot 10^{128}:\\ \;\;\;\;\sqrt{{x}^{2} + {y}^{2}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (x y)
  :name "sqrt(pow(x, 2) + pow(y, 2))"
  :precision binary64
  (sqrt (+ (pow x 2) (pow y 2))))