Average Error: 31.4 → 17.2
Time: 4.9s
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{y \cdot y + x \cdot x}\\ \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{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r55096585 = x;
        double r55096586 = r55096585 * r55096585;
        double r55096587 = y;
        double r55096588 = r55096587 * r55096587;
        double r55096589 = r55096586 + r55096588;
        double r55096590 = sqrt(r55096589);
        return r55096590;
}

double f(double x, double y) {
        double r55096591 = x;
        double r55096592 = -3.3032099476572043e+84;
        bool r55096593 = r55096591 <= r55096592;
        double r55096594 = -r55096591;
        double r55096595 = 1.943934747643532e+128;
        bool r55096596 = r55096591 <= r55096595;
        double r55096597 = y;
        double r55096598 = r55096597 * r55096597;
        double r55096599 = r55096591 * r55096591;
        double r55096600 = r55096598 + r55096599;
        double r55096601 = sqrt(r55096600);
        double r55096602 = r55096596 ? r55096601 : r55096591;
        double r55096603 = r55096593 ? r55096594 : r55096602;
        return r55096603;
}

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

Reproduce

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