Average Error: 31.4 → 17.2
Time: 3.6s
Precision: 64
$\sqrt{xre \cdot xre + xim \cdot xim}$
$\begin{array}{l} \mathbf{if}\;xre \le -3.303209947657204342880384766533788360025 \cdot 10^{84}:\\ \;\;\;\;-xre\\ \mathbf{elif}\;xre \le 1.943934747643531875760607600817076209382 \cdot 10^{128}:\\ \;\;\;\;\sqrt{xre \cdot xre + xim \cdot xim}\\ \mathbf{else}:\\ \;\;\;\;xre\\ \end{array}$
\sqrt{xre \cdot xre + xim \cdot xim}
\begin{array}{l}
\mathbf{if}\;xre \le -3.303209947657204342880384766533788360025 \cdot 10^{84}:\\
\;\;\;\;-xre\\

\mathbf{elif}\;xre \le 1.943934747643531875760607600817076209382 \cdot 10^{128}:\\
\;\;\;\;\sqrt{xre \cdot xre + xim \cdot xim}\\

\mathbf{else}:\\
\;\;\;\;xre\\

\end{array}
double f(double xre, double xim) {
double r1631243 = xre;
double r1631244 = r1631243 * r1631243;
double r1631245 = xim;
double r1631246 = r1631245 * r1631245;
double r1631247 = r1631244 + r1631246;
double r1631248 = sqrt(r1631247);
return r1631248;
}


double f(double xre, double xim) {
double r1631249 = xre;
double r1631250 = -3.3032099476572043e+84;
bool r1631251 = r1631249 <= r1631250;
double r1631252 = -r1631249;
double r1631253 = 1.943934747643532e+128;
bool r1631254 = r1631249 <= r1631253;
double r1631255 = r1631249 * r1631249;
double r1631256 = xim;
double r1631257 = r1631256 * r1631256;
double r1631258 = r1631255 + r1631257;
double r1631259 = sqrt(r1631258);
double r1631260 = r1631254 ? r1631259 : r1631249;
double r1631261 = r1631251 ? r1631252 : r1631260;
return r1631261;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 3 regimes
2. ## if xre < -3.3032099476572043e+84

1. Initial program 48.4

$\sqrt{xre \cdot xre + xim \cdot xim}$
2. Taylor expanded around -inf 10.3

$\leadsto \color{blue}{-1 \cdot xre}$
3. Simplified10.3

$\leadsto \color{blue}{-xre}$

## if -3.3032099476572043e+84 < xre < 1.943934747643532e+128

1. Initial program 21.1

$\sqrt{xre \cdot xre + xim \cdot xim}$

## if 1.943934747643532e+128 < xre

1. Initial program 57.0

$\sqrt{xre \cdot xre + xim \cdot xim}$
2. Taylor expanded around inf 8.2

$\leadsto \color{blue}{xre}$
3. Recombined 3 regimes into one program.
4. Final simplification17.2

$\leadsto \begin{array}{l} \mathbf{if}\;xre \le -3.303209947657204342880384766533788360025 \cdot 10^{84}:\\ \;\;\;\;-xre\\ \mathbf{elif}\;xre \le 1.943934747643531875760607600817076209382 \cdot 10^{128}:\\ \;\;\;\;\sqrt{xre \cdot xre + xim \cdot xim}\\ \mathbf{else}:\\ \;\;\;\;xre\\ \end{array}$

# Reproduce

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