Average Error: 9.8 → 0.3
Time: 17.0s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -17522.19903136883:\\ \;\;\;\;\frac{\frac{6}{x} - \left(\frac{2}{x \cdot x} + \frac{4}{{x}^{3}}\right)}{x \cdot \left(\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \left(x \cdot x + -1\right)\right)}\\ \mathbf{elif}\;x \leq 604.3633384530846:\\ \;\;\;\;\frac{x - 2 \cdot \left(x + 1\right)}{x \cdot \left(x + 1\right)} + \frac{1}{x + -1}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{1}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -17522.19903136883:\\
\;\;\;\;\frac{\frac{6}{x} - \left(\frac{2}{x \cdot x} + \frac{4}{{x}^{3}}\right)}{x \cdot \left(\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \left(x \cdot x + -1\right)\right)}\\

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

\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{1}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}\\

\end{array}
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= x -17522.19903136883)
   (/
    (- (/ 6.0 x) (+ (/ 2.0 (* x x)) (/ 4.0 (pow x 3.0))))
    (* x (* (+ (/ 2.0 x) (/ 1.0 (+ x 1.0))) (+ (* x x) -1.0))))
   (if (<= x 604.3633384530846)
     (+ (/ (- x (* 2.0 (+ x 1.0))) (* x (+ x 1.0))) (/ 1.0 (+ x -1.0)))
     (+ (* 2.0 (/ 1.0 (pow x 5.0))) (* 2.0 (/ 1.0 (pow x 3.0)))))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	double tmp;
	if (x <= -17522.19903136883) {
		tmp = ((6.0 / x) - ((2.0 / (x * x)) + (4.0 / pow(x, 3.0)))) / (x * (((2.0 / x) + (1.0 / (x + 1.0))) * ((x * x) + -1.0)));
	} else if (x <= 604.3633384530846) {
		tmp = ((x - (2.0 * (x + 1.0))) / (x * (x + 1.0))) + (1.0 / (x + -1.0));
	} else {
		tmp = (2.0 * (1.0 / pow(x, 5.0))) + (2.0 * (1.0 / pow(x, 3.0)));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.8
Target0.3
Herbie0.3
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)}\]

Derivation

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

    1. Initial program 20.3

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied flip--_binary64_175853.6

      \[\leadsto \color{blue}{\frac{\frac{1}{x + 1} \cdot \frac{1}{x + 1} - \frac{2}{x} \cdot \frac{2}{x}}{\frac{1}{x + 1} + \frac{2}{x}}} + \frac{1}{x - 1}\]
    4. Applied frac-add_binary64_179154.2

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{x + 1} \cdot \frac{1}{x + 1} - \frac{2}{x} \cdot \frac{2}{x}\right) \cdot \left(x - 1\right) + \left(\frac{1}{x + 1} + \frac{2}{x}\right) \cdot 1}{\left(\frac{1}{x + 1} + \frac{2}{x}\right) \cdot \left(x - 1\right)}}\]
    5. Simplified26.4

      \[\leadsto \frac{\color{blue}{\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \left(\left(\frac{-2}{x} + \frac{1}{x + 1}\right) \cdot \left(x + -1\right) + 1\right)}}{\left(\frac{1}{x + 1} + \frac{2}{x}\right) \cdot \left(x - 1\right)}\]
    6. Simplified26.4

      \[\leadsto \frac{\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \left(\left(\frac{-2}{x} + \frac{1}{x + 1}\right) \cdot \left(x + -1\right) + 1\right)}{\color{blue}{\left(x + -1\right) \cdot \left(\frac{2}{x} + \frac{1}{x + 1}\right)}}\]
    7. Taylor expanded around inf 0.3

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

      \[\leadsto \frac{\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \color{blue}{\left(\frac{2}{x \cdot x} - \frac{2}{{x}^{3}}\right)}}{\left(x + -1\right) \cdot \left(\frac{2}{x} + \frac{1}{x + 1}\right)}\]
    9. Using strategy rm
    10. Applied frac-add_binary64_17910.3

      \[\leadsto \frac{\color{blue}{\frac{2 \cdot \left(x + 1\right) + x \cdot 1}{x \cdot \left(x + 1\right)}} \cdot \left(\frac{2}{x \cdot x} - \frac{2}{{x}^{3}}\right)}{\left(x + -1\right) \cdot \left(\frac{2}{x} + \frac{1}{x + 1}\right)}\]
    11. Applied associate-*l/_binary64_17260.3

      \[\leadsto \frac{\color{blue}{\frac{\left(2 \cdot \left(x + 1\right) + x \cdot 1\right) \cdot \left(\frac{2}{x \cdot x} - \frac{2}{{x}^{3}}\right)}{x \cdot \left(x + 1\right)}}}{\left(x + -1\right) \cdot \left(\frac{2}{x} + \frac{1}{x + 1}\right)}\]
    12. Applied associate-/l/_binary64_17300.3

      \[\leadsto \color{blue}{\frac{\left(2 \cdot \left(x + 1\right) + x \cdot 1\right) \cdot \left(\frac{2}{x \cdot x} - \frac{2}{{x}^{3}}\right)}{\left(\left(x + -1\right) \cdot \left(\frac{2}{x} + \frac{1}{x + 1}\right)\right) \cdot \left(x \cdot \left(x + 1\right)\right)}}\]
    13. Simplified0.3

      \[\leadsto \frac{\left(2 \cdot \left(x + 1\right) + x \cdot 1\right) \cdot \left(\frac{2}{x \cdot x} - \frac{2}{{x}^{3}}\right)}{\color{blue}{x \cdot \left(\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \left(x \cdot x + -1\right)\right)}}\]
    14. Taylor expanded around 0 0.2

      \[\leadsto \frac{\color{blue}{6 \cdot \frac{1}{x} - \left(2 \cdot \frac{1}{{x}^{2}} + 4 \cdot \frac{1}{{x}^{3}}\right)}}{x \cdot \left(\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \left(x \cdot x + -1\right)\right)}\]
    15. Simplified0.3

      \[\leadsto \frac{\color{blue}{\frac{6}{x} - \left(\frac{2}{x \cdot x} + \frac{4}{{x}^{3}}\right)}}{x \cdot \left(\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \left(x \cdot x + -1\right)\right)}\]

    if -17522.19903136883 < x < 604.363338453084566

    1. Initial program 0.1

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied frac-sub_binary64_17920.1

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

    if 604.363338453084566 < x

    1. Initial program 20.3

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Taylor expanded around inf 0.6

      \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -17522.19903136883:\\ \;\;\;\;\frac{\frac{6}{x} - \left(\frac{2}{x \cdot x} + \frac{4}{{x}^{3}}\right)}{x \cdot \left(\left(\frac{2}{x} + \frac{1}{x + 1}\right) \cdot \left(x \cdot x + -1\right)\right)}\\ \mathbf{elif}\;x \leq 604.3633384530846:\\ \;\;\;\;\frac{x - 2 \cdot \left(x + 1\right)}{x \cdot \left(x + 1\right)} + \frac{1}{x + -1}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{1}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}\\ \end{array}\]

Reproduce

herbie shell --seed 2021027 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2.0 (* x (- (* x x) 1.0)))

  (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))