Average Error: 31.4 → 17.2
Time: 4.6s
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 r24382850 = x;
        double r24382851 = r24382850 * r24382850;
        double r24382852 = y;
        double r24382853 = r24382852 * r24382852;
        double r24382854 = r24382851 + r24382853;
        double r24382855 = sqrt(r24382854);
        return r24382855;
}

double f(double x, double y) {
        double r24382856 = x;
        double r24382857 = -3.3032099476572043e+84;
        bool r24382858 = r24382856 <= r24382857;
        double r24382859 = -r24382856;
        double r24382860 = 1.943934747643532e+128;
        bool r24382861 = r24382856 <= r24382860;
        double r24382862 = y;
        double r24382863 = r24382862 * r24382862;
        double r24382864 = r24382856 * r24382856;
        double r24382865 = r24382863 + r24382864;
        double r24382866 = sqrt(r24382865);
        double r24382867 = r24382861 ? r24382866 : r24382856;
        double r24382868 = r24382858 ? r24382859 : r24382867;
        return r24382868;
}

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))))