Average Error: 21.6 → 0.0
Time: 13.4s
Precision: 64
$\sqrt{x + {x}^{2}}$
$\begin{array}{l} \mathbf{if}\;x \le -1.34187617831678346445877735820560354144 \cdot 10^{154}:\\ \;\;\;\;\frac{\frac{1}{8}}{x} - \left(x + \frac{1}{2}\right)\\ \mathbf{elif}\;x \le 75949.519527743221260607242584228515625:\\ \;\;\;\;\sqrt{x + {x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\left(x + \frac{1}{2}\right) - \frac{\frac{1}{8}}{x}\\ \end{array}$
\sqrt{x + {x}^{2}}
\begin{array}{l}
\mathbf{if}\;x \le -1.34187617831678346445877735820560354144 \cdot 10^{154}:\\
\;\;\;\;\frac{\frac{1}{8}}{x} - \left(x + \frac{1}{2}\right)\\

\mathbf{elif}\;x \le 75949.519527743221260607242584228515625:\\
\;\;\;\;\sqrt{x + {x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\left(x + \frac{1}{2}\right) - \frac{\frac{1}{8}}{x}\\

\end{array}
double f(double x) {
double r1864136 = x;
double r1864137 = 2.0;
double r1864138 = pow(r1864136, r1864137);
double r1864139 = r1864136 + r1864138;
double r1864140 = sqrt(r1864139);
return r1864140;
}


double f(double x) {
double r1864141 = x;
double r1864142 = -1.3418761783167835e+154;
bool r1864143 = r1864141 <= r1864142;
double r1864144 = 0.125;
double r1864145 = r1864144 / r1864141;
double r1864146 = 0.5;
double r1864147 = r1864141 + r1864146;
double r1864148 = r1864145 - r1864147;
double r1864149 = 75949.51952774322;
bool r1864150 = r1864141 <= r1864149;
double r1864151 = 2.0;
double r1864152 = pow(r1864141, r1864151);
double r1864153 = r1864141 + r1864152;
double r1864154 = sqrt(r1864153);
double r1864155 = r1864147 - r1864145;
double r1864156 = r1864150 ? r1864154 : r1864155;
double r1864157 = r1864143 ? r1864148 : r1864156;
return r1864157;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 3 regimes
2. ## if x < -1.3418761783167835e+154

1. Initial program 64.0

$\sqrt{x + {x}^{2}}$
2. Taylor expanded around -inf 0

$\leadsto \color{blue}{\frac{1}{8} \cdot \frac{1}{x} - \left(x + \frac{1}{2}\right)}$
3. Simplified0

$\leadsto \color{blue}{\frac{\frac{1}{8}}{x} - \left(x + \frac{1}{2}\right)}$

## if -1.3418761783167835e+154 < x < 75949.51952774322

1. Initial program 0.0

$\sqrt{x + {x}^{2}}$

## if 75949.51952774322 < x

1. Initial program 32.5

$\sqrt{x + {x}^{2}}$
2. Taylor expanded around inf 0.0

$\leadsto \color{blue}{\left(x + \frac{1}{2}\right) - \frac{1}{8} \cdot \frac{1}{x}}$
3. Simplified0.0

$\leadsto \color{blue}{\left(x + \frac{1}{2}\right) - \frac{\frac{1}{8}}{x}}$
3. Recombined 3 regimes into one program.
4. Final simplification0.0

$\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.34187617831678346445877735820560354144 \cdot 10^{154}:\\ \;\;\;\;\frac{\frac{1}{8}}{x} - \left(x + \frac{1}{2}\right)\\ \mathbf{elif}\;x \le 75949.519527743221260607242584228515625:\\ \;\;\;\;\sqrt{x + {x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\left(x + \frac{1}{2}\right) - \frac{\frac{1}{8}}{x}\\ \end{array}$

# Reproduce

herbie shell --seed 1
(FPCore (x)
:name "sqrt(x+x^2)"
:precision binary64
(sqrt (+ x (pow x 2))))