Average Error: 30.9 → 0.4
Time: 16.4s
Precision: 64
$\sqrt{1 + {x}^{2}} - 1$
$\begin{array}{l} \mathbf{if}\;x \le -1.082711165719940638041407510172575712204:\\ \;\;\;\;\left(-\left(1 + \frac{0.5}{x}\right)\right) - x\\ \mathbf{elif}\;x \le 1.060447807660564345511033934599254280329:\\ \;\;\;\;\left(\left(\sqrt{1} - 1\right) - \frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\sqrt{1} \cdot 1} \cdot \frac{1}{8}\right) + \frac{x \cdot x}{\frac{\sqrt{1}}{\frac{1}{2}}}\\ \mathbf{else}:\\ \;\;\;\;\left(x - 1\right) + \frac{0.5}{x}\\ \end{array}$
\sqrt{1 + {x}^{2}} - 1
\begin{array}{l}
\mathbf{if}\;x \le -1.082711165719940638041407510172575712204:\\
\;\;\;\;\left(-\left(1 + \frac{0.5}{x}\right)\right) - x\\

\mathbf{elif}\;x \le 1.060447807660564345511033934599254280329:\\
\;\;\;\;\left(\left(\sqrt{1} - 1\right) - \frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\sqrt{1} \cdot 1} \cdot \frac{1}{8}\right) + \frac{x \cdot x}{\frac{\sqrt{1}}{\frac{1}{2}}}\\

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

\end{array}
double f(double x) {
double r773572 = 1.0;
double r773573 = x;
double r773574 = 2.0;
double r773575 = pow(r773573, r773574);
double r773576 = r773572 + r773575;
double r773577 = sqrt(r773576);
double r773578 = r773577 - r773572;
return r773578;
}


double f(double x) {
double r773579 = x;
double r773580 = -1.0827111657199406;
bool r773581 = r773579 <= r773580;
double r773582 = 1.0;
double r773583 = 0.5;
double r773584 = r773583 / r773579;
double r773585 = r773582 + r773584;
double r773586 = -r773585;
double r773587 = r773586 - r773579;
double r773588 = 1.0604478076605643;
bool r773589 = r773579 <= r773588;
double r773590 = sqrt(r773582);
double r773591 = r773590 - r773582;
double r773592 = r773579 * r773579;
double r773593 = r773592 * r773592;
double r773594 = r773590 * r773582;
double r773595 = r773593 / r773594;
double r773596 = 0.125;
double r773597 = r773595 * r773596;
double r773598 = r773591 - r773597;
double r773599 = 0.5;
double r773600 = r773590 / r773599;
double r773601 = r773592 / r773600;
double r773602 = r773598 + r773601;
double r773603 = r773579 - r773582;
double r773604 = r773603 + r773584;
double r773605 = r773589 ? r773602 : r773604;
double r773606 = r773581 ? r773587 : r773605;
return r773606;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 3 regimes
2. ## if x < -1.0827111657199406

1. Initial program 32.2

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

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

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

## if -1.0827111657199406 < x < 1.0604478076605643

1. Initial program 30.0

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

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

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

## if 1.0604478076605643 < x

1. Initial program 31.6

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

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

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

$\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.082711165719940638041407510172575712204:\\ \;\;\;\;\left(-\left(1 + \frac{0.5}{x}\right)\right) - x\\ \mathbf{elif}\;x \le 1.060447807660564345511033934599254280329:\\ \;\;\;\;\left(\left(\sqrt{1} - 1\right) - \frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}{\sqrt{1} \cdot 1} \cdot \frac{1}{8}\right) + \frac{x \cdot x}{\frac{\sqrt{1}}{\frac{1}{2}}}\\ \mathbf{else}:\\ \;\;\;\;\left(x - 1\right) + \frac{0.5}{x}\\ \end{array}$

# Reproduce

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