Average Error: 31.4 → 17.2
Time: 3.3s
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 r1336964 = X;
        double r1336965 = r1336964 * r1336964;
        double r1336966 = y;
        double r1336967 = r1336966 * r1336966;
        double r1336968 = r1336965 + r1336967;
        double r1336969 = sqrt(r1336968);
        return r1336969;
}

double f(double X, double y) {
        double r1336970 = X;
        double r1336971 = -3.3032099476572043e+84;
        bool r1336972 = r1336970 <= r1336971;
        double r1336973 = -r1336970;
        double r1336974 = 1.943934747643532e+128;
        bool r1336975 = r1336970 <= r1336974;
        double r1336976 = r1336970 * r1336970;
        double r1336977 = y;
        double r1336978 = r1336977 * r1336977;
        double r1336979 = r1336976 + r1336978;
        double r1336980 = sqrt(r1336979);
        double r1336981 = r1336975 ? r1336980 : r1336970;
        double r1336982 = r1336972 ? r1336973 : r1336981;
        return r1336982;
}

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