Average Error: 29.4 → 16.3
Time: 4.5s
Precision: 64
$\sqrt{x \cdot x + y \cdot y}$
$\begin{array}{l} \mathbf{if}\;x \le -5.325979075963888 \cdot 10^{+153}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.6722096998730964 \cdot 10^{+129}:\\ \;\;\;\;\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 -5.325979075963888 \cdot 10^{+153}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.6722096998730964 \cdot 10^{+129}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
double r43414176 = x;
double r43414177 = r43414176 * r43414176;
double r43414178 = y;
double r43414179 = r43414178 * r43414178;
double r43414180 = r43414177 + r43414179;
double r43414181 = sqrt(r43414180);
return r43414181;
}


double f(double x, double y) {
double r43414182 = x;
double r43414183 = -5.325979075963888e+153;
bool r43414184 = r43414182 <= r43414183;
double r43414185 = -r43414182;
double r43414186 = 1.6722096998730964e+129;
bool r43414187 = r43414182 <= r43414186;
double r43414188 = y;
double r43414189 = r43414188 * r43414188;
double r43414190 = r43414182 * r43414182;
double r43414191 = r43414189 + r43414190;
double r43414192 = sqrt(r43414191);
double r43414193 = r43414187 ? r43414192 : r43414182;
double r43414194 = r43414184 ? r43414185 : r43414193;
return r43414194;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 3 regimes
2. ## if x < -5.325979075963888e+153

1. Initial program 59.2

$\sqrt{x \cdot x + y \cdot y}$
2. Taylor expanded around -inf 7.8

$\leadsto \color{blue}{-1 \cdot x}$
3. Simplified7.8

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

## if -5.325979075963888e+153 < x < 1.6722096998730964e+129

1. Initial program 19.4

$\sqrt{x \cdot x + y \cdot y}$

## if 1.6722096998730964e+129 < x

1. Initial program 53.3

$\sqrt{x \cdot x + y \cdot y}$
2. Taylor expanded around inf 8.1

$\leadsto \color{blue}{x}$
3. Recombined 3 regimes into one program.
4. Final simplification16.3

$\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.325979075963888 \cdot 10^{+153}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.6722096998730964 \cdot 10^{+129}:\\ \;\;\;\;\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))))