Average Error: 58.3 → 0.1
Time: 40.2s
Precision: 64
$\frac{1}{1 + 2 \cdot x} - \left(\frac{1 - x}{1} + x\right)$
$\begin{array}{l} \mathbf{if}\;x \le -4.3626020996179295 \cdot 10^{-05}:\\ \;\;\;\;\frac{\frac{\left(\frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}\right) \cdot \left(\frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}\right) - 1}{1 + \frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}}}{1 + \frac{1}{1 + x \cdot 2}}\\ \mathbf{elif}\;x \le 4.376108730440258 \cdot 10^{-05}:\\ \;\;\;\;\left(\left(x \cdot 2\right) \cdot \left(x \cdot 2\right) - x \cdot 2\right) - \left(x \cdot 2\right) \cdot \left(\left(x \cdot 2\right) \cdot \left(x \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \frac{1}{1 + x \cdot 2}\right) \cdot \left(\frac{1}{1 + x \cdot 2} - 1\right)}{1 + \frac{1}{1 + x \cdot 2}}\\ \end{array}$
\frac{1}{1 + 2 \cdot x} - \left(\frac{1 - x}{1} + x\right)
\begin{array}{l}
\mathbf{if}\;x \le -4.3626020996179295 \cdot 10^{-05}:\\
\;\;\;\;\frac{\frac{\left(\frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}\right) \cdot \left(\frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}\right) - 1}{1 + \frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}}}{1 + \frac{1}{1 + x \cdot 2}}\\

\mathbf{elif}\;x \le 4.376108730440258 \cdot 10^{-05}:\\
\;\;\;\;\left(\left(x \cdot 2\right) \cdot \left(x \cdot 2\right) - x \cdot 2\right) - \left(x \cdot 2\right) \cdot \left(\left(x \cdot 2\right) \cdot \left(x \cdot 2\right)\right)\\

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

\end{array}
double f(double x) {
double r36596446 = 1.0;
double r36596447 = 2.0;
double r36596448 = x;
double r36596449 = r36596447 * r36596448;
double r36596450 = r36596446 + r36596449;
double r36596451 = r36596446 / r36596450;
double r36596452 = r36596446 - r36596448;
double r36596453 = r36596452 / r36596446;
double r36596454 = r36596453 + r36596448;
double r36596455 = r36596451 - r36596454;
return r36596455;
}


double f(double x) {
double r36596456 = x;
double r36596457 = -4.3626020996179295e-05;
bool r36596458 = r36596456 <= r36596457;
double r36596459 = 1.0;
double r36596460 = 2.0;
double r36596461 = r36596456 * r36596460;
double r36596462 = r36596459 + r36596461;
double r36596463 = r36596459 / r36596462;
double r36596464 = r36596463 * r36596463;
double r36596465 = r36596464 * r36596464;
double r36596466 = r36596465 - r36596459;
double r36596467 = r36596459 + r36596464;
double r36596468 = r36596466 / r36596467;
double r36596469 = r36596459 + r36596463;
double r36596470 = r36596468 / r36596469;
double r36596471 = 4.376108730440258e-05;
bool r36596472 = r36596456 <= r36596471;
double r36596473 = r36596461 * r36596461;
double r36596474 = r36596473 - r36596461;
double r36596475 = r36596461 * r36596473;
double r36596476 = r36596474 - r36596475;
double r36596477 = r36596463 - r36596459;
double r36596478 = r36596469 * r36596477;
double r36596479 = r36596478 / r36596469;
double r36596480 = r36596472 ? r36596476 : r36596479;
double r36596481 = r36596458 ? r36596470 : r36596480;
return r36596481;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 3 regimes
2. ## if x < -4.3626020996179295e-05

1. Initial program 56.5

$\frac{1}{1 + 2 \cdot x} - \left(\frac{1 - x}{1} + x\right)$
2. Simplified0.1

$\leadsto \color{blue}{\frac{1}{x \cdot 2 + 1} - 1}$
3. Using strategy rm
4. Applied flip--0.1

$\leadsto \color{blue}{\frac{\frac{1}{x \cdot 2 + 1} \cdot \frac{1}{x \cdot 2 + 1} - 1 \cdot 1}{\frac{1}{x \cdot 2 + 1} + 1}}$
5. Using strategy rm
6. Applied flip--0.1

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

## if -4.3626020996179295e-05 < x < 4.376108730440258e-05

1. Initial program 59.3

$\frac{1}{1 + 2 \cdot x} - \left(\frac{1 - x}{1} + x\right)$
2. Simplified59.3

$\leadsto \color{blue}{\frac{1}{x \cdot 2 + 1} - 1}$
3. Taylor expanded around 0 0.0

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

$\leadsto \color{blue}{\left(\left(2 \cdot x\right) \cdot \left(2 \cdot x\right) - 2 \cdot x\right) - \left(2 \cdot x\right) \cdot \left(\left(2 \cdot x\right) \cdot \left(2 \cdot x\right)\right)}$

## if 4.376108730440258e-05 < x

1. Initial program 58.0

$\frac{1}{1 + 2 \cdot x} - \left(\frac{1 - x}{1} + x\right)$
2. Simplified0.1

$\leadsto \color{blue}{\frac{1}{x \cdot 2 + 1} - 1}$
3. Using strategy rm
4. Applied flip--0.1

$\leadsto \color{blue}{\frac{\frac{1}{x \cdot 2 + 1} \cdot \frac{1}{x \cdot 2 + 1} - 1 \cdot 1}{\frac{1}{x \cdot 2 + 1} + 1}}$
5. Using strategy rm
6. Applied difference-of-squares0.1

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

$\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.3626020996179295 \cdot 10^{-05}:\\ \;\;\;\;\frac{\frac{\left(\frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}\right) \cdot \left(\frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}\right) - 1}{1 + \frac{1}{1 + x \cdot 2} \cdot \frac{1}{1 + x \cdot 2}}}{1 + \frac{1}{1 + x \cdot 2}}\\ \mathbf{elif}\;x \le 4.376108730440258 \cdot 10^{-05}:\\ \;\;\;\;\left(\left(x \cdot 2\right) \cdot \left(x \cdot 2\right) - x \cdot 2\right) - \left(x \cdot 2\right) \cdot \left(\left(x \cdot 2\right) \cdot \left(x \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \frac{1}{1 + x \cdot 2}\right) \cdot \left(\frac{1}{1 + x \cdot 2} - 1\right)}{1 + \frac{1}{1 + x \cdot 2}}\\ \end{array}$

# Reproduce

herbie shell --seed 1
(FPCore (x)
:name "(1/(1+2x))-((1-x)/1+x)"
(- (/ 1 (+ 1 (* 2 x))) (+ (/ (- 1 x) 1) x)))