Average Error: 16.1 → 0.0
Time: 5.3s
Precision: 64
$\sqrt{x \cdot x + 1}$
$\begin{array}{l} \mathbf{if}\;x \le -1.34187617831678346445877735820560354144 \cdot 10^{154}:\\ \;\;\;\;\left(\frac{0.125}{{x}^{3}} - \frac{0.5}{x}\right) - x\\ \mathbf{elif}\;x \le 271.00571350320626606844598427414894104:\\ \;\;\;\;\sqrt{x \cdot x + 1}\\ \mathbf{else}:\\ \;\;\;\;\left(x + \frac{0.5}{x}\right) - \frac{0.125}{{x}^{3}}\\ \end{array}$
\sqrt{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -1.34187617831678346445877735820560354144 \cdot 10^{154}:\\
\;\;\;\;\left(\frac{0.125}{{x}^{3}} - \frac{0.5}{x}\right) - x\\

\mathbf{elif}\;x \le 271.00571350320626606844598427414894104:\\
\;\;\;\;\sqrt{x \cdot x + 1}\\

\mathbf{else}:\\
\;\;\;\;\left(x + \frac{0.5}{x}\right) - \frac{0.125}{{x}^{3}}\\

\end{array}
double f(double x) {
double r1834696 = x;
double r1834697 = r1834696 * r1834696;
double r1834698 = 1.0;
double r1834699 = r1834697 + r1834698;
double r1834700 = sqrt(r1834699);
return r1834700;
}


double f(double x) {
double r1834701 = x;
double r1834702 = -1.3418761783167835e+154;
bool r1834703 = r1834701 <= r1834702;
double r1834704 = 0.125;
double r1834705 = 3.0;
double r1834706 = pow(r1834701, r1834705);
double r1834707 = r1834704 / r1834706;
double r1834708 = 0.5;
double r1834709 = r1834708 / r1834701;
double r1834710 = r1834707 - r1834709;
double r1834711 = r1834710 - r1834701;
double r1834712 = 271.00571350320627;
bool r1834713 = r1834701 <= r1834712;
double r1834714 = r1834701 * r1834701;
double r1834715 = 1.0;
double r1834716 = r1834714 + r1834715;
double r1834717 = sqrt(r1834716);
double r1834718 = r1834701 + r1834709;
double r1834719 = r1834718 - r1834707;
double r1834720 = r1834713 ? r1834717 : r1834719;
double r1834721 = r1834703 ? r1834711 : r1834720;
return r1834721;
}



# 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 \cdot x + 1}$
2. Taylor expanded around -inf 0

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

$\leadsto \color{blue}{\left(\frac{0.125}{{x}^{3}} - \frac{0.5}{x}\right) - x}$

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

1. Initial program 0.0

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

## if 271.00571350320627 < x

1. Initial program 31.8

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

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

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

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

# Reproduce

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