Average Error: 31.4 → 17.2
Time: 8.9s
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 r2247265 = x;
double r2247266 = 2.0;
double r2247267 = pow(r2247265, r2247266);
double r2247268 = y;
double r2247269 = pow(r2247268, r2247266);
double r2247270 = r2247267 + r2247269;
double r2247271 = sqrt(r2247270);
return r2247271;
}


double f(double x, double y) {
double r2247272 = x;
double r2247273 = -3.3032099476572043e+84;
bool r2247274 = r2247272 <= r2247273;
double r2247275 = -r2247272;
double r2247276 = 1.943934747643532e+128;
bool r2247277 = r2247272 <= r2247276;
double r2247278 = 2.0;
double r2247279 = pow(r2247272, r2247278);
double r2247280 = y;
double r2247281 = pow(r2247280, r2247278);
double r2247282 = r2247279 + r2247281;
double r2247283 = sqrt(r2247282);
double r2247284 = r2247277 ? r2247283 : r2247272;
double r2247285 = r2247274 ? r2247275 : r2247284;
return r2247285;
}



# Try it out

Results

 In Out
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(x^2 + y^2)"
:precision binary64
(sqrt (+ (pow x 2) (pow y 2))))