Average Error: 14.7 → 0.4
Time: 6.4s
Precision: 64
$\frac{1}{x + 1} - \frac{1}{x}$
$\begin{array}{l} \mathbf{if}\;x \le -3699362183749.66259765625 \lor \neg \left(x \le 297181.315169758279807865619659423828125\right):\\ \;\;\;\;\left(\frac{1}{{x}^{3}} - \frac{1}{{x}^{4}}\right) - \frac{1}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 1} \cdot \frac{x - \left(1 + x\right)}{x}\\ \end{array}$
\frac{1}{x + 1} - \frac{1}{x}
\begin{array}{l}
\mathbf{if}\;x \le -3699362183749.66259765625 \lor \neg \left(x \le 297181.315169758279807865619659423828125\right):\\
\;\;\;\;\left(\frac{1}{{x}^{3}} - \frac{1}{{x}^{4}}\right) - \frac{1}{x \cdot x}\\

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

\end{array}
double f(double x) {
double r1889789 = 1.0;
double r1889790 = x;
double r1889791 = r1889790 + r1889789;
double r1889792 = r1889789 / r1889791;
double r1889793 = r1889789 / r1889790;
double r1889794 = r1889792 - r1889793;
return r1889794;
}


double f(double x) {
double r1889795 = x;
double r1889796 = -3699362183749.6626;
bool r1889797 = r1889795 <= r1889796;
double r1889798 = 297181.3151697583;
bool r1889799 = r1889795 <= r1889798;
double r1889800 = !r1889799;
bool r1889801 = r1889797 || r1889800;
double r1889802 = 1.0;
double r1889803 = 3.0;
double r1889804 = pow(r1889795, r1889803);
double r1889805 = r1889802 / r1889804;
double r1889806 = 4.0;
double r1889807 = pow(r1889795, r1889806);
double r1889808 = r1889802 / r1889807;
double r1889809 = r1889805 - r1889808;
double r1889810 = r1889795 * r1889795;
double r1889811 = r1889802 / r1889810;
double r1889812 = r1889809 - r1889811;
double r1889813 = r1889795 + r1889802;
double r1889814 = r1889802 / r1889813;
double r1889815 = r1889802 + r1889795;
double r1889816 = r1889795 - r1889815;
double r1889817 = r1889816 / r1889795;
double r1889818 = r1889814 * r1889817;
double r1889819 = r1889801 ? r1889812 : r1889818;
return r1889819;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 2 regimes
2. ## if x < -3699362183749.6626 or 297181.3151697583 < x

1. Initial program 29.4

$\frac{1}{x + 1} - \frac{1}{x}$
2. Taylor expanded around inf 0.8

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

$\leadsto \color{blue}{\left(\frac{1}{{x}^{3}} - \frac{1}{{x}^{4}}\right) - \frac{1}{x \cdot x}}$

## if -3699362183749.6626 < x < 297181.3151697583

1. Initial program 0.5

$\frac{1}{x + 1} - \frac{1}{x}$
2. Using strategy rm
3. Applied frac-sub0.0

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

$\leadsto \frac{\color{blue}{1 \cdot \left(x - \left(1 + x\right)\right)}}{\left(x + 1\right) \cdot x}$
5. Using strategy rm
6. Applied times-frac0.0

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

$\leadsto \begin{array}{l} \mathbf{if}\;x \le -3699362183749.66259765625 \lor \neg \left(x \le 297181.315169758279807865619659423828125\right):\\ \;\;\;\;\left(\frac{1}{{x}^{3}} - \frac{1}{{x}^{4}}\right) - \frac{1}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 1} \cdot \frac{x - \left(1 + x\right)}{x}\\ \end{array}$

# Reproduce

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