Average Error: 31.4 → 17.2
Time: 5.5s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.303209947657204342880384766533788360025 \cdot 10^{84}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.943934747643531875760607600817076209382 \cdot 10^{128}:\\ \;\;\;\;\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 -3.303209947657204342880384766533788360025 \cdot 10^{84}:\\
\;\;\;\;-x\\

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

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

\end{array}
double f(double x, double y) {
        double r2209463 = x;
        double r2209464 = r2209463 * r2209463;
        double r2209465 = y;
        double r2209466 = r2209465 * r2209465;
        double r2209467 = r2209464 + r2209466;
        double r2209468 = sqrt(r2209467);
        return r2209468;
}

double f(double x, double y) {
        double r2209469 = x;
        double r2209470 = -3.3032099476572043e+84;
        bool r2209471 = r2209469 <= r2209470;
        double r2209472 = -r2209469;
        double r2209473 = 1.943934747643532e+128;
        bool r2209474 = r2209469 <= r2209473;
        double r2209475 = r2209469 * r2209469;
        double r2209476 = y;
        double r2209477 = r2209476 * r2209476;
        double r2209478 = r2209475 + r2209477;
        double r2209479 = sqrt(r2209478);
        double r2209480 = r2209474 ? r2209479 : r2209469;
        double r2209481 = r2209471 ? r2209472 : r2209480;
        return r2209481;
}

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 \cdot x + y \cdot y}\]
    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 \cdot x + y \cdot y}\]

    if 1.943934747643532e+128 < x

    1. Initial program 57.0

      \[\sqrt{x \cdot x + y \cdot y}\]
    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 \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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